Skip to content

Commit

Permalink
Merge pull request php#5 from mtraver/intl-tests
Browse files Browse the repository at this point in the history
Apply ext/intl test changes from github.com/php/php-src to bring ICU compat up to 64
  • Loading branch information
mtraver authored Jul 22, 2019
2 parents 8719117 + edf62a7 commit 27f12cd
Show file tree
Hide file tree
Showing 46 changed files with 953 additions and 54 deletions.
1 change: 1 addition & 0 deletions ext/intl/tests/breakiter_getLocale_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ IntlBreakIterator::getLocale(): basic test
--SKIPIF--
<?php if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '53.1') < 0) die('skip for ICU >= 53.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '64.0') >= 0) die('skip for ICU < 64.0'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
Expand Down
20 changes: 20 additions & 0 deletions ext/intl/tests/breakiter_getLocale_basic3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
IntlBreakIterator::getLocale(): basic test
--SKIPIF--
<?php if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '64.0') < 0) die('skip for ICU >= 64.0'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createSentenceInstance('pt');

var_dump($bi->getLocale(0));
var_dump($bi->getLocale(1));
?>
==DONE==
--EXPECT--
string(0) ""
string(2) "pt"
==DONE==
6 changes: 4 additions & 2 deletions ext/intl/tests/breakiter_getPartsIterator_basic.phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--TEST--
IntlBreakIterator::getPartsIterator(): basic test
IntlBreakIterator::getPartsIterator(): basic test, ICU <= 57.1
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
if (version_compare(INTL_ICU_VERSION, '57.1') > 0) die('skip for ICU <= 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
Expand Down Expand Up @@ -34,4 +36,4 @@ Array
[2] => bar
)
int(0)
==DONE==
==DONE==
39 changes: 39 additions & 0 deletions ext/intl/tests/breakiter_getPartsIterator_basic2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
IntlBreakIterator::getPartsIterator(): basic test, ICU >= 58.1
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
if (version_compare(INTL_ICU_VERSION, '57.1') <= 0) die('skip for ICU >= 58.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$pi = $bi->getPartsIterator();
var_dump(get_class($pi));
print_r(iterator_to_array($pi));

$bi->setText("foo bar");
$pi = $bi->getPartsIterator();
var_dump(get_class($pi->getBreakIterator()));
print_r(iterator_to_array($pi));
var_dump($pi->getRuleStatus());
?>
==DONE==
--EXPECTF--
string(17) "IntlPartsIterator"
Array
(
)
string(26) "IntlRuleBasedBreakIterator"
Array
(
[0] => foo
[1] =>
[2] => bar
)
int(%d)
==DONE==
6 changes: 4 additions & 2 deletions ext/intl/tests/breakiter_preceding_basic.phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--TEST--
IntlBreakIterator::preceding(): basic test
IntlBreakIterator::preceding(): basic test, ICU <= 57.1
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
if (version_compare(INTL_ICU_VERSION, '57.1') > 0) die('skip for ICU <= 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
Expand All @@ -21,4 +23,4 @@ var_dump($bi->preceding(-1));
int(4)
int(21)
int(0)
==DONE==
==DONE==
25 changes: 25 additions & 0 deletions ext/intl/tests/breakiter_preceding_basic2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
IntlBreakIterator::preceding(): basic test, ICU >= 58.1
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
if (version_compare(INTL_ICU_VERSION, '57.1') <= 0) die('skip for ICU >= 58.1');
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');

var_dump($bi->preceding(5));
var_dump($bi->preceding(50));
var_dump($bi->preceding(-1));
?>
==DONE==
--EXPECTF--
int(4)
int(21)
int(%i)
==DONE==
15 changes: 15 additions & 0 deletions ext/intl/tests/bug71020.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #71020 (Use after free in Collator::sortWithSortKeys)
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--FILE--
<?php

$var_3=new Collator("Whatever");
for($x=0;$x<0xbb;$x++)
$myarray[substr(md5(microtime()),rand(0,26),9) . strval($x)]= substr(md5(microtime()),rand(0,26),9) . strval($x);
$var_3->sortWithSortKeys($myarray);
?>
okey
--EXPECT--
okey
1 change: 1 addition & 0 deletions ext/intl/tests/dateformat_create_cal_arg_variant4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IntlDateFormatter: several forms of the calendar arg
<?php
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '54.1') < 0) die('skip for ICU >= 54.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '58.1') >= 0) die('skip for ICU <= 57.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
Expand Down
53 changes: 53 additions & 0 deletions ext/intl/tests/dateformat_create_cal_arg_variant5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
IntlDateFormatter: several forms of the calendar arg
--SKIPIF--
<?php
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '58.1') < 0) die('skip for ICU >= 58.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores');

$ts = strtotime('2012-01-01 00:00:00 UTC');

