2 declare(strict_types = 1);
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
42 'empty search array' => [
47 'empty string as needle' => [
57 'flat array searching for string' => [
67 'flat array searching for string with two matches' => [
71 'firstbanana' =>
'banana',
72 'secondbanana' =>
'banana'
75 'firstbanana' =>
'banana',
76 'secondbanana' =>
'banana'
79 'multi dimensional array searching for string with multiple matches' => [
83 'firstbanana' =>
'banana',
86 'secondbanana' =>
'banana',
92 'firstbanana' =>
'banana',
94 'secondbanana' =>
'banana'
98 'multi dimensional array searching for integer with multiple matches' => [
115 'flat array searching for boolean TRUE' => [
125 'multi dimensional array searching for boolean FALSE' => [
142 'flat array searching for array' => [
181 $instance = new \stdClass();
226 $this->expectException(\InvalidArgumentException::class);
227 $this->expectExceptionCode(1476557628);
237 $this->expectException(\RuntimeException::class);
238 $this->expectExceptionCode(1341397767);
270 'not existing index' => [
277 'not existing path 1' => [
284 'not existing path 2' => [
294 'last segment is not an array' => [
305 'doubletick encapsulated quoted doubletick does not work' => [
316 'path with doubletick does not work' => [
336 $this->expectException(\RuntimeException::class);
337 $this->expectExceptionCode(1341397869);
349 $this->expectException(MissingArrayPathException::class);
350 $this->expectExceptionCode(1341397869);
363 $testObject = new \stdClass();
364 $testObject->foo =
'foo';
365 $testObject->bar =
'bar';
367 'integer in multi level array' => [
379 'zero integer in multi level array' => [
390 'NULL value in multi level array' => [
399 'get string value' => [
402 'baz' =>
'this is a test string'
406 'this is a test string'
408 'get boolean value: FALSE' => [
417 'get boolean value: TRUE' => [
426 'get object value' => [
485 $searchPath =
'foo%bar%baz';
502 $this->expectException(\RuntimeException::class);
503 $this->expectExceptionCode(1341406194);
513 $this->expectException(\InvalidArgumentException::class);
514 $this->expectExceptionCode(1478781081);
524 $this->expectException(\RuntimeException::class);
525 $this->expectExceptionCode(1341406846);
557 $testObject = new \stdClass();
558 $testObject->foo =
'foo';
559 $testObject->bar =
'bar';
561 'set integer value: 42' => [
579 'set integer value: 0' => [
597 'set null value' => [
615 'set array value' => [
637 'set boolean value: FALSE' => [
655 'set boolean value: TRUE' => [
673 'set object value' => [
691 'multi keys in array' => [
743 $this->expectException(\RuntimeException::class);
744 $this->expectExceptionCode(1371757718);
754 $this->expectException(\RuntimeException::class);
755 $this->expectExceptionCode(1371757719);
771 $this->expectException(\RuntimeException::class);
772 $this->expectExceptionCode(1371757720);
794 $inputArray = [
'bar'];
810 $this->expectException(\RuntimeException::class);
811 $this->expectExceptionCode(1371758436);
827 $this->expectException(MissingArrayPathException::class);
828 $this->expectExceptionCode(1371758436);
844 $path =
'foo.toRemove';
959 'assoc array index' => [
997 'numeric array index' => [
1035 'numeric array index DESC' => [
1087 $this->assertSame($expectedResult, $sortedArray);
1095 $this->expectException(\RuntimeException::class);
1096 $this->expectExceptionCode(1373727309);
1122 'qux2' => 0.000000001,
1126 ' \'foo\' => [' . LF .
1127 ' \'bar\' => 42,' . LF .
1128 ' \'bar2\' => [' . LF .
1129 ' \'baz\' => \'val\\\'ue\',' . LF .
1130 ' \'baz2\' => true,' . LF .
1131 ' \'baz3\' => false,' . LF .
1132 ' \'baz4\' => [],' . LF .
1135 ' \'baz\' => 23,' . LF .
1136 ' \'foobar\' => null,' . LF .
1137 ' \'qux\' => 0.1,' . LF .
1138 ' \'qux2\' => 1.0E-9,' . LF .
1150 'bar' => new \stdClass()
1154 $this->expectException(\RuntimeException::class);
1155 $this->expectExceptionCode(1342294987);
1166 'foo' =>
'string key',
1167 23 =>
'integer key',
1168 '42' =>
'string key representing integer'
1172 ' \'foo\' => \'string key\',' . LF .
1173 ' 23 => \'integer key\',' . LF .
1174 ' 42 => \'string key representing integer\',' . LF .
1211 ' 0 => \'zero\',' . LF .
1212 ' 1 => \'one\',' . LF .
1213 ' 3 => \'three\',' . LF .
1214 ' 4 => \'four\',' . LF .
1239 'plain array with faulty dots' => [
1249 'nested array of 2 levels' => [
1259 'first.firstSub' => 1,
1260 'second.secondSub' => 2
1263 'nested array of 2 levels with faulty dots' => [
1273 'first.firstSub' => 1,
1274 'second.secondSub' => 2
1277 'nested array of 3 levels' => [
1291 'first.firstSub.firstSubSub' => 1,
1292 'second.secondSub.secondSubSub' => 2
1295 'nested array of 3 levels with faulty dots' => [
1304 'secondSubSub.' => 2
1309 'first.firstSub.firstSubSub' => 1,
1310 'second.secondSub.secondSubSub' => 2
1336 $sameObject = new \stdClass();
1339 'empty array is returned if source is empty array' => [
1346 'empty array is returned if mask is empty' => [
1353 'key is kept on first level if exists in mask' => [
1364 'value of key in source is kept if mask has different value' => [
1369 'foo' => new \stdClass(),
1375 'key is kept on first level if according mask value is NULL' => [
1386 'null in source value is kept' => [
1397 'mask does not add new keys' => [
1411 'mask does not overwrite simple values with arrays' => [
1424 'key is kept on first level if according mask value is array' => [
1437 'full array is kept if value is array and mask value is simple type' => [
1452 'key handling is type agnostic' => [
1463 'value is same if value is object' => [
1465 'foo' => $sameObject,
1468 'foo' =>
'something',
1471 'foo' => $sameObject,
1474 'mask does not add simple value to result if key does not exist in source' => [
1486 'array of source is kept if value of mask key exists but is no array' => [
1494 'foo' =>
'value is not significant',
1504 'sub arrays are kept if mask has according sub array key and is similar array' => [
1515 'second1' =>
'exists but different',
1549 'empty array is returned if source is empty array' => [
1553 'returns self if array is already numerically keyed' => [
1557 'returns correctly if keys are numeric, but contains a leap' => [
1558 [0 =>
'One', 1 =>
'Two', 3 =>
'Three'],
1559 [0 =>
'One', 1 =>
'Two', 2 =>
'Three'],
1561 'returns correctly even though keys are strings but still numeric' => [
1562 [
'0' =>
'One',
'1' =>
'Two',
'3' =>
'Three'],
1563 [0 =>
'One', 1 =>
'Two', 2 =>
'Three'],
1565 'returns correctly if just a single keys is not numeric' => [
1566 [0 =>
'Zero',
'1' =>
'One',
'Two' =>
'Two'],
1567 [0 =>
'Zero',
'1' =>
'One',
'Two' =>
'Two'],
1569 'returns unchanged if keys end with a dot' => [
1570 [
'2.' =>
'Two',
'1.' =>
'One',
'0.' =>
'Zero'],
1571 [
'2.' =>
'Two',
'1.' =>
'One',
'0.' =>
'Zero'],
1573 'return self with nested numerically keyed array' => [
1593 'returns correctly with nested numerically keyed array with leaps' => [
1613 'returns correctly with nested string-keyed array' => [
1633 'returns correctly with deeply nested arrays' => [
1683 'Override array can reset string to array' => [
1691 'second' => [
'third' =>
'bar'],
1699 'second' => [
'third' =>
'bar'],
1703 'Override array does not reset array to string (weird!)' => [
1717 'Override array does override string with null' => [
1731 'Override array does override null with string' => [
1745 'Override array does override null with empty string' => [
1759 'Override array does not override string with NULL if requested' => [
1773 'Override array does override null with null' => [
1787 'Override array can __UNSET values' => [
1790 'second' =>
'second',
1797 'second' =>
'overrule',
1798 'third' =>
'__UNSET',
1799 'fourth' =>
'overrile',
1801 'fifth' =>
'__UNSET',
1808 'second' =>
'overrule',
1809 'fourth' =>
'overrile',
1813 'Override can add keys' => [
1828 'Override does not add key if __UNSET' => [
1833 'second' =>
'__UNSET',
1842 'Override does not add key if not requested' => [
1856 'Override does not add key if not requested with add include empty values' => [
1870 'Override does not override string with empty string if requested' => [
1884 'Override array does merge instead of __UNSET if requested (weird!)' => [
1887 'second' =>
'second',
1894 'second' =>
'overrule',
1895 'third' =>
'__UNSET',
1896 'fourth' =>
'overrile',
1898 'fifth' =>
'__UNSET',
1905 'second' =>
'overrule',
1906 'third' =>
'__UNSET',
1907 'fourth' =>
'overrile',
1928 $this->assertEquals($expected, $input1);
1945 $compareValue =
'test2';
1951 $this->assertEquals($expectedResult, $actualResult);
1966 $compareValue =
'bar';
1972 $this->assertEquals($expectedResult, $actualResult);
1991 $this->assertEquals($expectedResult, $actualResult);
2023 'Empty argument will match "all" elements' => [
null, $array, $array],
2024 'No match' => [
'four', $array, []],
2025 'One match' => [
'two', $array, [
'two' =>
'two']],
2026 'Multiple matches' => [
'two,one', $array, [
'one' =>
'one',
'two' =>
'two']],
2027 'Argument can be an array' => [[
'three'], $array, [
'three' =>
'three']]
2041 'aa' => [
'first',
'second'],
2042 'bb' => [
'third',
'fourth'],
2043 'cc' => [
'fifth',
'sixth']
2045 $expected = [
'bb' => [
'third',
'fourth']];
2046 $keepItems =
'third';
2054 $this->assertEquals($expected, $match);
2080 $this->assertEquals($expected, $array);
2104 $this->assertEquals($expectedResult, $actualResult);
2115 'key21' =>
'value21',
2116 'key22' =>
'value22',
2118 'key231' =>
'value231',
2119 'key232' =>
'value232'
2124 'key1' =>
'valueDoesNotMatter',
2126 'key21' =>
'value21',
2128 'key231' =>
'value231'
2134 'key22' =>
'value22',
2136 'key232' =>
'value232'
2141 $this->assertEquals($expectedResult, $actualResult);
2151 'key11' =>
'value11',
2152 'key12' =>
'value12'
2160 'key21' =>
'valueDoesNotMatter'
2167 $this->assertEquals($expectedResult, $actualResult);
2177 'key11' =>
'value11',
2178 'key12' =>
'value12'
2185 'key11' =>
'valueDoesNotMatter',
2186 'key12' =>
'value12'
2191 $expectedResult = [];
2193 $this->assertEquals($expectedResult, $actualResult);
2232 $this->assertEquals($expectedResult, array_values($testArray));
2291 $this->assertEquals($expectedResult, array_values(array_keys($testArray[
'aaa'][
'bad'])));
2292 $this->assertEquals($expectedResult, array_values(array_keys($testArray[
'aaa'])));
2293 $this->assertEquals($expectedResult, array_values(array_keys($testArray)));
2304 'ordered list of plain numeric keys' => [
2314 'unordered list of plain numeric keys' => [
2324 'list of string keys' => [
2338 'list of mixed keys' => [
2350 'list of mixed keys with one not interpreted as integer' => [
2362 'list of mixed keys with more than one not interpreted as integer' => [
2390 $this->assertEquals($result, $expected);
2401 'ordered list of plain numeric keys' => [
2411 'unordered list of plain numeric keys' => [
2421 'list of string keys' => [
2432 'list of mixed keys' => [
2456 $this->assertEquals($result, $expected);
2494 'somestring' =>
'teststring',
2499 'somestring' =>
'teststring',
2517 $this->assertSame($sortedArray, $expectedArray);
2525 $this->expectException(\InvalidArgumentException::class);
2526 $this->expectExceptionCode(1325697085);
2534 $allowedArrayKeys = [
2553 $allowedArrayKeys = [
2705 'c' =>
'<b>i am evil</b>',
2726 $testObject = new \stdClass();
2729 'stringWithTags' =>
'<b>i am evil</b>',
2733 'object' => $testObject,
2734 'objectWithStringConversion' =>
new class {
2738 public function __toString()
2740 return 'i am evil <b>too</b>';
2746 'stringWithTags' =>
'i am evil',
2750 'object' => $testObject,
2751 'objectWithStringConversion' =>
'i am evil too',
2788 'filter all values which will be false when converted to boolean' => [
2855 $this->assertEquals($expectedResult, $result);
2865 'filter empty values, keep zero integers' => [
2937 return $item !==
'' && $item !== [] && $item !==
null;
2940 $this->assertEquals($expectedResult, $result);
2965 'filter using a closure' => [
2968 function ($value):
bool {
2969 return is_array($value) || $value ===
'keep';
2972 'filter using a callable "static class-method call" as string' => [
2975 ArrayUtilityFilterRecursiveCallbackFixture::class .
'::callbackViaStaticMethod',
2977 'filter using a callable "static class-method call" as array' => [
2980 [ArrayUtilityFilterRecursiveCallbackFixture::class,
'callbackViaStaticMethod'],
2982 'filter using a callable "instance-method call" as array' => [
3001 $this->assertEquals($expectedResult, $result);