Commit 50d1df30 authored by Chris Graham's avatar Chris Graham

Fixed MANTIS-4191 (Array sorting issue on PHP 7.4 )

parent b6e3390e
<?php /*
Composr
Copyright (c) ocProducts, 2004-2020
See text/EN/licence.txt for full licencing information.
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package testing_platform
*/
/**
* Composr test case class (unit testing).
*/
class sorting_test_set extends cms_test_case
{
public function testSortMapsBy()
{
$arr = array(
array(1),
array(3),
array(2),
);
// Ascending
sort_maps_by($arr, 0);
$expected = array(
array(1),
array(2),
array(3),
);
$this->assertTrue($arr == $expected);
// Descending
sort_maps_by($arr, '!0');
$expected = array(
array(3),
array(2),
array(1),
);
$this->assertTrue($arr == $expected);
// Now with nulls...
$arr = array(
array(null),
array(3),
array(2),
);
// Ascending
sort_maps_by($arr, 0);
$expected = array(
array(null),
array(2),
array(3),
);
$this->assertTrue($arr == $expected);
// Descending
sort_maps_by($arr, '!0');
$expected = array(
array(3),
array(2),
array(null),
);
$this->assertTrue($arr == $expected);
}
}
......@@ -1538,6 +1538,14 @@ function _multi_sort($a, $b)
$first_key = substr($first_key, 1);
}
if (($a === null) && ($b === null)) {
return 0;
} elseif ($a === null) {
return ($key[0] === '!') ? 1 : -1;
} elseif ($b === null) {
return ($key[0] === '!') ? -1 : 1;
}
if ((is_string($a[$first_key])) || (is_object($a[$first_key]))) {
$ret = 0;
do {
......
......@@ -524,6 +524,7 @@ class Hook_addon_registry_testing_platform
'_tests/tests/unit_tests/url_management.php',
'_tests/tests/unit_tests/news.php',
'_tests/tests/unit_tests/news_category.php',
'_tests/tests/unit_tests/sorting.php',
'_tests/tests/unit_tests/newsletter.php',
'_tests/tests/unit_tests/cms_merge.php',
'_tests/tests/unit_tests/should_ignore_file.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment