From 986b4a63ba2d15aeb1ce7bcd749d6b800cbfb8a3 Mon Sep 17 00:00:00 2001 From: Deltik <deltik@gmx.com> Date: Fri, 23 Feb 2018 15:51:05 -0600 Subject: [PATCH] Test e_tree_model::multiFieldCmp() Relates to: 840859a32f5e7c6d579f1b643e99ed30d30d1fd7 --- e107 | 2 +- tests/unit/TreeModelTest.php | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/e107 b/e107 index e92c6789c..840859a32 160000 --- a/e107 +++ b/e107 @@ -1 +1 @@ -Subproject commit e92c6789c51c9b653153efe555d1ded9ffbff49f +Subproject commit 840859a32f5e7c6d579f1b643e99ed30d30d1fd7 diff --git a/tests/unit/TreeModelTest.php b/tests/unit/TreeModelTest.php index 270f95aa5..14ba1dfcc 100644 --- a/tests/unit/TreeModelTest.php +++ b/tests/unit/TreeModelTest.php @@ -122,6 +122,76 @@ class TreeModelTest extends \Codeception\Test\Unit $this->assertEquals('163', $tree_model->getParam('db_limit_count')); $this->assertEquals('79', $tree_model->getParam('db_limit_offset')); } + + public function testMultiFieldCompareWithSortFieldsReturnsExpectedValues() + { + $tree_model = $this->make('e_tree_model'); + $class = new \ReflectionClass(get_class($tree_model)); + $method = $class->getMethod('multiFieldCmp'); + $method->setAccessible(true); + + $row1 = array( + 'field1' => '0', + 'field2' => '-1', + ); + $row2 = array( + 'field1' => '0', + 'field2' => '1', + ); + $sort_fields = ['field1', 'field2']; + + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(-1, $result); + + $row1['field2'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(0, $result); + + $row1['field2'] = 2; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(1, $result); + + $row1['field1'] = -1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(-1, $result); + + $row1['field1'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(1, $result); + } + + public function testMultiFieldCompareWithSortFieldReturnsExpectedValues() + { + $tree_model = $this->make('e_tree_model'); + $class = new \ReflectionClass(get_class($tree_model)); + $method = $class->getMethod('multiFieldCmp'); + $method->setAccessible(true); + + $row1 = array( + 'field1' => '0', + 'field2' => '-1', + ); + $row2 = array( + 'field1' => '0', + 'field2' => '1', + ); + $sort_field = 'field1'; + + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(0, $result); + + $row1['field1'] = -1; + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(-1, $result); + + $row1['field1'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(1, $result); + + $row1['field2'] = 1337; + $this->assertEquals(1, $result); + } + protected $sample_rows = array ( 1 =>