Add PHPunit test for DefaultCollator
This extends Test_NaturalSort to include a basic test for \OC\NaturalSort_DefaultCollator()
This commit is contained in:
parent
d57f5c70e9
commit
0066c6f001
|
@ -8,27 +8,32 @@
|
||||||
|
|
||||||
class Test_NaturalSort extends \Test\TestCase {
|
class Test_NaturalSort extends \Test\TestCase {
|
||||||
|
|
||||||
public function setUp() {
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
if(!class_exists('Collator')) {
|
|
||||||
$this->markTestSkipped('The intl module is not available, natural sorting will not work as expected.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider naturalSortDataProvider
|
* @dataProvider naturalSortDataProvider
|
||||||
*/
|
*/
|
||||||
public function testNaturalSortCompare($array, $sorted)
|
public function testNaturalSortCompare($array, $sorted)
|
||||||
{
|
{
|
||||||
|
if(!class_exists('Collator')) {
|
||||||
|
$this->markTestSkipped('The intl module is not available, natural sorting might not work as expected.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$comparator = \OC\NaturalSort::getInstance();
|
$comparator = \OC\NaturalSort::getInstance();
|
||||||
usort($array, array($comparator, 'compare'));
|
usort($array, array($comparator, 'compare'));
|
||||||
$this->assertEquals($sorted, $array);
|
$this->assertEquals($sorted, $array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data provider for natural sort.
|
* @dataProvider defaultCollatorDataProvider
|
||||||
|
*/
|
||||||
|
public function testDefaultCollatorCompare($array, $sorted)
|
||||||
|
{
|
||||||
|
$comparator = new \OC\NaturalSort(new \OC\NaturalSort_DefaultCollator());
|
||||||
|
usort($array, array($comparator, 'compare'));
|
||||||
|
$this->assertEquals($sorted, $array);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for natural sorting with php5-intl's Collator.
|
||||||
* Must provide the same result as in core/js/tests/specs/coreSpec.js
|
* Must provide the same result as in core/js/tests/specs/coreSpec.js
|
||||||
* @return array test cases
|
* @return array test cases
|
||||||
*/
|
*/
|
||||||
|
@ -181,4 +186,85 @@ class Test_NaturalSort extends \Test\TestCase {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for natural sorting with \OC\NaturalSort_DefaultCollator.
|
||||||
|
* Must provide the same result as in core/js/tests/specs/coreSpec.js
|
||||||
|
* @return array test cases
|
||||||
|
*/
|
||||||
|
public function defaultCollatorDataProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// different casing
|
||||||
|
array(
|
||||||
|
// unsorted
|
||||||
|
array(
|
||||||
|
'aaa',
|
||||||
|
'bbb',
|
||||||
|
'BBB',
|
||||||
|
'AAA'
|
||||||
|
),
|
||||||
|
// sorted
|
||||||
|
array(
|
||||||
|
'aaa',
|
||||||
|
'AAA',
|
||||||
|
'bbb',
|
||||||
|
'BBB'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
// numbers
|
||||||
|
array(
|
||||||
|
// unsorted
|
||||||
|
array(
|
||||||
|
'124.txt',
|
||||||
|
'abc1',
|
||||||
|
'123.txt',
|
||||||
|
'abc',
|
||||||
|
'abc2',
|
||||||
|
'def (2).txt',
|
||||||
|
'ghi 10.txt',
|
||||||
|
'abc12',
|
||||||
|
'def.txt',
|
||||||
|
'def (1).txt',
|
||||||
|
'ghi 2.txt',
|
||||||
|
'def (10).txt',
|
||||||
|
'abc10',
|
||||||
|
'def (12).txt',
|
||||||
|
'z',
|
||||||
|
'ghi.txt',
|
||||||
|
'za',
|
||||||
|
'ghi 1.txt',
|
||||||
|
'ghi 12.txt',
|
||||||
|
'zz',
|
||||||
|
'15.txt',
|
||||||
|
'15b.txt',
|
||||||
|
),
|
||||||
|
// sorted
|
||||||
|
array(
|
||||||
|
'15.txt',
|
||||||
|
'15b.txt',
|
||||||
|
'123.txt',
|
||||||
|
'124.txt',
|
||||||
|
'abc',
|
||||||
|
'abc1',
|
||||||
|
'abc2',
|
||||||
|
'abc10',
|
||||||
|
'abc12',
|
||||||
|
'def.txt',
|
||||||
|
'def (1).txt',
|
||||||
|
'def (2).txt',
|
||||||
|
'def (10).txt',
|
||||||
|
'def (12).txt',
|
||||||
|
'ghi.txt',
|
||||||
|
'ghi 1.txt',
|
||||||
|
'ghi 2.txt',
|
||||||
|
'ghi 10.txt',
|
||||||
|
'ghi 12.txt',
|
||||||
|
'z',
|
||||||
|
'za',
|
||||||
|
'zz',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue