TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ArrayUtilityTest Class Reference
Inheritance diagram for ArrayUtilityTest:
UnitTestCase BaseTestCase

Public Member Functions

 filterByValueRecursive ()
 
 filterByValueRecursiveCorrectlyFiltersArray ($needle, $haystack, $expectedResult)
 
 filterByValueRecursiveMatchesReferencesToSameObject ()
 
 filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass ()
 
 isValidPathReturnsTrueIfPathExists ()
 
 isValidPathReturnsFalseIfPathDoesNotExist ()
 
 getValueByPathThrowsExceptionIfPathIsNotString ()
 
 getValueByPathThrowsExceptionIfPathIsEmpty ()
 
 getValueByPathReturnsFirstIndexIfPathIsZero ()
 
 getValueByPathReturnsFirstIndexIfPathSegmentIsZero ()
 
 getValueByPathInvalidPathDataProvider ()
 
 getValueByPathThrowsExceptionIfPathNotExists (array $array, $path)
 
 getValueByPathValidDataProvider ()
 
 getValueByPathGetsCorrectValue (array $array, $path, $expectedResult)
 
 getValueByPathAcceptsDifferentDelimiter ()
 
 setValueByPathThrowsExceptionIfPathIsEmpty ()
 
 setValueByPathThrowsExceptionIfPathIsNotAString ()
 
 setValueByPathThrowsExceptionIfPathSegmentIsEmpty ()
 
 setValueByPathCanUseZeroAsPathSegment ()
 
 setValueByPathCanUseZeroAsPath ()
 
 setValueByPathSetsCorrectValueDataProvider ()
 
 setValueByPathSetsCorrectValue (array $array, $path, $value, $expectedResult)
 
 removeByPathThrowsExceptionIfPathIsEmpty ()
 
 removeByPathThrowsExceptionIfPathIsNotAString ()
 
 removeByPathThrowsExceptionWithEmptyPathSegment ()
 
 removeByPathRemovesFirstIndexWithZeroAsPathSegment ()
 
 removeByPathRemovesFirstIndexWithZeroAsPath ()
 
 removeByPathThrowsExceptionIfPathDoesNotExistInArray ()
 
 removeByPathAcceptsGivenDelimiter ()
 
 removeByPathRemovesCorrectPathDataProvider ()
 
 removeByPathRemovesCorrectPath (array $array, $path, $expectedResult)
 
 sortByKeyRecursiveCheckIfSortingIsCorrect ()
 
 sortArraysByKeyCheckIfSortingIsCorrectDataProvider ()
 
 sortArraysByKeyCheckIfSortingIsCorrect (array $array, $key, $ascending, $expectedResult)
 
 sortArraysByKeyThrowsExceptionForNonExistingKey ()
 
 arrayExportReturnsFormattedMultidimensionalArray ()
 
 arrayExportThrowsExceptionIfObjectShouldBeExported ()
 
 arrayExportReturnsNumericArrayKeys ()
 
 arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays ()
 
 arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays ()
 
 flattenCalculatesExpectedResultDataProvider ()
 
 flattenCalculatesExpectedResult (array $array, array $expected)
 
 intersectRecursiveCalculatesExpectedResultDataProvider ()
 
 intersectRecursiveCalculatesExpectedResult (array $source, array $mask, array $expected)
 
 renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider ()
 
 renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder (array $inputArray, array $expected)
 
 mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider ()
 
 mergeRecursiveWithOverruleCalculatesExpectedResult ($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected)
 
 inArrayChecksStringExistenceWithinArray ($array, $item, $expected)
 
 inArrayDataProvider ()
 
 checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray ()
 
 checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray ()
 
 checkRemoveArrayEntryByValueRemovesEntryWithEmptyString ()
 
 keepItemsInArrayWorksWithOneArgument ($search, $array, $expected)
 
 keepItemsInArrayWorksWithOneArgumentDataProvider ()
 
 keepItemsInArrayCanUseClosure ()
 
 remapArrayKeysExchangesKeysWithGivenMapping ()
 
 arrayDiffAssocRecursiveHandlesOneDimensionalArrays ()
 
 arrayDiffAssocRecursiveHandlesMultiDimensionalArrays ()
 
 arrayDiffAssocRecursiveHandlesMixedArrays ()
 
 naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder ()
 
 naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder ()
 
 filterAndSortByNumericKeysWithAcceptAnyKey ()
 
 filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue ($input, $expected)
 
 filterAndSortByNumericKeysWithoutAcceptAnyKey ()
 
 filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse ($input, $expected)
 
 sortArrayWithIntegerKeysDataProvider ()
 
 sortArrayWithIntegerKeysSortsNumericArrays (array $arrayToSort, array $expectedArray)
 
 assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys ()
 
 assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys ()
 
 sortArrayWithIntegerKeysRecursiveExpectSorting ()
 
 sortArrayWithIntegerKeysRecursiveExpectNoSorting ()
 
 reIndexNumericArrayKeysRecursiveExpectReindexing ()
 
 reIndexNumericArrayKeysRecursiveExpectNoReindexing ()
 
 removeNullValuesRecursiveExpectRemoval ()
 
 stripTagsFromValuesRecursiveExpectRemoval ()
 
 convertBooleanStringsToBooleanRecursiveExpectConverting ()
 

