1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-20 09:54:16 +01:00

Add tests to reveal the to RFC string error - Fix typo in variable of rfcString function of RRule

This commit is contained in:
Antoine Chabert 2016-08-17 23:14:38 +02:00
parent 8fbc51e499
commit d7acacad6a
2 changed files with 67 additions and 3 deletions

View File

@ -604,9 +604,9 @@ class RRule implements RRuleInterface
continue;
}
if ( $key === 'FREQ' && $value && !array_key_exists($value, static::$frequencies) ) {
$frequencyKey = array_search($value, static::$frequencies);
if ($frequencyKey !== false) {
$value = $frequencyKey;
$frequency_key = array_search($value, static::$frequencies);
if ($frequency_key !== false) {
$value = $frequency_key;
}
}
if ( $value ) {

View File

@ -1845,6 +1845,70 @@ class RRuleTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expected_str, $rule->rfcString(false));
}
public function rfcStringsGenerated()
{
return array(
array(
array(
'FREQ' => RRule::YEARLY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=YEARLY"
),
array(
array(
'FREQ' => RRule::MONTHLY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=MONTHLY"
),
array(
array(
'FREQ' => RRule::WEEKLY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=WEEKLY"
),
array(
array(
'FREQ' => RRule::DAILY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=DAILY"
),
array(
array(
'FREQ' => RRule::HOURLY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=HOURLY"
),
array(
array(
'FREQ' => RRule::MINUTELY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=MINUTELY"
),
array(
array(
'FREQ' => RRule::SECONDLY,
'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))
),
"DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=SECONDLY"
),
);
}
/**
* @dataProvider rfcStringsGenerated
*/
public function testRfcStringsGenerated($params, $expected_str)
{
$rule = new RRule($params);
$this->assertEquals($expected_str, $rule->rfcString());
}
///////////////////////////////////////////////////////////////////////////////
// Timezone