1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2024-11-28 05:24:10 +01:00

Fix tests when ext-intl is not loaded

This commit is contained in:
rlanvin 2020-02-24 17:39:41 +01:00
parent 931d53d162
commit f2cead618c

View File

@ -2924,6 +2924,10 @@ class RRuleTest extends TestCase
*/ */
public function testI18nFilesToLoadWithIntl($locale, $files) public function testI18nFilesToLoadWithIntl($locale, $files)
{ {
if (!extension_loaded('intl')) {
$this->markTestSkipped('intl extension is not loaded');
}
$reflector = new ReflectionClass('RRule\RRule'); $reflector = new ReflectionClass('RRule\RRule');
$method = $reflector->getMethod('i18nFilesToLoad'); $method = $reflector->getMethod('i18nFilesToLoad');
$method->setAccessible(true); $method->setAccessible(true);
@ -2980,6 +2984,10 @@ class RRuleTest extends TestCase
*/ */
public function testI18nLoadWithIntl($locale) public function testI18nLoadWithIntl($locale)
{ {
if (!extension_loaded('intl')) {
$this->markTestSkipped('intl extension is not loaded');
}
$reflector = new ReflectionClass('RRule\RRule'); $reflector = new ReflectionClass('RRule\RRule');
$method = $reflector->getMethod('i18nLoad'); $method = $reflector->getMethod('i18nLoad');
$method->setAccessible(true); $method->setAccessible(true);
@ -3068,59 +3076,70 @@ class RRuleTest extends TestCase
return array( return array(
array( array(
"DTSTART:20170202T000000Z\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z", "DTSTART:20170202T000000Z\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z",
array('locale' => "en"), ['locale' => "en"],
"daily, starting from 2/2/17, until 2/5/17" "daily, starting from 2/2/17, until 2/5/17",
'daily, starting from 2017-02-02 00:00:00, until 2017-02-05 00:00:00',
), ),
array( array(
"RRULE:FREQ=DAILY;UNTIL=20190405T055959Z", "RRULE:FREQ=DAILY;UNTIL=20190405T055959Z",
array('locale' => "en"), ['locale' => "en"],
"daily, starting from 1/10/19, until 4/5/19", "daily, starting from 1/10/19, until 4/5/19",
'daily, starting from 2019-01-10 12:00:00, until 2019-04-05 05:59:59',
'2019-01-10T12:00:00-05:00' '2019-01-10T12:00:00-05:00'
), ),
array( array(
"DTSTART:20170202T000000Z\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z", "DTSTART:20170202T000000Z\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z",
array('locale' => "en_IE"), array('locale' => "en_IE"),
"daily, starting from 02/02/2017, until 05/02/2017" "daily, starting from 02/02/2017, until 05/02/2017",
'daily, starting from 2017-02-02 00:00:00, until 2017-02-05 00:00:00'
), ),
array( array(
"DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z", "DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z",
array('locale' => "en_IE"), array('locale' => "en_IE"),
"daily, starting from 01/09/1997, until 04/02/2017" "daily, starting from 01/09/1997, until 04/02/2017",
'daily, starting from 1997-09-01 09:00:00, until 2017-02-05 00:00:00'
), ),
array( array(
"DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z", "DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY;UNTIL=20170205T000000Z",
array('locale' => "en_IE", 'include_start' => false), array('locale' => "en_IE", 'include_start' => false),
"daily, until 04/02/2017" "daily, until 04/02/2017",
'daily, until 2017-02-05 00:00:00'
), ),
array( array(
"DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY", "DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY",
array('locale' => "en_IE", 'explicit_infinite' => false), array('locale' => "en_IE", 'explicit_infinite' => false),
"daily, starting from 01/09/1997" "daily, starting from 01/09/1997",
'daily, starting from 1997-09-01 09:00:00'
), ),
array( array(
"DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=YEARLY;INTERVAL=2", "DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=YEARLY;INTERVAL=2",
array('locale' => "en_IE", 'explicit_infinite' => false), array('locale' => "en_IE", 'explicit_infinite' => false),
"every 2 years, starting from 01/09/1997" "every 2 years, starting from 01/09/1997",
'every 2 years, starting from 1997-09-01 09:00:00'
), ),
array( array(
"FREQ=DAILY", "FREQ=DAILY",
array('locale' => "en_IE", 'include_start' => false, 'explicit_infinite' => false), array('locale' => "en_IE", 'include_start' => false, 'explicit_infinite' => false),
"daily",
"daily" "daily"
), ),
// with custom_path // with custom_path
'custom_path' => array( 'custom_path' => array(
"DTSTART:20170202T000000Z\nRRULE:FREQ=YEARLY;UNTIL=20170205T000000Z", "DTSTART:20170202T000000Z\nRRULE:FREQ=YEARLY;UNTIL=20170205T000000Z",
array('locale' => "fr_BE", "custom_path" => __DIR__."/i18n"), array('locale' => "fr_BE", "custom_path" => __DIR__."/i18n"),
"chaque année, à partir du 2/02/17, jusqu'au 5/02/17" "chaque année, à partir du 2/02/17, jusqu'au 5/02/17",
"chaque année, à partir du 2017-02-02 00:00:00, jusqu'au 2017-02-05 00:00:00"
), ),
'custom_path cached separately' => array( 'custom_path cached separately' => array(
"DTSTART:20170202T000000Z\nRRULE:FREQ=YEARLY;UNTIL=20170205T000000Z", "DTSTART:20170202T000000Z\nRRULE:FREQ=YEARLY;UNTIL=20170205T000000Z",
array('locale' => "fr_BE"), array('locale' => "fr_BE"),
"tous les ans, à partir du 2/02/17, jusqu'au 5/02/17", "tous les ans, à partir du 2/02/17, jusqu'au 5/02/17",
"tous les ans, à partir du 2017-02-02 00:00:00, jusqu'au 2017-02-05 00:00:00"
), ),
array( array(
"RRULE:FREQ=DAILY;UNTIL=20190405T055959Z", "RRULE:FREQ=DAILY;UNTIL=20190405T055959Z",
array('locale' => "xx", "custom_path" => __DIR__."/i18n", "date_formatter" => function($date) { return "X"; }), array('locale' => "xx", "custom_path" => __DIR__."/i18n", "date_formatter" => function($date) { return "X"; }),
"daily, starting from X, until X",
"daily, starting from X, until X" "daily, starting from X, until X"
), ),
); );
@ -3129,12 +3148,13 @@ class RRuleTest extends TestCase
/** /**
* @dataProvider humanReadableStrings * @dataProvider humanReadableStrings
*/ */
public function testHumanReadable($rrule, $options, $string, $dtstart = null) public function testHumanReadable($rrule, $options, $withIntl, $withoutIntl, $dtstart = null)
{ {
if ($dtstart) { if ($dtstart) {
$dtstart = new DateTime($dtstart); $dtstart = new DateTime($dtstart);
} }
$rrule = new RRule($rrule, $dtstart); $rrule = new RRule($rrule, $dtstart);
$this->assertEquals($string, $rrule->humanReadable($options)); $expected = extension_loaded('intl') ? $withIntl : $withoutIntl;
$this->assertEquals($expected, $rrule->humanReadable($options));
} }
} }