‪TYPO3CMS  11.5
GeneralUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪GeneralUtilityTest extends UnitTestCase
24 {
29  {
30  $filter = 'foo,bar';
31  $getArray = ['foo' => 1, 'cake' => 'lie'];
32  $expected = ['foo' => 1];
33  $result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, false);
34  self::assertSame($expected, $result);
35  }
36 
41  {
42  $_GET['bar'] = '2';
43  $filter = 'foo,bar';
44  $getArray = ['foo' => 1, 'cake' => 'lie'];
45  $expected = ['foo' => 1, 'bar' => '2'];
46  $result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, true);
47  self::assertSame($expected, $result);
48  }
49 
58  string $initialList,
59  string $listWithElementRemoved
60  ): void {
61  self::assertSame($listWithElementRemoved, GeneralUtility::rmFromList('removeme', $initialList));
62  }
63 
70  {
71  return [
72  'Element as second element of three' => ['one,removeme,two', 'one,two'],
73  'Element at beginning of list' => ['removeme,one,two', 'one,two'],
74  'Element at end of list' => ['one,two,removeme', 'one,two'],
75  'One item list' => ['removeme', ''],
76  'Element not contained in list' => ['one,two,three', 'one,two,three'],
77  'Empty element survives' => ['one,,three,,removeme', 'one,,three,'],
78  'Empty element survives at start' => [',removeme,three,removeme', ',three'],
79  'Empty element survives at end' => ['removeme,three,removeme,', 'three,'],
80  'Empty list' => ['', ''],
81  'List contains removeme multiple times' => ['removeme,notme,removeme,removeme', 'notme'],
82  'List contains removeme multiple times nothing else' => ['removeme,removeme,removeme', ''],
83  'List contains removeme multiple times nothing else 2x' => ['removeme,removeme', ''],
84  'List contains removeme multiple times nothing else 3x' => ['removeme,removeme,removeme', ''],
85  'List contains removeme multiple times nothing else 4x' => ['removeme,removeme,removeme,removeme', ''],
86  'List contains removeme multiple times nothing else 5x' => ['removeme,removeme,removeme,removeme,removeme', ''],
87  ];
88  }
89 
91  // Tests concerning isFirstPartOfStr
93 
99  {
100  return [
101  'match first part of string' => ['hello world', 'hello'],
102  'match whole string' => ['hello', 'hello'],
103  'integer is part of string with same number' => ['24', 24],
104  'string is part of integer with same number' => [24, '24'],
105  'integer is part of string starting with same number' => ['24 beer please', 24],
106  ];
107  }
108 
113  public function ‪isFirstPartOfStrReturnsTrueForMatchingFirstPart($string, $part): void
114  {
115  self::assertTrue(GeneralUtility::isFirstPartOfStr($string, $part));
116  }
117 
124  {
125  return [
126  'no string match' => ['hello', 'bye'],
127  'no case sensitive string match' => ['hello world', 'Hello'],
128  'array is not part of string' => ['string', []],
129  'string is not part of array' => [[], 'string'],
130  'NULL is not part of string' => ['string', null],
131  'string is not part of NULL' => [null, 'string'],
132  'NULL is not part of array' => [[], null],
133  'array is not part of NULL' => [null, []],
134  'empty string is not part of empty string' => ['', ''],
135  'NULL is not part of empty string' => ['', null],
136  'false is not part of empty string' => ['', false],
137  'empty string is not part of NULL' => [null, ''],
138  'empty string is not part of false' => [false, ''],
139  'empty string is not part of zero integer' => [0, ''],
140  'zero integer is not part of NULL' => [null, 0],
141  'zero integer is not part of empty string' => ['', 0],
142  ];
143  }
144 
149  public function ‪isFirstPartOfStrReturnsFalseForNotMatchingFirstPart($string, $part): void
150  {
151  self::assertFalse(GeneralUtility::isFirstPartOfStr($string, $part));
152  }
153 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest
Definition: GeneralUtilityTest.php:24
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\compileSelectedGetVarsFromArrayFiltersIncomingData
‪compileSelectedGetVarsFromArrayFiltersIncomingData()
Definition: GeneralUtilityTest.php:28
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\rmFromListRemovesElementsFromCommaSeparatedList
‪rmFromListRemovesElementsFromCommaSeparatedList(string $initialList, string $listWithElementRemoved)
Definition: GeneralUtilityTest.php:57
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\isFirstPartOfStrReturnsFalseForNotMatchingFirstPartDataProvider
‪array isFirstPartOfStrReturnsFalseForNotMatchingFirstPartDataProvider()
Definition: GeneralUtilityTest.php:123
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\isFirstPartOfStrReturnsTrueForMatchingFirstPartDataProvider
‪array isFirstPartOfStrReturnsTrueForMatchingFirstPartDataProvider()
Definition: GeneralUtilityTest.php:98
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\isFirstPartOfStrReturnsFalseForNotMatchingFirstPart
‪isFirstPartOfStrReturnsFalseForNotMatchingFirstPart($string, $part)
Definition: GeneralUtilityTest.php:149
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility
Definition: ExtensionManagementUtilityTest.php:18
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\isFirstPartOfStrReturnsTrueForMatchingFirstPart
‪isFirstPartOfStrReturnsTrueForMatchingFirstPart($string, $part)
Definition: GeneralUtilityTest.php:113
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\rmFromListRemovesElementsFromCommaSeparatedListDataProvider
‪array rmFromListRemovesElementsFromCommaSeparatedListDataProvider()
Definition: GeneralUtilityTest.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\GeneralUtilityTest\compileSelectedGetVarsFromArrayUsesGetPostDataFallback
‪compileSelectedGetVarsFromArrayUsesGetPostDataFallback()
Definition: GeneralUtilityTest.php:40