Additional Inherited Members

- Protected Member Functions inherited from UnitTestCase
 tearDown ()
 
- Protected Member Functions inherited from BaseTestCase
 getAccessibleMock ($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
 
 getAccessibleMockForAbstractClass ($originalClassName, array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true, $mockedMethods=[])
 
 buildAccessibleProxy ($className)
 
 callInaccessibleMethod ($object, $name,...$arguments)
 
 inject ($target, $name, $dependency)
 
 getUniqueId ($prefix= '')
 
- Protected Attributes inherited from UnitTestCase
 $backupGlobalsBlacklist = ['TYPO3_LOADED_EXT']
 
 $testFilesToDelete = []
 
- Protected Attributes inherited from BaseTestCase
 $backupGlobals = true
 
 $backupStaticAttributes = false
 

Detailed Description

Test case

Definition at line 23 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

Member Function Documentation

arrayDiffAssocRecursiveHandlesMixedArrays ( )
arrayDiffAssocRecursiveHandlesMultiDimensionalArrays ( )
arrayDiffAssocRecursiveHandlesOneDimensionalArrays ( )
arrayExportReturnsFormattedMultidimensionalArray ( )
arrayExportReturnsKeyIndexForNonConsecutiveCountedArrays ( )
arrayExportReturnsNoKeyIndexForConsecutiveCountedArrays ( )
arrayExportReturnsNumericArrayKeys ( )
arrayExportThrowsExceptionIfObjectShouldBeExported ( )
assertAllArrayKeysAreValidReturnsNullOnAllowedArrayKeys ( )
assertAllArrayKeysAreValidThrowsExceptionOnNotAllowedArrayKeys ( )
checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray ( )
checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray ( )
checkRemoveArrayEntryByValueRemovesEntryWithEmptyString ( )
convertBooleanStringsToBooleanRecursiveExpectConverting ( )
filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse (   $input,
  $expected 
)
Test:
filterAndSortByNumericKeysWithoutAcceptAnyKey
Parameters
array$input
array$expected

Definition at line 2407 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\filterAndSortByNumericKeys().

filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue (   $input,
  $expected 
)
Test:
filterAndSortByNumericKeysWithAcceptAnyKey
Parameters
array$input
array$expected

Definition at line 2341 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\filterAndSortByNumericKeys().

filterAndSortByNumericKeysWithAcceptAnyKey ( )

Data provider for filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsTrue

Returns
array

Definition at line 2255 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

filterAndSortByNumericKeysWithoutAcceptAnyKey ( )

Data provider for filterAndSortByNumericKeysBehavesCorrectlyForAcceptAnyKeysIsFalse

Returns
array

Definition at line 2352 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

filterByValueRecursive ( )

Data provider for filterByValueRecursiveCorrectlyFiltersArray

Every array splits into:

  • String value to search for
  • Input array
  • Expected result array

Definition at line 36 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

filterByValueRecursiveCorrectlyFiltersArray (   $needle,
  $haystack,
  $expectedResult 
)
Test:
filterByValueRecursive
Parameters
array$needle
array$haystack
array$expectedResult

Definition at line 165 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\filterByValueRecursive().

filterByValueRecursiveDoesNotMatchDifferentInstancesOfSameClass ( )
filterByValueRecursiveMatchesReferencesToSameObject ( )
flattenCalculatesExpectedResult ( array  $array,
array  $expected 
)
Test:
Parameters
array$array
array$expectedflattenCalculatesExpectedResultDataProvider

Definition at line 1273 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\flatten().

flattenCalculatesExpectedResultDataProvider ( )
Returns
array

Definition at line 1177 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

getValueByPathAcceptsDifferentDelimiter ( )
getValueByPathGetsCorrectValue ( array  $array,
  $path,
  $expectedResult 
)
Test:
getValueByPathValidDataProvider
Parameters
array$array
string$path
mixed$expectedResult

Definition at line 435 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\getValueByPath().

getValueByPathInvalidPathDataProvider ( )

Data provider for getValueByPathThrowsExceptionIfPathNotExists Every array splits into:

  • Array to get value from
  • String path
  • Expected result
    Returns
    array

Definition at line 269 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

getValueByPathReturnsFirstIndexIfPathIsZero ( )
getValueByPathReturnsFirstIndexIfPathSegmentIsZero ( )
getValueByPathThrowsExceptionIfPathIsEmpty ( )
getValueByPathThrowsExceptionIfPathIsNotString ( )
getValueByPathThrowsExceptionIfPathNotExists ( array  $array,
  $path 
)
Test:
getValueByPathInvalidPathDataProvider
Parameters
array$array
string$path

Definition at line 327 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\getValueByPath().

getValueByPathValidDataProvider ( )

Data provider for getValueByPathReturnsCorrectValue Every array splits into:

  • Array to get value from
  • String path
  • Expected result

Definition at line 342 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

inArrayChecksStringExistenceWithinArray (   $array,
  $item,
  $expected 
)
Test:
inArrayDataProvider
Parameters
array$arraytarget array
string$itemsearch string
bool$expectedexpected value

Definition at line 1888 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\inArray().

inArrayDataProvider ( )

Data provider for inArrayChecksStringExistenceWithinArray

Returns
array

Definition at line 1898 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

intersectRecursiveCalculatesExpectedResult ( array  $source,
array  $mask,
array  $expected 
)
Test:
Parameters
array$source
array$mask
array$expectedintersectRecursiveCalculatesExpectedResultDataProvider

Definition at line 1486 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\intersectRecursive().

intersectRecursiveCalculatesExpectedResultDataProvider ( )
Returns
array

Definition at line 1285 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

isValidPathReturnsFalseIfPathDoesNotExist ( )
isValidPathReturnsTrueIfPathExists ( )

Mock the class under test, isValidPath() (method under test), calls static getValuePath() internally, which is mocked here to return a specific result. This works because of 'static' keyword' instead of 'self' for getValueByPath() call, using late static binding in PHP 5.3

Test:

Definition at line 207 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\isValidPath().

keepItemsInArrayCanUseClosure ( )

Shows the example from the doc comment where a function is used to reduce the sub arrays to one item which is then used for the matching.

Test:

Definition at line 2018 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\keepItemsInArray().

keepItemsInArrayWorksWithOneArgument (   $search,
  $array,
  $expected 
)
Test:
keepItemsInArrayWorksWithOneArgumentDataProvider
Parameters
mixed$searchThe items which are allowed/kept in the array
array$arraytarget array
array$expectedexpected array

Definition at line 1985 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\keepItemsInArray().

keepItemsInArrayWorksWithOneArgumentDataProvider ( )

Data provider for keepItemsInArrayWorksWithOneArgument

Returns
array

Definition at line 1995 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

mergeRecursiveWithOverruleCalculatesExpectedResult (   $input1,
  $input2,
  $addKeys,
  $includeEmptyValues,
  $enableUnsetFeature,
  $expected 
)
Test:
mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider
Parameters
array$input1Input 1
array$input2Input 2
bool$addKeysTRUE if should add keys, else FALSE
bool$includeEmptyValuesTRUE if should include empty values, else FALSE
bool$enableUnsetFeatureTRUE if should enable unset feature, else FALSE
array$expectedexpected array

Definition at line 1872 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\mergeRecursiveWithOverrule().

mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider ( )
Returns
array

Definition at line 1627 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

naturalKeySortRecursiveSortsMultiDimensionalArrayByNaturalOrder ( )
naturalKeySortRecursiveSortsOneDimensionalArrayByNaturalOrder ( )
reIndexNumericArrayKeysRecursiveExpectNoReindexing ( )
reIndexNumericArrayKeysRecursiveExpectReindexing ( )
remapArrayKeysExchangesKeysWithGivenMapping ( )
removeByPathAcceptsGivenDelimiter ( )
removeByPathRemovesCorrectPath ( array  $array,
  $path,
  $expectedResult 
)
Test:
removeByPathRemovesCorrectPathDataProvider
Parameters
array$array
string$path
array$expectedResult

Definition at line 862 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\removeByPath().

removeByPathRemovesCorrectPathDataProvider ( )

Data provider for removeByPathRemovesCorrectPath

Definition at line 810 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

removeByPathRemovesFirstIndexWithZeroAsPath ( )
removeByPathRemovesFirstIndexWithZeroAsPathSegment ( )
removeByPathThrowsExceptionIfPathDoesNotExistInArray ( )
removeByPathThrowsExceptionIfPathIsEmpty ( )
removeByPathThrowsExceptionIfPathIsNotAString ( )
removeByPathThrowsExceptionWithEmptyPathSegment ( )
removeNullValuesRecursiveExpectRemoval ( )
renumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider ( )
Returns
array

Definition at line 1497 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

renumberKeysToAvoidLeapsIfKeysAreAllNumericReturnsExpectedOrder ( array  $inputArray,
array  $expected 
)
Test:
Parameters
array$inputArray
array$expectedrenumberKeysToAvoidLeapsIfKeysAreAllNumericDataProvider

Definition at line 1619 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\renumberKeysToAvoidLeapsIfKeysAreAllNumeric().

setValueByPathCanUseZeroAsPath ( )
setValueByPathCanUseZeroAsPathSegment ( )
setValueByPathSetsCorrectValue ( array  $array,
  $path,
  $value,
  $expectedResult 
)
Test:
setValueByPathSetsCorrectValueDataProvider
Parameters
array$array
string$path
string$value
array$expectedResult

Definition at line 694 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\setValueByPath().

setValueByPathSetsCorrectValueDataProvider ( )

Data provider for setValueByPathSetsCorrectValueDataProvider

Every array splits into:

  • Array to set value in
  • String path
  • Value to set
  • Expected result

Definition at line 523 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

setValueByPathThrowsExceptionIfPathIsEmpty ( )
setValueByPathThrowsExceptionIfPathIsNotAString ( )
setValueByPathThrowsExceptionIfPathSegmentIsEmpty ( )
sortArraysByKeyCheckIfSortingIsCorrect ( array  $array,
  $key,
  $ascending,
  $expectedResult 
)
Test:
sortArraysByKeyCheckIfSortingIsCorrectDataProvider
Parameters
array$array
string$key
bool$ascending
array$expectedResult

Definition at line 1035 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\sortArraysByKey().

sortArraysByKeyCheckIfSortingIsCorrectDataProvider ( )

Data provider for sortArraysByKeyCheckIfSortingIsCorrect

Definition at line 907 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

sortArraysByKeyThrowsExceptionForNonExistingKey ( )
sortArrayWithIntegerKeysDataProvider ( )

dataProvider for sortArrayWithIntegerKeys

Returns
array

Definition at line 2418 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

sortArrayWithIntegerKeysRecursiveExpectNoSorting ( )
sortArrayWithIntegerKeysRecursiveExpectSorting ( )
sortArrayWithIntegerKeysSortsNumericArrays ( array  $arrayToSort,
array  $expectedArray 
)
Test:
Parameters
array$arrayToSort
array$expectedArraysortArrayWithIntegerKeysDataProvider

Definition at line 2468 of file core/Tests/Unit/Utility/ArrayUtilityTest.php.

References ArrayUtility\sortArrayWithIntegerKeys().

sortByKeyRecursiveCheckIfSortingIsCorrect ( )
stripTagsFromValuesRecursiveExpectRemoval ( )