[TASk] Add tests for t3lib_div addSlashesOnArray and stripSlashesOnArray
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_divTest.php
index 7716eb8..3c21f21 100644 (file)
@@ -1111,6 +1111,66 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
 
        //////////////////////////////////////
+       // Tests concerning addSlashesOnArray
+       //////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function addSlashesOnArrayAddsSlashesRecursive() {
+               $inputArray = array(
+                       'key1' => array(
+                               'key11' => "val'ue1",
+                               'key12' => 'val"ue2',
+                       ),
+                       'key2' => 'val\ue3',
+               );
+               $expectedResult = array(
+                       'key1' => array(
+                               'key11' => "val\'ue1",
+                               'key12' => 'val\"ue2',
+                       ),
+                       'key2' => 'val\\\\ue3',
+               );
+               t3lib_div::addSlashesOnArray($inputArray);
+               $this->assertEquals(
+                       $expectedResult,
+                       $inputArray
+               );
+       }
+
+
+       //////////////////////////////////////
+       // Tests concerning addSlashesOnArray
+       //////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function stripSlashesOnArrayStripsSlashesRecursive() {
+               $inputArray = array(
+                       'key1' => array(
+                               'key11' => "val\'ue1",
+                               'key12' => 'val\"ue2',
+                       ),
+                       'key2' => 'val\\\\ue3',
+               );
+               $expectedResult = array(
+                       'key1' => array(
+                               'key11' => "val'ue1",
+                               'key12' => 'val"ue2',
+                       ),
+                       'key2' => 'val\ue3',
+               );
+               t3lib_div::stripSlashesOnArray($inputArray);
+               $this->assertEquals(
+                       $expectedResult,
+                       $inputArray
+               );
+       }
+
+
+       //////////////////////////////////////
        // Tests concerning arrayDiffAssocRecursive
        //////////////////////////////////////
 
@@ -1281,6 +1341,119 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
        }
 
+       //////////////////////////////////////
+       // Tests concerning naturalKeySortRecursive
+       //////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function naturalKeySortRecursiveReturnsFalseIfInputIsNotAnArray() {
+               $testValues = array(
+                       1,
+                       'string',
+                       FALSE
+               );
+               foreach($testValues as $testValue) {
+                       $this->assertFalse(t3lib_div::naturalKeySortRecursive($testValue));
+               }
+       }
+
+       /**
+        * @test
+        */
+       public function naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder() {
+               $testArray = array(
+                       'bb' => 'bb',
+                       'ab' => 'ab',
+                       '123' => '123',
+                       'aaa' => 'aaa',
+                       'abc' => 'abc',
+                       '23' => '23',
+                       'ba' => 'ba',
+                       'bad' => 'bad',
+                       '2' => '2',
+                       'zap' => 'zap',
+                       '210' => '210'
+               );
+               $expectedResult = array(
+                       '2',
+                       '23',
+                       '123',
+                       '210',
+                       'aaa',
+                       'ab',
+                       'abc',
+                       'ba',
+                       'bad',
+                       'bb',
+                       'zap'
+               );
+               t3lib_div::naturalKeySortRecursive($testArray);
+               $this->assertEquals($expectedResult, array_values($testArray));
+       }
+
+       /**
+        * @test
+        */
+       public function naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder() {
+               $testArray = array(
+                       '2' => '2',
+                       'bb' => 'bb',
+                       'ab' => 'ab',
+                       '23' => '23',
+                       'aaa' => array(
+                               'bb' => 'bb',
+                               'ab' => 'ab',
+                               '123' => '123',
+                               'aaa' => 'aaa',
+                               '2' => '2',
+                               'abc' => 'abc',
+                               'ba' => 'ba',
+                               '23' => '23',
+                               'bad' => array(
+                                       'bb' => 'bb',
+                                       'ab' => 'ab',
+                                       '123' => '123',
+                                       'aaa' => 'aaa',
+                                       'abc' => 'abc',
+                                       '23' => '23',
+                                       'ba' => 'ba',
+                                       'bad' => 'bad',
+                                       '2' => '2',
+                                       'zap' => 'zap',
+                                       '210' => '210'
+                               ),
+                               '210' => '210',
+                               'zap' => 'zap'
+                       ),
+                       'abc' => 'abc',
+                       'ba' => 'ba',
+                       '210' => '210',
+                       'bad' => 'bad',
+                       '123' => '123',
+                       'zap' => 'zap'
+               );
+
+               $expectedResult = array(
+                       '2',
+                       '23',
+                       '123',
+                       '210',
+                       'aaa',
+                       'ab',
+                       'abc',
+                       'ba',
+                       'bad',
+                       'bb',
+                       'zap'
+               );
+               t3lib_div::naturalKeySortRecursive($testArray);
+
+               $this->assertEquals($expectedResult, array_values(array_keys($testArray['aaa']['bad'])));
+               $this->assertEquals($expectedResult, array_values(array_keys($testArray['aaa'])));
+               $this->assertEquals($expectedResult, array_values(array_keys($testArray)));
+       }
 
        //////////////////////////////////////
        // Tests concerning get_dirs
@@ -2790,4 +2963,4 @@ class t3lib_divTest extends tx_phpunit_testcase {
                );
        }
 }
-?>
+?>
\ No newline at end of file