‪TYPO3CMS  9.5
ArrayUtilityTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪ArrayUtilityTest extends UnitTestCase
27 {
29  // Tests concerning filterByValueRecursive
31 
39  public function ‪filterByValueRecursive()
40  {
41  return [
42  'empty search array' => [
43  'banana',
44  [],
45  []
46  ],
47  'empty string as needle' => [
48  '',
49  [
50  '',
51  'apple'
52  ],
53  [
54  ''
55  ]
56  ],
57  'flat array searching for string' => [
58  'banana',
59  [
60  'apple',
61  'banana'
62  ],
63  [
64  1 => 'banana'
65  ]
66  ],
67  'flat array searching for string with two matches' => [
68  'banana',
69  [
70  'foo' => 'apple',
71  'firstbanana' => 'banana',
72  'secondbanana' => 'banana'
73  ],
74  [
75  'firstbanana' => 'banana',
76  'secondbanana' => 'banana'
77  ]
78  ],
79  'multi dimensional array searching for string with multiple matches' => [
80  'banana',
81  [
82  'foo' => 'apple',
83  'firstbanana' => 'banana',
84  'grape' => [
85  'foo2' => 'apple2',
86  'secondbanana' => 'banana',
87  'foo3' => []
88  ],
89  'bar' => 'orange'
90  ],
91  [
92  'firstbanana' => 'banana',
93  'grape' => [
94  'secondbanana' => 'banana'
95  ]
96  ]
97  ],
98  'multi dimensional array searching for integer with multiple matches' => [
99  42,
100  [
101  'foo' => 23,
102  'bar' => 42,
103  [
104  'foo' => 23,
105  'bar' => 42
106  ]
107  ],
108  [
109  'bar' => 42,
110  [
111  'bar' => 42
112  ]
113  ]
114  ],
115  'flat array searching for boolean TRUE' => [
116  true,
117  [
118  23 => false,
119  42 => true
120  ],
121  [
122  42 => true
123  ]
124  ],
125  'multi dimensional array searching for boolean FALSE' => [
126  false,
127  [
128  23 => false,
129  42 => true,
130  'foo' => [
131  23 => false,
132  42 => true
133  ]
134  ],
135  [
136  23 => false,
137  'foo' => [
138  23 => false
139  ]
140  ]
141  ],
142  'flat array searching for array' => [
143  [
144  'foo' => 'bar'
145  ],
146  [
147  'foo' => 'bar',
148  'foobar' => [
149  'foo' => 'bar'
150  ]
151  ],
152  [
153  'foobar' => [
154  'foo' => 'bar'
155  ]
156  ]
157  ]
158  ];
159  }
160 
168  public function ‪filterByValueRecursiveCorrectlyFiltersArray($needle, $haystack, $expectedResult)
169  {
170  $this->assertEquals(
171  $expectedResult,
172  ‪ArrayUtility::filterByValueRecursive($needle, $haystack)
173  );
174  }
175 
180  {
181  $instance = new \stdClass();
182  $this->assertEquals(
183  [$instance],
184  ‪ArrayUtility::filterByValueRecursive($instance, [$instance])
185  );
186  }
187 
192  {
193  $this->assertEquals(
194  [],
195  ‪ArrayUtility::filterByValueRecursive(new \stdClass(), [new \stdClass()])
196  );
197  }
198 
200  // Tests concerning isValidPath
202 
206  {
207  $this->assertTrue(‪ArrayUtility::isValidPath(['foo' => 'bar'], 'foo'));
208  }
209 
214  {
215  $this->assertFalse(‪ArrayUtility::isValidPath(['foo' => 'bar'], 'bar'));
216  }
217 
219  // Tests concerning getValueByPath
221 
225  {
226  $this->expectException(\InvalidArgumentException::class);
227  $this->expectExceptionCode(1476557628);
228 
230  }
231 
236  {
237  $this->expectException(\RuntimeException::class);
238  $this->expectExceptionCode(1341397767);
239 
241  }
242 
247  {
248  $this->assertSame('foo', ‪ArrayUtility::getValueByPath(['foo'], '0'));
249  }
250 
255  {
256  $this->assertSame('bar', ‪ArrayUtility::getValueByPath(['foo' => ['bar']], 'foo/0'));
257  }
258 
268  {
269  return [
270  'not existing index' => [
271  [
272  'foo' => ['foo']
273  ],
274  'foo/1',
275  false
276  ],
277  'not existing path 1' => [
278  [
279  'foo' => []
280  ],
281  'foo/bar/baz',
282  false
283  ],
284  'not existing path 2' => [
285  [
286  'foo' => [
287  'baz' => 42
288  ],
289  'bar' => []
290  ],
291  'foo/bar/baz',
292  false
293  ],
294  'last segment is not an array' => [
295  [
296  'foo' => [
297  'baz' => 42
298  ],
299  ],
300  'foo/baz/baz',
301  false
302  ],
303  // Negative test: This could be improved and the test moved to
304  // the valid data provider if the method supports this
305  'doubletick encapsulated quoted doubletick does not work' => [
306  [
307  '"foo"bar"' => [
308  'baz' => 42
309  ],
310  'bar' => []
311  ],
312  '"foo\\"bar"/baz',
313  42
314  ],
315  // Negative test: Method could be improved here
316  'path with doubletick does not work' => [
317  [
318  'fo"o' => [
319  'bar' => 42
320  ]
321  ],
322  'fo"o/foobar',
323  42
324  ]
325  ];
326  }
327 
334  public function ‪getValueByPathThrowsExceptionIfPathNotExists(array $array, $path)
335  {
336  $this->expectException(\RuntimeException::class);
337  $this->expectExceptionCode(1341397869);
338  ‪ArrayUtility::getValueByPath($array, $path);
339  }
340 
347  public function ‪getValueByPathThrowsSpecificExceptionIfPathNotExists(array $array, string $path)
348  {
349  $this->expectException(MissingArrayPathException::class);
350  $this->expectExceptionCode(1341397869);
351  ‪ArrayUtility::getValueByPath($array, $path);
352  }
353 
362  {
363  $testObject = new \stdClass();
364  $testObject->foo = 'foo';
365  $testObject->bar = 'bar';
366  return [
367  'integer in multi level array' => [
368  [
369  'foo' => [
370  'bar' => [
371  'baz' => 42
372  ],
373  'bar2' => []
374  ]
375  ],
376  'foo/bar/baz',
377  42
378  ],
379  'zero integer in multi level array' => [
380  [
381  'foo' => [
382  'bar' => [
383  'baz' => 0
384  ]
385  ]
386  ],
387  'foo/bar/baz',
388  0
389  ],
390  'NULL value in multi level array' => [
391  [
392  'foo' => [
393  'baz' => null
394  ]
395  ],
396  'foo/baz',
397  null
398  ],
399  'get string value' => [
400  [
401  'foo' => [
402  'baz' => 'this is a test string'
403  ]
404  ],
405  'foo/baz',
406  'this is a test string'
407  ],
408  'get boolean value: FALSE' => [
409  [
410  'foo' => [
411  'baz' => false
412  ]
413  ],
414  'foo/baz',
415  false
416  ],
417  'get boolean value: TRUE' => [
418  [
419  'foo' => [
420  'baz' => true
421  ]
422  ],
423  'foo/baz',
424  true
425  ],
426  'get object value' => [
427  [
428  'foo' => [
429  'baz' => $testObject
430  ]
431  ],
432  'foo/baz',
433  $testObject
434  ],
435  'sub array' => [
436  [
437  'foo' => [
438  'bar' => [
439  'baz' => 42,
440  ],
441  ],
442  ],
443  'foo/bar',
444  [
445  'baz' => 42,
446  ],
447  ],
448  'enclosed path' => [
449  [
450  'foo/bar' => [
451  'foobar' => 42
452  ]
453  ],
454  '"foo/bar"/foobar',
455  42
456  ]
457  ];
458  }
459 
467  public function ‪getValueByPathGetsCorrectValue(array $array, $path, $expectedResult)
468  {
469  $this->assertEquals($expectedResult, ‪ArrayUtility::getValueByPath($array, $path));
470  }
471 
476  {
477  $input = [
478  'foo' => [
479  'bar' => [
480  'baz' => 42
481  ],
482  'bar2' => []
483  ]
484  ];
485  $searchPath = 'foo%bar%baz';
486  $expected = 42;
487  $delimiter = '%';
488  $this->assertEquals(
489  $expected,
490  ‪ArrayUtility::getValueByPath($input, $searchPath, $delimiter)
491  );
492  }
493 
495  // Tests concerning setValueByPath
497 
501  {
502  $this->expectException(\RuntimeException::class);
503  $this->expectExceptionCode(1341406194);
504 
505  ‪ArrayUtility::setValueByPath([], '', null);
506  }
507 
512  {
513  $this->expectException(\InvalidArgumentException::class);
514  $this->expectExceptionCode(1478781081);
515 
516  ‪ArrayUtility::setValueByPath([], 123, null);
517  }
518 
523  {
524  $this->expectException(\RuntimeException::class);
525  $this->expectExceptionCode(1341406846);
526 
527  ‪ArrayUtility::setValueByPath(['foo' => 'bar'], '/foo', 'value');
528  }
529 
534  {
535  $this->assertSame(['foo' => ['value']], ‪ArrayUtility::setValueByPath(['foo' => []], 'foo/0', 'value'));
536  }
537 
542  {
543  $this->assertSame(['value', 'bar'], ‪ArrayUtility::setValueByPath(['foo', 'bar'], '0', 'value'));
544  }
545 
556  {
557  $testObject = new \stdClass();
558  $testObject->foo = 'foo';
559  $testObject->bar = 'bar';
560  return [
561  'set integer value: 42' => [
562  [
563  'foo' => [
564  'bar' => [
565  'baz' => 0
566  ]
567  ]
568  ],
569  'foo/bar/baz',
570  42,
571  [
572  'foo' => [
573  'bar' => [
574  'baz' => 42
575  ]
576  ]
577  ]
578  ],
579  'set integer value: 0' => [
580  [
581  'foo' => [
582  'bar' => [
583  'baz' => 42
584  ]
585  ]
586  ],
587  'foo/bar/baz',
588  0,
589  [
590  'foo' => [
591  'bar' => [
592  'baz' => 0
593  ]
594  ]
595  ]
596  ],
597  'set null value' => [
598  [
599  'foo' => [
600  'bar' => [
601  'baz' => 42
602  ]
603  ]
604  ],
605  'foo/bar/baz',
606  null,
607  [
608  'foo' => [
609  'bar' => [
610  'baz' => null
611  ]
612  ]
613  ]
614  ],
615  'set array value' => [
616  [
617  'foo' => [
618  'bar' => [
619  'baz' => 42
620  ]
621  ]
622  ],
623  'foo/bar/baz',
624  [
625  'foo' => 123
626  ],
627  [
628  'foo' => [
629  'bar' => [
630  'baz' => [
631  'foo' => 123
632  ]
633  ]
634  ]
635  ]
636  ],
637  'set boolean value: FALSE' => [
638  [
639  'foo' => [
640  'bar' => [
641  'baz' => true
642  ]
643  ]
644  ],
645  'foo/bar/baz',
646  false,
647  [
648  'foo' => [
649  'bar' => [
650  'baz' => false
651  ]
652  ]
653  ]
654  ],
655  'set boolean value: TRUE' => [
656  [
657  'foo' => [
658  'bar' => [
659  'baz' => null
660  ]
661  ]
662  ],
663  'foo/bar/baz',
664  true,
665  [
666  'foo' => [
667  'bar' => [
668  'baz' => true
669  ]
670  ]
671  ]
672  ],
673  'set object value' => [
674  [
675  'foo' => [
676  'bar' => [
677  'baz' => null
678  ]
679  ]
680  ],
681  'foo/bar/baz',
682  $testObject,
683  [
684  'foo' => [
685  'bar' => [
686  'baz' => $testObject
687  ]
688  ]
689  ]
690  ],
691  'multi keys in array' => [
692  [
693  'foo' => [
694  'bar' => [
695  'baz' => 'value'
696  ],
697  'bar2' => [
698  'baz' => 'value'
699  ]
700  ]
701  ],
702  'foo/bar2/baz',
703  'newValue',
704  [
705  'foo' => [
706  'bar' => [
707  'baz' => 'value'
708  ],
709  'bar2' => [
710  'baz' => 'newValue'
711  ]
712  ]
713  ]
714  ]
715  ];
716  }
717 
726  public function ‪setValueByPathSetsCorrectValue(array $array, $path, $value, $expectedResult)
727  {
728  $this->assertEquals(
729  $expectedResult,
730  ‪ArrayUtility::setValueByPath($array, $path, $value)
731  );
732  }
733 
734  /**********************
735  /* Tests concerning removeByPath
736  ***********************/
737 
742  {
743  $this->expectException(\RuntimeException::class);
744  $this->expectExceptionCode(1371757718);
745 
747  }
748 
753  {
754  $this->expectException(\RuntimeException::class);
755  $this->expectExceptionCode(1371757719);
756 
757  ‪ArrayUtility::removeByPath([], ['foo']);
758  }
759 
764  {
765  $inputArray = [
766  'foo' => [
767  'bar' => 42,
768  ]
769  ];
770 
771  $this->expectException(\RuntimeException::class);
772  $this->expectExceptionCode(1371757720);
773 
774  ‪ArrayUtility::removeByPath($inputArray, 'foo//bar');
775  }
776 
781  {
782  $inputArray = [
783  'foo' => ['bar']
784  ];
785 
786  $this->assertSame(['foo' => []], ‪ArrayUtility::removeByPath($inputArray, 'foo/0'));
787  }
788 
793  {
794  $inputArray = ['bar'];
795 
796  $this->assertSame([], ‪ArrayUtility::removeByPath($inputArray, '0'));
797  }
798 
803  {
804  $inputArray = [
805  'foo' => [
806  'bar' => 42,
807  ]
808  ];
809 
810  $this->expectException(\RuntimeException::class);
811  $this->expectExceptionCode(1371758436);
812 
813  ‪ArrayUtility::removeByPath($inputArray, 'foo/baz');
814  }
815 
820  {
821  $inputArray = [
822  'foo' => [
823  'bar' => 42,
824  ]
825  ];
826 
827  $this->expectException(MissingArrayPathException::class);
828  $this->expectExceptionCode(1371758436);
829 
830  ‪ArrayUtility::removeByPath($inputArray, 'foo/baz');
831  }
832 
837  {
838  $inputArray = [
839  'foo' => [
840  'toRemove' => 42,
841  'keep' => 23
842  ],
843  ];
844  $path = 'foo.toRemove';
845  $expected = [
846  'foo' => [
847  'keep' => 23,
848  ],
849  ];
850  $this->assertEquals(
851  $expected,
852  ‪ArrayUtility::removeByPath($inputArray, $path, '.')
853  );
854  }
855 
860  {
861  return [
862  'single value' => [
863  [
864  'foo' => [
865  'toRemove' => 42,
866  'keep' => 23
867  ],
868  ],
869  'foo/toRemove',
870  [
871  'foo' => [
872  'keep' => 23,
873  ],
874  ],
875  ],
876  'whole array' => [
877  [
878  'foo' => [
879  'bar' => 42
880  ],
881  ],
882  'foo',
883  [],
884  ],
885  'sub array' => [
886  [
887  'foo' => [
888  'keep' => 23,
889  'toRemove' => [
890  'foo' => 'bar',
891  ],
892  ],
893  ],
894  'foo/toRemove',
895  [
896  'foo' => [
897  'keep' => 23,
898  ],
899  ],
900  ],
901  ];
902  }
903 
911  public function ‪removeByPathRemovesCorrectPath(array $array, $path, $expectedResult)
912  {
913  $this->assertEquals(
914  $expectedResult,
915  ‪ArrayUtility::removeByPath($array, $path)
916  );
917  }
918 
920  // Tests concerning sortByKeyRecursive
922 
926  {
927  $unsortedArray = [
928  'z' => null,
929  'a' => null,
930  'd' => [
931  'c' => null,
932  'b' => null,
933  'd' => null,
934  'a' => null
935  ]
936  ];
937  $expectedResult = [
938  'a' => null,
939  'd' => [
940  'a' => null,
941  'b' => null,
942  'c' => null,
943  'd' => null
944  ],
945  'z' => null
946  ];
947  $this->assertSame($expectedResult, ‪ArrayUtility::sortByKeyRecursive($unsortedArray));
948  }
949 
951  // Tests concerning sortArraysByKey
953 
957  {
958  return [
959  'assoc array index' => [
960  [
961  '22' => [
962  'uid' => '22',
963  'title' => 'c',
964  'dummy' => 2
965  ],
966  '24' => [
967  'uid' => '24',
968  'title' => 'a',
969  'dummy' => 3
970  ],
971  '23' => [
972  'uid' => '23',
973  'title' => 'b',
974  'dummy' => 4
975  ],
976  ],
977  'title',
978  true,
979  [
980  '24' => [
981  'uid' => '24',
982  'title' => 'a',
983  'dummy' => 3
984  ],
985  '23' => [
986  'uid' => '23',
987  'title' => 'b',
988  'dummy' => 4
989  ],
990  '22' => [
991  'uid' => '22',
992  'title' => 'c',
993  'dummy' => 2
994  ],
995  ],
996  ],
997  'numeric array index' => [
998  [
999  22 => [
1000  'uid' => '22',
1001  'title' => 'c',
1002  'dummy' => 2
1003  ],
1004  24 => [
1005  'uid' => '24',
1006  'title' => 'a',
1007  'dummy' => 3
1008  ],
1009  23 => [
1010  'uid' => '23',
1011  'title' => 'b',
1012  'dummy' => 4
1013  ],
1014  ],
1015  'title',
1016  true,
1017  [
1018  24 => [
1019  'uid' => '24',
1020  'title' => 'a',
1021  'dummy' => 3
1022  ],
1023  23 => [
1024  'uid' => '23',
1025  'title' => 'b',
1026  'dummy' => 4
1027  ],
1028  22 => [
1029  'uid' => '22',
1030  'title' => 'c',
1031  'dummy' => 2
1032  ],
1033  ],
1034  ],
1035  'numeric array index DESC' => [
1036  [
1037  23 => [
1038  'uid' => '23',
1039  'title' => 'b',
1040  'dummy' => 4
1041  ],
1042  22 => [
1043  'uid' => '22',
1044  'title' => 'c',
1045  'dummy' => 2
1046  ],
1047  24 => [
1048  'uid' => '24',
1049  'title' => 'a',
1050  'dummy' => 3
1051  ],
1052  ],
1053  'title',
1054  false,
1055  [
1056  22 => [
1057  'uid' => '22',
1058  'title' => 'c',
1059  'dummy' => 2
1060  ],
1061  23 => [
1062  'uid' => '23',
1063  'title' => 'b',
1064  'dummy' => 4
1065  ],
1066  24 => [
1067  'uid' => '24',
1068  'title' => 'a',
1069  'dummy' => 3
1070  ],
1071  ],
1072  ],
1073  ];
1074  }
1075 
1084  public function ‪sortArraysByKeyCheckIfSortingIsCorrect(array $array, $key, $ascending, $expectedResult)
1085  {
1086  $sortedArray = ‪ArrayUtility::sortArraysByKey($array, $key, $ascending);
1087  $this->assertSame($expectedResult, $sortedArray);
1088  }
1089 
1094  {
1095  $this->expectException(\RuntimeException::class);
1096  $this->expectExceptionCode(1373727309);
1097 
1098  ‪ArrayUtility::sortArraysByKey([['a'], ['a']], 'dummy');
1099  }
1100 
1102  // Tests concerning arrayExport
1104 
1108  {
1109  $array = [
1110  'foo' => [
1111  'bar' => 42,
1112  'bar2' => [
1113  'baz' => 'val\'ue',
1114  'baz2' => true,
1115  'baz3' => false,
1116  'baz4' => []
1117  ]
1118  ],
1119  'baz' => 23,
1120  'foobar' => null,
1121  'qux' => 0.1,
1122  'qux2' => 0.000000001,
1123  ];
1124  $expected =
1125  '[' . LF .
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 .
1133  ' ],' . LF .
1134  ' ],' . LF .
1135  ' \'baz\' => 23,' . LF .
1136  ' \'foobar\' => null,' . LF .
1137  ' \'qux\' => 0.1,' . LF .
1138  ' \'qux2\' => 1.0E-9,' . LF .
1139  ']';
1140  $this->assertSame($expected, ‪ArrayUtility::arrayExport($array));
1141  }
1142 
1147  {
1148  $array = [
1149  'foo' => [
1150  'bar' => new \stdClass()
1151  ]
1152  ];
1153 
1154  $this->expectException(\RuntimeException::class);
1155  $this->expectExceptionCode(1342294987);
1156 
1158  }
1159 
1164  {
1165  $array = [
1166  'foo' => 'string key',
1167  23 => 'integer key',
1168  '42' => 'string key representing integer'
1169  ];
1170  $expected =
1171  '[' . LF .
1172  ' \'foo\' => \'string key\',' . LF .
1173  ' 23 => \'integer key\',' . LF .
1174  ' 42 => \'string key representing integer\',' . LF .
1175  ']';
1176  $this->assertSame($expected, ‪ArrayUtility::arrayExport($array));
1177  }
1178 
1183  {
1184  $array = [
1185  0 => 'zero',
1186  1 => 'one',
1187  2 => 'two'
1188  ];
1189  $expected =
1190  '[' . LF .
1191  ' \'zero\',' . LF .
1192  ' \'one\',' . LF .
1193  ' \'two\',' . LF .
1194  ']';
1195  $this->assertSame($expected, ‪ArrayUtility::arrayExport($array));
1196  }
1197 
1202  {
1203  $array = [
1204  0 => 'zero',
1205  1 => 'one',
1206  3 => 'three',
1207  4 => 'four'
1208  ];
1209  $expected =
1210  '[' . LF .
1211  ' 0 => \'zero\',' . LF .
1212  ' 1 => \'one\',' . LF .
1213  ' 3 => \'three\',' . LF .
1214  ' 4 => \'four\',' . LF .
1215  ']';
1216  $this->assertSame($expected, ‪ArrayUtility::arrayExport($array));
1217  }
1218 
1220  // Tests concerning flatten
1222 
1227  {
1228  return [
1229  'plain array' => [
1230  [
1231  'first' => 1,
1232  'second' => 2
1233  ],
1234  [
1235  'first' => 1,
1236  'second' => 2
1237  ]
1238  ],
1239  'plain array with faulty dots' => [
1240  [
1241  'first.' => 1,
1242  'second.' => 2
1243  ],
1244  [
1245  'first' => 1,
1246  'second' => 2
1247  ]
1248  ],
1249  'nested array of 2 levels' => [
1250  [
1251  'first.' => [
1252  'firstSub' => 1
1253  ],
1254  'second.' => [
1255  'secondSub' => 2
1256  ]
1257  ],
1258  [
1259  'first.firstSub' => 1,
1260  'second.secondSub' => 2
1261  ]
1262  ],
1263  'nested array of 2 levels with faulty dots' => [
1264  [
1265  'first.' => [
1266  'firstSub.' => 1
1267  ],
1268  'second.' => [
1269  'secondSub.' => 2
1270  ]
1271  ],
1272  [
1273  'first.firstSub' => 1,
1274  'second.secondSub' => 2
1275  ]
1276  ],
1277  'nested array of 3 levels' => [
1278  [
1279  'first.' => [
1280  'firstSub.' => [
1281  'firstSubSub' => 1
1282  ]
1283  ],
1284  'second.' => [
1285  'secondSub.' => [
1286  'secondSubSub' => 2
1287  ]
1288  ]
1289  ],
1290  [
1291  'first.firstSub.firstSubSub' => 1,
1292  'second.secondSub.secondSubSub' => 2
1293  ]
1294  ],
1295  'nested array of 3 levels with faulty dots' => [
1296  [
1297  'first.' => [
1298  'firstSub.' => [
1299  'firstSubSub.' => 1
1300  ]
1301  ],
1302  'second.' => [
1303  'secondSub.' => [
1304  'secondSubSub.' => 2
1305  ]
1306  ]
1307  ],
1308  [
1309  'first.firstSub.firstSubSub' => 1,
1310  'second.secondSub.secondSubSub' => 2
1311  ]
1312  ]
1313  ];
1314  }
1315 
1322  public function ‪flattenCalculatesExpectedResult(array $array, array $expected)
1323  {
1324  $this->assertEquals($expected, ‪ArrayUtility::flatten($array));
1325  }
1326 
1328  // Tests concerning intersectRecursive
1330 
1335  {
1336  $sameObject = new \stdClass();
1337  return [
1338  // array($source, $mask, $expected)
1339  'empty array is returned if source is empty array' => [
1340  [],
1341  [
1342  'foo' => 'bar',
1343  ],
1344  [],
1345  ],
1346  'empty array is returned if mask is empty' => [
1347  [
1348  'foo' => 'bar',
1349  ],
1350  [],
1351  [],
1352  ],
1353  'key is kept on first level if exists in mask' => [
1354  [
1355  'foo' => 42,
1356  ],
1357  [
1358  'foo' => 42,
1359  ],
1360  [
1361  'foo' => 42,
1362  ],
1363  ],
1364  'value of key in source is kept if mask has different value' => [
1365  [
1366  'foo' => 42,
1367  ],
1368  [
1369  'foo' => new \stdClass(),
1370  ],
1371  [
1372  'foo' => 42,
1373  ],
1374  ],
1375  'key is kept on first level if according mask value is NULL' => [
1376  [
1377  'foo' => 42,
1378  ],
1379  [
1380  'foo' => null,
1381  ],
1382  [
1383  'foo' => 42,
1384  ],
1385  ],
1386  'null in source value is kept' => [
1387  [
1388  'foo' => null,
1389  ],
1390  [
1391  'foo' => 'bar',
1392  ],
1393  [
1394  'foo' => null,
1395  ]
1396  ],
1397  'mask does not add new keys' => [
1398  [
1399  'foo' => 42,
1400  ],
1401  [
1402  'foo' => 23,
1403  'bar' => [
1404  4711
1405  ],
1406  ],
1407  [
1408  'foo' => 42,
1409  ],
1410  ],
1411  'mask does not overwrite simple values with arrays' => [
1412  [
1413  'foo' => 42,
1414  ],
1415  [
1416  'foo' => [
1417  'bar' => 23,
1418  ],
1419  ],
1420  [
1421  'foo' => 42,
1422  ],
1423  ],
1424  'key is kept on first level if according mask value is array' => [
1425  [
1426  'foo' => 42,
1427  ],
1428  [
1429  'foo' => [
1430  'bar' => 23
1431  ],
1432  ],
1433  [
1434  'foo' => 42,
1435  ],
1436  ],
1437  'full array is kept if value is array and mask value is simple type' => [
1438  [
1439  'foo' => [
1440  'bar' => 23
1441  ],
1442  ],
1443  [
1444  'foo' => 42,
1445  ],
1446  [
1447  'foo' => [
1448  'bar' => 23
1449  ],
1450  ],
1451  ],
1452  'key handling is type agnostic' => [
1453  [
1454  42 => 'foo',
1455  ],
1456  [
1457  '42' => 'bar',
1458  ],
1459  [
1460  42 => 'foo',
1461  ],
1462  ],
1463  'value is same if value is object' => [
1464  [
1465  'foo' => $sameObject,
1466  ],
1467  [
1468  'foo' => 'something',
1469  ],
1470  [
1471  'foo' => $sameObject,
1472  ],
1473  ],
1474  'mask does not add simple value to result if key does not exist in source' => [
1475  [
1476  'foo' => '42',
1477  ],
1478  [
1479  'foo' => '42',
1480  'bar' => 23
1481  ],
1482  [
1483  'foo' => '42',
1484  ],
1485  ],
1486  'array of source is kept if value of mask key exists but is no array' => [
1487  [
1488  'foo' => '42',
1489  'bar' => [
1490  'baz' => 23
1491  ],
1492  ],
1493  [
1494  'foo' => 'value is not significant',
1495  'bar' => null,
1496  ],
1497  [
1498  'foo' => '42',
1499  'bar' => [
1500  'baz' => 23
1501  ],
1502  ],
1503  ],
1504  'sub arrays are kept if mask has according sub array key and is similar array' => [
1505  [
1506  'first1' => 42,
1507  'first2' => [
1508  'second1' => 23,
1509  'second2' => 4711,
1510  ],
1511  ],
1512  [
1513  'first1' => 42,
1514  'first2' => [
1515  'second1' => 'exists but different',
1516  ],
1517  ],
1518  [
1519  'first1' => 42,
1520  'first2' => [
1521  'second1' => 23,
1522  ],
1523  ],
1524  ],
1525  ];
1526  }
1527 
1535  public function ‪intersectRecursiveCalculatesExpectedResult(array $source, array $mask, array $expected)
1536  {
1537  $this->assertSame($expected, ‪ArrayUtility::intersectRecursive($source, $mask));
1538  }
1539 
1541  // Tests concerning renumberKeysToAvoidLeapsIfKeysAreAllNumeric
1543 
1547  {
1548  return [
1549  'empty array is returned if source is empty array' => [
1550  [],
1551  []
1552  ],
1553  'returns self if array is already numerically keyed' => [
1554  [1, 2, 3],
1555  [1, 2, 3]
1556  ],
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'],
1560  ],
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'],
1564  ],
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'],
1568  ],
1569  'returns unchanged if keys end with a dot' => [
1570  ['2.' => 'Two', '1.' => 'One', '0.' => 'Zero'],
1571  ['2.' => 'Two', '1.' => 'One', '0.' => 'Zero'],
1572  ],
1573  'return self with nested numerically keyed array' => [
1574  [
1575  'One',
1576  'Two',
1577  'Three',
1578  [
1579  'sub.One',
1580  'sub.Two',
1581  ]
1582  ],
1583  [
1584  'One',
1585  'Two',
1586  'Three',
1587  [
1588  'sub.One',
1589  'sub.Two',
1590  ]
1591  ]
1592  ],
1593  'returns correctly with nested numerically keyed array with leaps' => [
1594  [
1595  'One',
1596  'Two',
1597  'Three',
1598  [
1599  0 => 'sub.One',
1600  2 => 'sub.Two',
1601  ]
1602  ],
1603  [
1604  'One',
1605  'Two',
1606  'Three',
1607  [
1608  'sub.One',
1609  'sub.Two',
1610  ]
1611  ]
1612  ],
1613  'returns correctly with nested string-keyed array' => [
1614  [
1615  'One',
1616  'Two',
1617  'Three',
1618  [
1619  'one' => 'sub.One',
1620  'two' => 'sub.Two',
1621  ]
1622  ],
1623  [
1624  'One',
1625  'Two',
1626  'Three',
1627  [
1628  'one' => 'sub.One',
1629  'two' => 'sub.Two',
1630  ]
1631  ]
1632  ],
1633  'returns correctly with deeply nested arrays' => [
1634  [
1635  'One',
1636  'Two',
1637  [
1638  'one' => 1,
1639  'two' => 2,
1640  'three' => [
1641  2 => 'SubSubOne',
1642  5 => 'SubSubTwo',
1643  9 => [0, 1, 2],
1644  []
1645  ]
1646  ]
1647  ],
1648  [
1649  'One',
1650  'Two',
1651  [
1652  'one' => 1,
1653  'two' => 2,
1654  'three' => [
1655  'SubSubOne',
1656  'SubSubTwo',
1657  [0, 1, 2],
1658  []
1659  ]
1660  ]
1661  ]
1662  ]
1663  ];
1664  }
1665 
1672  public function ‪renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder(array $inputArray, array $expected)
1673  {
1674  $this->assertEquals($expected, ‪ArrayUtility::renumberKeysToAvoidLeapsIfKeysAreAllNumeric($inputArray));
1675  }
1676 
1681  {
1682  return [
1683  'Override array can reset string to array' => [
1684  [
1685  'first' => [
1686  'second' => 'foo',
1687  ],
1688  ],
1689  [
1690  'first' => [
1691  'second' => ['third' => 'bar'],
1692  ],
1693  ],
1694  true,
1695  true,
1696  true,
1697  [
1698  'first' => [
1699  'second' => ['third' => 'bar'],
1700  ],
1701  ],
1702  ],
1703  'Override array does not reset array to string (weird!)' => [
1704  [
1705  'first' => [],
1706  ],
1707  [
1708  'first' => 'foo',
1709  ],
1710  true,
1711  true,
1712  true,
1713  [
1714  'first' => [], // This is rather unexpected, naive expectation: first => 'foo'
1715  ],
1716  ],
1717  'Override array does override string with null' => [
1718  [
1719  'first' => 'foo',
1720  ],
1721  [
1722  'first' => null,
1723  ],
1724  true,
1725  true,
1726  true,
1727  [
1728  'first' => null,
1729  ],
1730  ],
1731  'Override array does override null with string' => [
1732  [
1733  'first' => null,
1734  ],
1735  [
1736  'first' => 'foo',
1737  ],
1738  true,
1739  true,
1740  true,
1741  [
1742  'first' => 'foo',
1743  ],
1744  ],
1745  'Override array does override null with empty string' => [
1746  [
1747  'first' => null,
1748  ],
1749  [
1750  'first' => '',
1751  ],
1752  true,
1753  true,
1754  true,
1755  [
1756  'first' => '',
1757  ],
1758  ],
1759  'Override array does not override string with NULL if requested' => [
1760  [
1761  'first' => 'foo',
1762  ],
1763  [
1764  'first' => null,
1765  ],
1766  true,
1767  false, // no include empty values
1768  true,
1769  [
1770  'first' => 'foo',
1771  ],
1772  ],
1773  'Override array does override null with null' => [
1774  [
1775  'first' => null,
1776  ],
1777  [
1778  'first' => null,
1779  ],
1780  true,
1781  true,
1782  true,
1783  [
1784  'first' => '',
1785  ],
1786  ],
1787  'Override array can __UNSET values' => [
1788  [
1789  'first' => [
1790  'second' => 'second',
1791  'third' => 'third',
1792  ],
1793  'fifth' => [],
1794  ],
1795  [
1796  'first' => [
1797  'second' => 'overrule',
1798  'third' => '__UNSET',
1799  'fourth' => 'overrile',
1800  ],
1801  'fifth' => '__UNSET',
1802  ],
1803  true,
1804  true,
1805  true,
1806  [
1807  'first' => [
1808  'second' => 'overrule',
1809  'fourth' => 'overrile',
1810  ],
1811  ],
1812  ],
1813  'Override can add keys' => [
1814  [
1815  'first' => 'foo',
1816  ],
1817  [
1818  'second' => 'bar',
1819  ],
1820  true,
1821  true,
1822  true,
1823  [
1824  'first' => 'foo',
1825  'second' => 'bar',
1826  ],
1827  ],
1828  'Override does not add key if __UNSET' => [
1829  [
1830  'first' => 'foo',
1831  ],
1832  [
1833  'second' => '__UNSET',
1834  ],
1835  true,
1836  true,
1837  true,
1838  [
1839  'first' => 'foo',
1840  ],
1841  ],
1842  'Override does not add key if not requested' => [
1843  [
1844  'first' => 'foo',
1845  ],
1846  [
1847  'second' => 'bar',
1848  ],
1849  false, // no add keys
1850  true,
1851  true,
1852  [
1853  'first' => 'foo',
1854  ],
1855  ],
1856  'Override does not add key if not requested with add include empty values' => [
1857  [
1858  'first' => 'foo',
1859  ],
1860  [
1861  'second' => 'bar',
1862  ],
1863  false, // no add keys
1864  false, // no include empty values
1865  true,
1866  [
1867  'first' => 'foo',
1868  ],
1869  ],
1870  'Override does not override string with empty string if requested' => [
1871  [
1872  'first' => 'foo',
1873  ],
1874  [
1875  'first' => '',
1876  ],
1877  true,
1878  false, // no include empty values
1879  true,
1880  [
1881  'first' => 'foo',
1882  ],
1883  ],
1884  'Override array does merge instead of __UNSET if requested (weird!)' => [
1885  [
1886  'first' => [
1887  'second' => 'second',
1888  'third' => 'third',
1889  ],
1890  'fifth' => [],
1891  ],
1892  [
1893  'first' => [
1894  'second' => 'overrule',
1895  'third' => '__UNSET',
1896  'fourth' => 'overrile',
1897  ],
1898  'fifth' => '__UNSET',
1899  ],
1900  true,
1901  true,
1902  false,
1903  [
1904  'first' => [
1905  'second' => 'overrule',
1906  'third' => '__UNSET', // overruled
1907  'fourth' => 'overrile',
1908  ],
1909  'fifth' => [], // not overruled with string here, naive expectation: 'fifth' => '__UNSET'
1910  ],
1911  ],
1912  ];
1913  }
1914 
1925  public function ‪mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected)
1926  {
1927  ‪ArrayUtility::mergeRecursiveWithOverrule($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature);
1928  $this->assertEquals($expected, $input1);
1929  }
1930 
1932  // Tests concerning removeArrayEntryByValue
1934 
1938  {
1939  $inputArray = [
1940  '0' => 'test1',
1941  '1' => 'test2',
1942  '2' => 'test3',
1943  '3' => 'test2'
1944  ];
1945  $compareValue = 'test2';
1946  $expectedResult = [
1947  '0' => 'test1',
1948  '2' => 'test3'
1949  ];
1950  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
1951  $this->assertEquals($expectedResult, $actualResult);
1952  }
1953 
1958  {
1959  $inputArray = [
1960  '0' => 'foo',
1961  '1' => [
1962  '10' => 'bar'
1963  ],
1964  '2' => 'bar'
1965  ];
1966  $compareValue = 'bar';
1967  $expectedResult = [
1968  '0' => 'foo',
1969  '1' => []
1970  ];
1971  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
1972  $this->assertEquals($expectedResult, $actualResult);
1973  }
1974 
1979  {
1980  $inputArray = [
1981  '0' => 'foo',
1982  '1' => '',
1983  '2' => 'bar'
1984  ];
1985  $compareValue = '';
1986  $expectedResult = [
1987  '0' => 'foo',
1988  '2' => 'bar'
1989  ];
1990  $actualResult = ‪ArrayUtility::removeArrayEntryByValue($inputArray, $compareValue);
1991  $this->assertEquals($expectedResult, $actualResult);
1992  }
1993 
1995  // Tests concerning keepItemsInArray
1997 
2004  public function ‪keepItemsInArrayWorksWithOneArgument($search, $array, $expected)
2005  {
2006  $this->assertEquals($expected, ‪ArrayUtility::keepItemsInArray($array, $search));
2007  }
2008 
2015  {
2016  $array = [
2017  0 => 0,
2018  'one' => 'one',
2019  'two' => 'two',
2020  'three' => 'three'
2021  ];
2022  return [
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']]
2028  ];
2029  }
2030 
2039  {
2040  $array = [
2041  'aa' => ['first', 'second'],
2042  'bb' => ['third', 'fourth'],
2043  'cc' => ['fifth', 'sixth']
2044  ];
2045  $expected = ['bb' => ['third', 'fourth']];
2046  $keepItems = 'third';
2048  $array,
2049  $keepItems,
2050  function ($value) {
2051  return $value[0];
2052  }
2053  );
2054  $this->assertEquals($expected, $match);
2055  }
2056 
2058  // Tests concerning remapArrayKeys
2060 
2064  {
2065  $array = [
2066  'one' => 'one',
2067  'two' => 'two',
2068  'three' => 'three'
2069  ];
2070  $keyMapping = [
2071  'one' => '1',
2072  'two' => '2'
2073  ];
2074  $expected = [
2075  '1' => 'one',
2076  '2' => 'two',
2077  'three' => 'three'
2078  ];
2079  ‪ArrayUtility::remapArrayKeys($array, $keyMapping);
2080  $this->assertEquals($expected, $array);
2081  }
2082 
2084  // Tests concerning arrayDiffAssocRecursive
2086 
2090  {
2091  $array1 = [
2092  'key1' => 'value1',
2093  'key2' => 'value2',
2094  'key3' => 'value3'
2095  ];
2096  $array2 = [
2097  'key1' => 'value1',
2098  'key3' => 'value3'
2099  ];
2100  $expectedResult = [
2101  'key2' => 'value2'
2102  ];
2103  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2);
2104  $this->assertEquals($expectedResult, $actualResult);
2105  }
2106 
2111  {
2112  $array1 = [
2113  'key1' => 'value1',
2114  'key2' => [
2115  'key21' => 'value21',
2116  'key22' => 'value22',
2117  'key23' => [
2118  'key231' => 'value231',
2119  'key232' => 'value232'
2120  ]
2121  ]
2122  ];
2123  $array2 = [
2124  'key1' => 'valueDoesNotMatter',
2125  'key2' => [
2126  'key21' => 'value21',
2127  'key23' => [
2128  'key231' => 'value231'
2129  ]
2130  ]
2131  ];
2132  $expectedResult = [
2133  'key2' => [
2134  'key22' => 'value22',
2135  'key23' => [
2136  'key232' => 'value232'
2137  ]
2138  ]
2139  ];
2140  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2);
2141  $this->assertEquals($expectedResult, $actualResult);
2142  }
2143 
2148  {
2149  $array1 = [
2150  'key1' => [
2151  'key11' => 'value11',
2152  'key12' => 'value12'
2153  ],
2154  'key2' => 'value2',
2155  'key3' => 'value3'
2156  ];
2157  $array2 = [
2158  'key1' => 'value1',
2159  'key2' => [
2160  'key21' => 'valueDoesNotMatter'
2161  ]
2162  ];
2163  $expectedResult = [
2164  'key3' => 'value3'
2165  ];
2166  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2);
2167  $this->assertEquals($expectedResult, $actualResult);
2168  }
2169 
2174  {
2175  $array1 = [
2176  'key1' => [
2177  'key11' => 'value11',
2178  'key12' => 'value12'
2179  ],
2180  'key2' => 'value2',
2181  'key3' => 'value3'
2182  ];
2183  $array2 = [
2184  'key1' => [
2185  'key11' => 'valueDoesNotMatter',
2186  'key12' => 'value12'
2187  ],
2188  'key2' => 'value2',
2189  'key3' => 'value3'
2190  ];
2191  $expectedResult = [];
2192  $actualResult = ‪ArrayUtility::arrayDiffAssocRecursive($array1, $array2);
2193  $this->assertEquals($expectedResult, $actualResult);
2194  }
2195 
2197  // Tests concerning naturalKeySortRecursive
2199 
2204  {
2205  $testArray = [
2206  'bb' => 'bb',
2207  'ab' => 'ab',
2208  '123' => '123',
2209  'aaa' => 'aaa',
2210  'abc' => 'abc',
2211  '23' => '23',
2212  'ba' => 'ba',
2213  'bad' => 'bad',
2214  '2' => '2',
2215  'zap' => 'zap',
2216  '210' => '210'
2217  ];
2218  $expectedResult = [
2219  '2',
2220  '23',
2221  '123',
2222  '210',
2223  'aaa',
2224  'ab',
2225  'abc',
2226  'ba',
2227  'bad',
2228  'bb',
2229  'zap'
2230  ];
2232  $this->assertEquals($expectedResult, array_values($testArray));
2233  }
2234 
2239  {
2240  $testArray = [
2241  '2' => '2',
2242  'bb' => 'bb',
2243  'ab' => 'ab',
2244  '23' => '23',
2245  'aaa' => [
2246  'bb' => 'bb',
2247  'ab' => 'ab',
2248  '123' => '123',
2249  'aaa' => 'aaa',
2250  '2' => '2',
2251  'abc' => 'abc',
2252  'ba' => 'ba',
2253  '23' => '23',
2254  'bad' => [
2255  'bb' => 'bb',
2256  'ab' => 'ab',
2257  '123' => '123',
2258  'aaa' => 'aaa',
2259  'abc' => 'abc',
2260  '23' => '23',
2261  'ba' => 'ba',
2262  'bad' => 'bad',
2263  '2' => '2',
2264  'zap' => 'zap',
2265  '210' => '210'
2266  ],
2267  '210' => '210',
2268  'zap' => 'zap'
2269  ],
2270  'abc' => 'abc',
2271  'ba' => 'ba',
2272  '210' => '210',
2273  'bad' => 'bad',
2274  '123' => '123',
2275  'zap' => 'zap'
2276  ];
2277  $expectedResult = [
2278  '2',
2279  '23',
2280  '123',
2281  '210',
2282  'aaa',
2283  'ab',
2284  'abc',
2285  'ba',
2286  'bad',
2287  'bb',
2288  'zap'
2289  ];
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)));
2294  }
2295 
2302  {
2303  return [
2304  'ordered list of plain numeric keys' => [
2305  'input' => [
2306  '10' => 'foo',
2307  '20' => 'bar',
2308  ],
2309  'expected' => [
2310  10,
2311  20,
2312  ],
2313  ],
2314  'unordered list of plain numeric keys' => [
2315  'input' => [
2316  '20' => 'bar',
2317  '10' => 'foo',
2318  ],
2319  'expected' => [
2320  10,
2321  20,
2322  ],
2323  ],
2324  'list of string keys' => [
2325  'input' => [
2326  '10.' => [
2327  'wrap' => 'foo',
2328  ],
2329  '20.' => [
2330  'wrap' => 'bar',
2331  ],
2332  ],
2333  'expected' => [
2334  10,
2335  20,
2336  ],
2337  ],
2338  'list of mixed keys' => [
2339  'input' => [
2340  '10' => 'foo',
2341  '20.' => [
2342  'wrap' => 'bar',
2343  ],
2344  ],
2345  'expected' => [
2346  10,
2347  20,
2348  ],
2349  ],
2350  'list of mixed keys with one not interpreted as integer' => [
2351  'input' => [
2352  '10' => 'foo',
2353  'bla20.' => [
2354  'wrap' => 'bar',
2355  ],
2356  ],
2357  'expected' => [
2358  0,
2359  10,
2360  ],
2361  ],
2362  'list of mixed keys with more than one not interpreted as integer' => [
2363  'input' => [
2364  '10' => 'foo',
2365  'bla20.' => [
2366  'wrap' => 'bar',
2367  ],
2368  'bla21.' => [
2369  'wrap' => 'foobar',
2370  ],
2371  ],
2372  'expected' => [
2373  0,
2374  10,
2375  ],
2376  ],
2377  ];
2378  }
2379 
2388  {
2389  $result = ‪ArrayUtility::filterAndSortByNumericKeys($input, true);
2390  $this->assertEquals($result, $expected);
2391  }
2392 
2399  {
2400  return [
2401  'ordered list of plain numeric keys' => [
2402  'input' => [
2403  '10' => 'foo',
2404  '20' => 'bar',
2405  ],
2406  'expected' => [
2407  10,
2408  20,
2409  ],
2410  ],
2411  'unordered list of plain numeric keys' => [
2412  'input' => [
2413  '20' => 'bar',
2414  '10' => 'foo',
2415  ],
2416  'expected' => [
2417  10,
2418  20,
2419  ],
2420  ],
2421  'list of string keys' => [
2422  'input' => [
2423  '10.' => [
2424  'wrap' => 'foo',
2425  ],
2426  '20.' => [
2427  'wrap' => 'bar',
2428  ],
2429  ],
2430  'expected' => [],
2431  ],
2432  'list of mixed keys' => [
2433  'input' => [
2434  '10' => 'foo',
2435  '20.' => [
2436  'wrap' => 'bar',
2437  ],
2438  ],
2439  'expected' => [
2440  10,
2441  ],
2442  ],
2443  ];
2444  }
2445 
2454  {
2456  $this->assertEquals($result, $expected);
2457  }
2458 
2465  {
2466  return [
2467  [
2468  [
2469  '20' => 'test1',
2470  '11' => 'test2',
2471  '16' => 'test3',
2472  ],
2473  [
2474  '11' => 'test2',
2475  '16' => 'test3',
2476  '20' => 'test1',
2477  ]
2478  ],
2479  [
2480  [
2481  '20' => 'test1',
2482  '16.5' => 'test2',
2483  '16' => 'test3',
2484  ],
2485  [
2486  '20' => 'test1',
2487  '16.5' => 'test2',
2488  '16' => 'test3',
2489  ]
2490  ],
2491  [
2492  [
2493  '20' => 'test20',
2494  'somestring' => 'teststring',
2495  '16' => 'test16',
2496  ],
2497  [
2498  '20' => 'test20',
2499  'somestring' => 'teststring',
2500  '16' => 'test16',
2501  ]
2502  ],
2503  ];
2504  }
2505 
2514  public function ‪sortArrayWithIntegerKeysSortsNumericArrays(array $arrayToSort, array $expectedArray)
2515  {
2516  $sortedArray = ‪ArrayUtility::sortArrayWithIntegerKeys($arrayToSort);
2517  $this->assertSame($sortedArray, $expectedArray);
2518  }
2519 
2524  {
2525  $this->expectException(\InvalidArgumentException::class);
2526  $this->expectExceptionCode(1325697085);
2527 
2528  $arrayToTest = [
2529  'roger' => '',
2530  'francine' => '',
2531  'stan' => '',
2532  ];
2533 
2534  $allowedArrayKeys = [
2535  'roger',
2536  'francine',
2537  ];
2538 
2539  ‪ArrayUtility::assertAllArrayKeysAreValid($arrayToTest, $allowedArrayKeys);
2540  }
2541 
2546  {
2547  $arrayToTest = [
2548  'roger' => '',
2549  'francine' => '',
2550  'stan' => '',
2551  ];
2552 
2553  $allowedArrayKeys = [
2554  'roger',
2555  'francine',
2556  'stan',
2557  ];
2558 
2559  ‪ArrayUtility::assertAllArrayKeysAreValid($arrayToTest, $allowedArrayKeys);
2560  }
2561 
2566  {
2567  $input = [
2568  20 => 'b',
2569  10 => 'a',
2570  40 => 'd',
2571  30 => 'c',
2572  50 => [
2573  20 => 'a',
2574  10 => 'b',
2575  ],
2576  ];
2577 
2578  $expected = [
2579  10 => 'a',
2580  20 => 'b',
2581  30 => 'c',
2582  40 => 'd',
2583  50 => [
2584  10 => 'b',
2585  20 => 'a',
2586  ],
2587  ];
2588 
2589  $this->assertSame($expected, ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($input));
2590  }
2591 
2596  {
2597  $input = [
2598  'b' => 'b',
2599  10 => 'a',
2600  40 => 'd',
2601  30 => 'c',
2602  ];
2603 
2604  $expected = [
2605  'b' => 'b',
2606  10 => 'a',
2607  40 => 'd',
2608  30 => 'c',
2609  ];
2610 
2611  $this->assertSame($expected, ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($input));
2612  }
2613 
2618  {
2619  $input = [
2620  20 => 'b',
2621  10 => 'a',
2622  40 => 'd',
2623  30 => 'c',
2624  50 => [
2625  20 => 'a',
2626  10 => 'b',
2627  ],
2628  ];
2629 
2630  $expected = [
2631  0 => 'b',
2632  1 => 'a',
2633  2 => 'd',
2634  3 => 'c',
2635  4 => [
2636  0 => 'a',
2637  1 => 'b',
2638  ],
2639  ];
2640 
2641  $this->assertSame($expected, ‪ArrayUtility::reIndexNumericArrayKeysRecursive($input));
2642  }
2643 
2648  {
2649  $input = [
2650  'a' => 'b',
2651  10 => 'a',
2652  40 => 'd',
2653  30 => 'c',
2654  50 => [
2655  20 => 'a',
2656  10 => 'b',
2657  ],
2658  ];
2659 
2660  $expected = [
2661  'a' => 'b',
2662  10 => 'a',
2663  40 => 'd',
2664  30 => 'c',
2665  50 => [
2666  0 => 'a',
2667  1 => 'b',
2668  ],
2669  ];
2670 
2671  $this->assertSame($expected, ‪ArrayUtility::reIndexNumericArrayKeysRecursive($input));
2672  }
2673 
2678  {
2679  $input = [
2680  'a' => 'a',
2681  'b' => [
2682  'c' => null,
2683  'd' => 'd',
2684  ],
2685  ];
2686 
2687  $expected = [
2688  'a' => 'a',
2689  'b' => [
2690  'd' => 'd',
2691  ],
2692  ];
2693 
2694  $this->assertSame($expected, ‪ArrayUtility::removeNullValuesRecursive($input));
2695  }
2696 
2701  {
2702  $input = [
2703  'a' => 'a',
2704  'b' => [
2705  'c' => '<b>i am evil</b>',
2706  'd' => 'd',
2707  ],
2708  ];
2709 
2710  $expected = [
2711  'a' => 'a',
2712  'b' => [
2713  'c' => 'i am evil',
2714  'd' => 'd',
2715  ],
2716  ];
2717 
2718  $this->assertSame($expected, ‪ArrayUtility::stripTagsFromValuesRecursive($input));
2719  }
2720 
2725  {
2726  $testObject = new \stdClass();
2727 
2728  $input = [
2729  'stringWithTags' => '<b>i am evil</b>',
2730  'boolean' => true,
2731  'integer' => 1,
2732  'float' => 1.9,
2733  'object' => $testObject,
2734  'objectWithStringConversion' => new class {
2738  public function __toString()
2739  {
2740  return 'i am evil <b>too</b>';
2741  }
2742  },
2743  ];
2744 
2745  $expected = [
2746  'stringWithTags' => 'i am evil',
2747  'boolean' => true,
2748  'integer' => 1,
2749  'float' => 1.9,
2750  'object' => $testObject,
2751  'objectWithStringConversion' => 'i am evil too',
2752  ];
2753 
2754  $this->assertSame($expected, ‪ArrayUtility::stripTagsFromValuesRecursive($input));
2755  }
2756 
2761  {
2762  $input = [
2763  'a' => 'a',
2764  'b' => [
2765  'c' => 'true',
2766  'd' => 'd',
2767  ],
2768  ];
2769 
2770  $expected = [
2771  'a' => 'a',
2772  'b' => [
2773  'c' => true,
2774  'd' => 'd',
2775  ],
2776  ];
2777 
2778  $this->assertSame($expected, ‪ArrayUtility::convertBooleanStringsToBooleanRecursive($input));
2779  }
2780 
2786  {
2787  return [
2788  'filter all values which will be false when converted to boolean' => [
2789  // input
2790  [
2791  true,
2792  false,
2793  'foo1' => [
2794  'bar' => [
2795  'baz' => [
2796  '1',
2797  null,
2798  '',
2799  ],
2800  '' => 1,
2801  'bbd' => 0,
2802  ]
2803  ],
2804  'foo2' => 'foo',
2805  'foo3' => '',
2806  'foo4' => [
2807  'z' => 'bar',
2808  'bar' => 0,
2809  'baz' => [
2810  'foo' => [
2811  'bar' => '',
2812  'boo' => [],
2813  'bamboo' => 5,
2814  'fooAndBoo' => [0],
2815  ]
2816  ],
2817  ],
2818  ],
2819  // expected
2820  [
2821  true,
2822  'foo1' => [
2823  'bar' => [
2824  'baz' => [
2825  '1',
2826  ],
2827  '' => 1,
2828  ]
2829  ],
2830  'foo2' => 'foo',
2831  'foo4' => [
2832  'z' => 'bar',
2833  'baz' => [
2834  'foo' => [
2835  'bamboo' => 5,
2836  'fooAndBoo' => [],
2837  ]
2838  ],
2839  ],
2840  ],
2841  ],
2842  ];
2843  }
2844 
2851  public function ‪filterRecursiveFiltersFalseElements(array $input, array $expectedResult)
2852  {
2853  // If no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed.
2854  $result = ‪ArrayUtility::filterRecursive($input);
2855  $this->assertEquals($expectedResult, $result);
2856  }
2857 
2863  {
2864  return [
2865  'filter empty values, keep zero integers' => [
2866  // input
2867  [
2868  true,
2869  false,
2870  'foo1' => [
2871  'bar' => [
2872  'baz' => [
2873  '1',
2874  null,
2875  '',
2876  ],
2877  '' => 1,
2878  'bbd' => 0,
2879  ]
2880  ],
2881  'foo2' => 'foo',
2882  'foo3' => '',
2883  'foo4' => [
2884  'z' => 'bar',
2885  'bar' => 0,
2886  'baz' => [
2887  'foo' => [
2888  'bar' => '',
2889  'boo' => [],
2890  'bamboo' => 5,
2891  'fooAndBoo' => [0],
2892  ]
2893  ],
2894  ],
2895  ],
2896  // expected
2897  [
2898  true,
2899  false,
2900  'foo1' => [
2901  'bar' => [
2902  'baz' => [
2903  '1',
2904  ],
2905  '' => 1,
2906  'bbd' => 0,
2907  ]
2908  ],
2909  'foo2' => 'foo',
2910  'foo4' => [
2911  'z' => 'bar',
2912  'bar' => 0,
2913  'baz' => [
2914  'foo' => [
2915  'bamboo' => 5,
2916  'fooAndBoo' => [0],
2917  ]
2918  ],
2919  ],
2920  ],
2921  ],
2922  ];
2923  }
2924 
2931  public function ‪filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback(array $input, array $expectedResult)
2932  {
2933  // callback filters empty strings, array and null but keeps zero integers
2935  $input,
2936  function ($item) {
2937  return $item !== '' && $item !== [] && $item !== null;
2938  }
2939  );
2940  $this->assertEquals($expectedResult, $result);
2941  }
2942 
2948  {
2949  $input = [
2950  'foo' => 'remove',
2951  'bar' => [
2952  'baz' => 'remove',
2953  'keep1' => 'keep'
2954  ],
2955  'keep2' => 'keep'
2956  ];
2957  $expectedResult = [
2958  'bar' => [
2959  'keep1' => 'keep'
2960  ],
2961  'keep2' => 'keep'
2962  ];
2963 
2964  return [
2965  'filter using a closure' => [
2966  $input,
2967  $expectedResult,
2968  function ($value): bool {
2969  return is_array($value) || $value === 'keep';
2970  },
2971  ],
2972  'filter using a callable "static class-method call" as string' => [
2973  $input,
2974  $expectedResult,
2975  ArrayUtilityFilterRecursiveCallbackFixture::class . '::callbackViaStaticMethod',
2976  ],
2977  'filter using a callable "static class-method call" as array' => [
2978  $input,
2979  $expectedResult,
2980  [ArrayUtilityFilterRecursiveCallbackFixture::class, 'callbackViaStaticMethod'],
2981  ],
2982  'filter using a callable "instance-method call" as array' => [
2983  $input,
2984  $expectedResult,
2985  [new ‪ArrayUtilityFilterRecursiveCallbackFixture(), 'callbackViaInstanceMethod'],
2986  ],
2987  ];
2988  }
2989 
2998  public function ‪filterRecursiveSupportsCallableCallback(array $input, array $expectedResult, callable $callback)
2999  {
3000  $result = ‪ArrayUtility::filterRecursive($input, $callback);
3001  $this->assertEquals($expectedResult, $result);
3002  }
3003 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays
‪arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays()
Definition: ArrayUtilityTest.php:1182
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeNullValuesRecursiveExpectRemoval
‪removeNullValuesRecursiveExpectRemoval()
Definition: ArrayUtilityTest.php:2677
‪TYPO3\CMS\Core\Utility\ArrayUtility\keepItemsInArray
‪static array keepItemsInArray(array $array, $keepItems, $getValueFunc=null)
Definition: ArrayUtility.php:678
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsNumericArrayKeys
‪arrayExportReturnsNumericArrayKeys()
Definition: ArrayUtilityTest.php:1163
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys
‪assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys()
Definition: ArrayUtilityTest.php:2523
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesCorrectPathDataProvider
‪removeByPathRemovesCorrectPathDataProvider()
Definition: ArrayUtilityTest.php:859
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsEmpty
‪getValueByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:235
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathGetsCorrectValue
‪getValueByPathGetsCorrectValue(array $array, $path, $expectedResult)
Definition: ArrayUtilityTest.php:467
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathSegmentIsEmpty
‪setValueByPathThrowsExceptionIfPathSegmentIsEmpty()
Definition: ArrayUtilityTest.php:522
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathValidDataProvider
‪getValueByPathValidDataProvider()
Definition: ArrayUtilityTest.php:361
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveSupportsCallableCallback
‪filterRecursiveSupportsCallableCallback(array $input, array $expectedResult, callable $callback)
Definition: ArrayUtilityTest.php:2998
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathAcceptsDifferentDelimiter
‪getValueByPathAcceptsDifferentDelimiter()
Definition: ArrayUtilityTest.php:475
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveMatchesReferencesToSameObject
‪filterByValueRecursiveMatchesReferencesToSameObject()
Definition: ArrayUtilityTest.php:179
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathIsNotAString
‪setValueByPathThrowsExceptionIfPathIsNotAString()
Definition: ArrayUtilityTest.php:511
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\reIndexNumericArrayKeysRecursiveExpectNoReindexing
‪reIndexNumericArrayKeysRecursiveExpectNoReindexing()
Definition: ArrayUtilityTest.php:2647
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortByKeyRecursiveCheckIfSortingIsCorrect
‪sortByKeyRecursiveCheckIfSortingIsCorrect()
Definition: ArrayUtilityTest.php:925
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayWorksWithOneArgumentDataProvider
‪array keepItemsInArrayWorksWithOneArgumentDataProvider()
Definition: ArrayUtilityTest.php:2014
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:26
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesFirstIndexWithZeroAsPathSegment
‪removeByPathRemovesFirstIndexWithZeroAsPathSegment()
Definition: ArrayUtilityTest.php:780
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyCheckIfSortingIsCorrect
‪sortArraysByKeyCheckIfSortingIsCorrect(array $array, $key, $ascending, $expectedResult)
Definition: ArrayUtilityTest.php:1084
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathInvalidPathDataProvider
‪array getValueByPathInvalidPathDataProvider()
Definition: ArrayUtilityTest.php:267
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveCorrectlyFiltersArray
‪filterByValueRecursiveCorrectlyFiltersArray($needle, $haystack, $expectedResult)
Definition: ArrayUtilityTest.php:168
‪TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath
‪static bool isValidPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:143
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsNotString
‪getValueByPathThrowsExceptionIfPathIsNotString()
Definition: ArrayUtilityTest.php:224
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysDataProvider
‪array sortArrayWithIntegerKeysDataProvider()
Definition: ArrayUtilityTest.php:2464
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterRecursive
‪static array filterRecursive(array $array, callable $callback=null)
Definition: ArrayUtility.php:846
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveFiltersFalseElementsDataProvider
‪array filterRecursiveFiltersFalseElementsDataProvider()
Definition: ArrayUtilityTest.php:2785
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayWorksWithOneArgument
‪keepItemsInArrayWorksWithOneArgument($search, $array, $expected)
Definition: ArrayUtilityTest.php:2004
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortByKeyRecursive
‪static array sortByKeyRecursive(array $array)
Definition: ArrayUtility.php:349
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathNotExists
‪getValueByPathThrowsExceptionIfPathNotExists(array $array, $path)
Definition: ArrayUtilityTest.php:334
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathCanUseZeroAsPath
‪setValueByPathCanUseZeroAsPath()
Definition: ArrayUtilityTest.php:541
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\mergeRecursiveWithOverruleCalculatesExpectedResult
‪mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected)
Definition: ArrayUtilityTest.php:1925
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesCorrectPath
‪removeByPathRemovesCorrectPath(array $array, $path, $expectedResult)
Definition: ArrayUtilityTest.php:911
‪TYPO3\CMS\Core\Utility\ArrayUtility\arrayExport
‪static string arrayExport(array $array=[], $level=0)
Definition: ArrayUtility.php:397
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathDoesNotExistInArray
‪removeByPathThrowsExceptionIfPathDoesNotExistInArray()
Definition: ArrayUtilityTest.php:802
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest
Definition: ArrayUtilityTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder
‪naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder()
Definition: ArrayUtilityTest.php:2238
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysSortsNumericArrays
‪sortArrayWithIntegerKeysSortsNumericArrays(array $arrayToSort, array $expectedArray)
Definition: ArrayUtilityTest.php:2514
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays
‪arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays()
Definition: ArrayUtilityTest.php:1201
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathAcceptsGivenDelimiter
‪removeByPathAcceptsGivenDelimiter()
Definition: ArrayUtilityTest.php:836
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysRecursiveExpectSorting
‪sortArrayWithIntegerKeysRecursiveExpectSorting()
Definition: ArrayUtilityTest.php:2565
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\stripTagsFromValuesRecursiveExpectRemoval
‪stripTagsFromValuesRecursiveExpectRemoval()
Definition: ArrayUtilityTest.php:2700
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:179
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursive
‪filterByValueRecursive()
Definition: ArrayUtilityTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\reIndexNumericArrayKeysRecursiveExpectReindexing
‪reIndexNumericArrayKeysRecursiveExpectReindexing()
Definition: ArrayUtilityTest.php:2617
‪TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\ArrayUtilityFilterRecursiveCallbackFixture
Definition: ArrayUtilityFilterRecursiveCallbackFixture.php:22
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue
‪filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue($input, $expected)
Definition: ArrayUtilityTest.php:2387
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionWithEmptyPathSegment
‪removeByPathThrowsExceptionWithEmptyPathSegment()
Definition: ArrayUtilityTest.php:763
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\intersectRecursiveCalculatesExpectedResult
‪intersectRecursiveCalculatesExpectedResult(array $source, array $mask, array $expected)
Definition: ArrayUtilityTest.php:1535
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyThrowsExceptionForNonExistingKey
‪sortArraysByKeyThrowsExceptionForNonExistingKey()
Definition: ArrayUtilityTest.php:1093
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenCalculatesExpectedResult
‪flattenCalculatesExpectedResult(array $array, array $expected)
Definition: ArrayUtilityTest.php:1322
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathRemovesFirstIndexWithZeroAsPath
‪removeByPathRemovesFirstIndexWithZeroAsPath()
Definition: ArrayUtilityTest.php:792
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsSpecificExceptionIfPathNotExists
‪getValueByPathThrowsSpecificExceptionIfPathNotExists(array $array, string $path)
Definition: ArrayUtilityTest.php:347
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathReturnsFirstIndexIfPathSegmentIsZero
‪getValueByPathReturnsFirstIndexIfPathSegmentIsZero()
Definition: ArrayUtilityTest.php:254
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\intersectRecursiveCalculatesExpectedResultDataProvider
‪array intersectRecursiveCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1334
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterByValueRecursive
‪static array filterByValueRecursive($needle='', array $haystack=[])
Definition: ArrayUtility.php:103
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\stripTagsFromValuesRecursiveExpectNoTypeCast
‪stripTagsFromValuesRecursiveExpectNoTypeCast()
Definition: ArrayUtilityTest.php:2724
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathThrowsExceptionIfPathIsEmpty
‪setValueByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:500
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesOneDimensionalArrays
‪arrayDiffAssocRecursiveHandlesOneDimensionalArrays()
Definition: ArrayUtilityTest.php:2089
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\convertBooleanStringsToBooleanRecursiveExpectConverting
‪convertBooleanStringsToBooleanRecursiveExpectConverting()
Definition: ArrayUtilityTest.php:2760
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeArrayEntryByValue
‪static array removeArrayEntryByValue(array $array, $cmpValue)
Definition: ArrayUtility.php:643
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathIsNotAString
‪removeByPathThrowsExceptionIfPathIsNotAString()
Definition: ArrayUtilityTest.php:752
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerZeroByCallbackDataProvider
‪array filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerZeroByCallbackDataProvider()
Definition: ArrayUtilityTest.php:2862
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathCanUseZeroAsPathSegment
‪setValueByPathCanUseZeroAsPathSegment()
Definition: ArrayUtilityTest.php:533
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys
‪assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys()
Definition: ArrayUtilityTest.php:2545
‪TYPO3\CMS\Core\Utility\ArrayUtility\intersectRecursive
‪static array intersectRecursive(array $source, array $mask=[])
Definition: ArrayUtility.php:529
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isValidPathReturnsTrueIfPathExists
‪isValidPathReturnsTrueIfPathExists()
Definition: ArrayUtilityTest.php:205
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArraysByKeyCheckIfSortingIsCorrectDataProvider
‪sortArraysByKeyCheckIfSortingIsCorrectDataProvider()
Definition: ArrayUtilityTest.php:956
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntryWithEmptyString
‪checkRemoveArrayEntryByValueRemovesEntryWithEmptyString()
Definition: ArrayUtilityTest.php:1978
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeByPath
‪static array removeByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:311
‪TYPO3\CMS\Core\Utility\ArrayUtility\stripTagsFromValuesRecursive
‪static array stripTagsFromValuesRecursive(array $array)
Definition: ArrayUtility.php:825
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysWithoutAcceptAnyKey
‪array filterAndSortByNumericKeysWithoutAcceptAnyKey()
Definition: ArrayUtilityTest.php:2398
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsExceptionIfPathIsEmpty
‪removeByPathThrowsExceptionIfPathIsEmpty()
Definition: ArrayUtilityTest.php:741
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportReturnsFormattedMultidimensionalArray
‪arrayExportReturnsFormattedMultidimensionalArray()
Definition: ArrayUtilityTest.php:1107
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass
‪filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass()
Definition: ArrayUtilityTest.php:191
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\remapArrayKeysExchangesKeysWithGivenMapping
‪remapArrayKeysExchangesKeysWithGivenMapping()
Definition: ArrayUtilityTest.php:2063
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:271
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray
‪checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray()
Definition: ArrayUtilityTest.php:1937
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathSetsCorrectValueDataProvider
‪setValueByPathSetsCorrectValueDataProvider()
Definition: ArrayUtilityTest.php:555
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray
‪checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray()
Definition: ArrayUtilityTest.php:1957
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\setValueByPathSetsCorrectValue
‪setValueByPathSetsCorrectValue(array $array, $path, $value, $expectedResult)
Definition: ArrayUtilityTest.php:726
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\sortArrayWithIntegerKeysRecursiveExpectNoSorting
‪sortArrayWithIntegerKeysRecursiveExpectNoSorting()
Definition: ArrayUtilityTest.php:2595
‪TYPO3\CMS\Core\Utility\ArrayUtility\assertAllArrayKeysAreValid
‪static assertAllArrayKeysAreValid(array $arrayToTest, array $allowedArrayKeys)
Definition: ArrayUtility.php:32
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\removeByPathThrowsSpecificExceptionIfPathDoesNotExistInArray
‪removeByPathThrowsSpecificExceptionIfPathDoesNotExistInArray()
Definition: ArrayUtilityTest.php:819
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveFiltersFalseElements
‪filterRecursiveFiltersFalseElements(array $input, array $expectedResult)
Definition: ArrayUtilityTest.php:2851
‪TYPO3\CMS\Core\Utility\ArrayUtility\flatten
‪static array flatten(array $array, $prefix='')
Definition: ArrayUtility.php:479
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static array removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:232
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider
‪array renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider()
Definition: ArrayUtilityTest.php:1546
‪TYPO3\CMS\Core\Utility\ArrayUtility\reIndexNumericArrayKeysRecursive
‪static array reIndexNumericArrayKeysRecursive(array $array)
Definition: ArrayUtility.php:213
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeysRecursive
‪static array sortArrayWithIntegerKeysRecursive(array $array)
Definition: ArrayUtility.php:808
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\keepItemsInArrayCanUseClosure
‪keepItemsInArrayCanUseClosure()
Definition: ArrayUtilityTest.php:2038
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveReturnsEmptyIfEqual
‪arrayDiffAssocRecursiveReturnsEmptyIfEqual()
Definition: ArrayUtilityTest.php:2173
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesMixedArrays
‪arrayDiffAssocRecursiveHandlesMixedArrays()
Definition: ArrayUtilityTest.php:2147
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArraysByKey
‪static array sortArraysByKey(array $arrays, $key, $ascending=true)
Definition: ArrayUtility.php:369
‪TYPO3\CMS\Core\Utility\ArrayUtility\renumberKeysToAvoidLeapsIfKeysAreAllNumeric
‪static array renumberKeysToAvoidLeapsIfKeysAreAllNumeric(array $array=[], $level=0)
Definition: ArrayUtility.php:573
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder
‪renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder(array $inputArray, array $expected)
Definition: ArrayUtilityTest.php:1672
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder
‪naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder()
Definition: ArrayUtilityTest.php:2203
‪TYPO3\CMS\Core\Utility\ArrayUtility\naturalKeySortRecursive
‪static bool naturalKeySortRecursive(array &$array)
Definition: ArrayUtility.php:752
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysWithAcceptAnyKey
‪array filterAndSortByNumericKeysWithAcceptAnyKey()
Definition: ArrayUtilityTest.php:2301
‪TYPO3\CMS\Core\Utility\ArrayUtility\remapArrayKeys
‪static remapArrayKeys(array &$array, array $mappingTable)
Definition: ArrayUtility.php:710
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:793
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterAndSortByNumericKeys
‪static array filterAndSortByNumericKeys($setupArr, $acceptAnyKeys=false)
Definition: ArrayUtility.php:772
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathReturnsFirstIndexIfPathIsZero
‪getValueByPathReturnsFirstIndexIfPathIsZero()
Definition: ArrayUtilityTest.php:246
‪TYPO3\CMS\Core\Utility\ArrayUtility\arrayDiffAssocRecursive
‪static array arrayDiffAssocRecursive(array $array1, array $array2)
Definition: ArrayUtility.php:728
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayDiffAssocRecursiveHandlesMultiDimensionalArrays
‪arrayDiffAssocRecursiveHandlesMultiDimensionalArrays()
Definition: ArrayUtilityTest.php:2110
‪TYPO3\CMS\Core\Utility\ArrayUtility\convertBooleanStringsToBooleanRecursive
‪static array convertBooleanStringsToBooleanRecursive(array $array)
Definition: ArrayUtility.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback
‪filterRecursiveCallbackFiltersEmptyElementsWithoutIntegerByCallback(array $input, array $expectedResult)
Definition: ArrayUtilityTest.php:2931
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse
‪filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse($input, $expected)
Definition: ArrayUtilityTest.php:2453
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\filterRecursiveSupportsCallableCallbackDataProvider
‪array filterRecursiveSupportsCallableCallbackDataProvider()
Definition: ArrayUtilityTest.php:2947
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\isValidPathReturnsFalseIfPathDoesNotExist
‪isValidPathReturnsFalseIfPathDoesNotExist()
Definition: ArrayUtilityTest.php:213
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider
‪array mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1680
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\flattenCalculatesExpectedResultDataProvider
‪array flattenCalculatesExpectedResultDataProvider()
Definition: ArrayUtilityTest.php:1226
‪TYPO3\CMS\Core\Tests\Unit\Utility\ArrayUtilityTest\arrayExportThrowsExceptionIfObjectShouldBeExported
‪arrayExportThrowsExceptionIfObjectShouldBeExported()
Definition: ArrayUtilityTest.php:1146