Fixed bug #14972: Add unit tests for t3lib_div::removeArrayEntryByValue (Thanks to...
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 6 Jul 2010 18:30:25 +0000 (18:30 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 6 Jul 2010 18:30:25 +0000 (18:30 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8117 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
tests/t3lib/t3lib_divTest.php

index 000ecc9..adc0105 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-07-06  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Fixed bug #14972: Add unit tests for t3lib_div::removeArrayEntryByValue (Thanks to Thorben Kapp)
        * Fixed bug #14967: [Caching framework] fileBackend testcase removes files in /sbin
        * Fixed bug #14977: Add php cache frontend to t3lib/config_default.php (Thanks to Felix Oertel)
 
index 252cb84..dcf5c29 100644 (file)
@@ -1811,7 +1811,6 @@ final class t3lib_div {
                                unset($array[$k]);
                        }
                }
-               reset($array);
                return $array;
        }
 
index f07fef2..11f2ea7 100644 (file)
@@ -201,6 +201,63 @@ class t3lib_divTest extends tx_phpunit_testcase {
        }
 
        /**
+        * @test
+        */
+       public function checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray() {
+               $inputArray = array(
+                       '0' => 'test1',
+                       '1' => 'test2',
+                       '2' => 'test3',
+                       '3' => 'test2',
+               );
+               $compareValue = 'test2';
+               $expectedResult = array(
+                       '0' => 'test1',
+                       '2' => 'test3',
+               );
+               $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray() {
+               $inputArray = array(
+                       '0' => 'foo',
+                       '1' => array(
+                               '10' => 'bar',
+                       ),
+                       '2' => 'bar',
+               );
+               $compareValue = 'bar';
+               $expectedResult = array(
+                       '0' => 'foo',
+                       '1' => array(),
+               );
+               $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function checkRemoveArrayEntryByValueRemovesEntryWithEmptyString() {
+               $inputArray = array(
+                       '0' => 'foo',
+                       '1' => '',
+                       '2' => 'bar',
+               );
+               $compareValue = '';
+               $expectedResult = array(
+                       '0' => 'foo',
+                       '2' => 'bar',
+               );
+               $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
         * Checks whether measurement strings like "100k" return the accordant
         * byte representation like 102400 in this case.
         *