$cal = new IntlGregorianCalendar('UTC', NULL);
$df = new IntlDateFormatter('es_ES', 0, 0, NULL, $cal);
echo $df->format($ts), "\n";

$cal = IntlCalendar::createInstance('UTC', 'en@calendar=islamic');
$df = new IntlDateFormatter('es_ES', 0, 0, NULL, $cal);
echo $df->format($ts), "\n";

//override calendar's timezone
$cal = new IntlGregorianCalendar('UTC', NULL);
$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Madrid', $cal);
echo $df->format($ts), "\n";

//default calendar is gregorian
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0);
echo $df->format($ts), "\n";

//try now with traditional
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, NULL, IntlDateFormatter::TRADITIONAL);
echo $df->format($ts), "\n";

//the timezone can be overridden when not specifying a calendar
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, 'UTC', IntlDateFormatter::TRADITIONAL);
echo $df->format($ts), "\n";

$df = new IntlDateFormatter('es_ES', 0, 0, 'UTC', 0);
echo $df->format($ts), "\n";

?>
==DONE==
--EXPECTF--
domingo%S 1 de enero de 2012, 0:00:00 (%siempo %sniversal %sordinado)
domingo%S 8 de %safar de 1433, 0:00:00 (%siempo %sniversal %sordinado)
domingo, 1 de enero de 2012, 1:00:00 (hora estándar de Europa central)
sábado, 31 de diciembre de 2011 d. C., 23:00:00 (hora estándar de las Azores)
sábado, 7 de %safar de 1433 AH, 23:00:00 (hora estándar de las Azores)
domingo%S 8 de %safar de 1433 AH, 0:00:00 (%siempo %sniversal %sordinado)
domingo%S 1 de enero de 2012, 0:00:00 (%siempo %sniversal %sordinado)
==DONE==
1 change: 1 addition & 0 deletions ext/intl/tests/dateformat_get_set_calendar_variant4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IntlDateFormatter: setCalendar()/getCalendar()/getCalendarObject()
<?php
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '54.1') < 0) die('skip for ICU >= 54.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '58.1') >= 0) die('skip for ICU <= 57.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
Expand Down
55 changes: 55 additions & 0 deletions ext/intl/tests/dateformat_get_set_calendar_variant5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
IntlDateFormatter: setCalendar()/getCalendar()/getCalendarObject()
--SKIPIF--
<?php
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '58.1') < 0) die('skip for ICU >= 58.1'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores');

$ts = strtotime('2012-01-01 00:00:00 UTC');

function d(IntlDateFormatter $df) {
global $ts;
echo $df->format($ts), "\n";
var_dump($df->getCalendar(),
$df->getCalendarObject()->getType(),
$df->getCalendarObject()->getTimeZone()->getId());
echo "\n";
}

$df = new IntlDateFormatter('fr@calendar=islamic', 0, 0, 'Europe/Minsk');
d($df);


//changing the calendar with a cal type should not change tz
$df->setCalendar(IntlDateFormatter::TRADITIONAL);
d($df);

//but changing with an actual calendar should
$cal = IntlCalendar::createInstance("UTC");
$df->setCalendar($cal);
d($df);

?>
==DONE==
--EXPECT--
dimanche 1 janvier 2012 ap. J.-C. à 03:00:00 heure de Kaliningrad
int(1)
string(9) "gregorian"
string(12) "Europe/Minsk"

dimanche 8 safar 1433 AH à 03:00:00 heure de Kaliningrad
int(0)
string(7) "islamic"
string(12) "Europe/Minsk"

dimanche 1 janvier 2012 ap. J.-C. à 00:00:00 Temps universel coordonné
bool(false)
string(9) "gregorian"
string(3) "UTC"

==DONE==
2 changes: 1 addition & 1 deletion ext/intl/tests/dateformat_set_timezone_id2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ datefmt_set_timezone_id_code() icu >= 4.8
date.timezone=Atlantic/Azores
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip intl extension not loaded'; ?>
<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip for ICU > 4.8'; ?>
<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip for ICU >= 4.8'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '50.1.2') >= 0) die('skip for ICU < 50.1.2'); ?>
--FILE--
<?php
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/formatter_format2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
numfmt_format() icu >= 4.8
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip intl extension not loaded'; ?>
<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip for ICU > 4.8'; ?>
<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip for ICU >= 4.8'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '52.1') >= 0) die('skip for ICU <= 52.1'); ?>
--FILE--
<?php
Expand Down
3 changes: 2 additions & 1 deletion ext/intl/tests/formatter_format6.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
--TEST--
numfmt_format() icu >= 56.1
numfmt_format() icu >= 56.1 && icu < 61.1
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '61.1') >= 0) die('skip for ICU < 61.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '56.1') < 0) die('skip for ICU >= 56.1'); ?>
--FILE--
<?php
Expand Down
Loading

0 comments on commit 27f12cd

Please sign in to comment.