0f09a44a8b3aadb9eabed614ae3912a4b2e019e5
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / QueryGeneratorTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Database;
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
18 use TYPO3\CMS\Core\Database\QueryGenerator;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class QueryGeneratorTest extends UnitTestCase
25 {
26 /**
27 * Subject is not notice free, disable E_NOTICES
28 */
29 protected static $suppressNotices = true;
30
31 /**
32 * @return array
33 */
34 public function getSubscriptReturnsExpectedValuesDataProvider(): array
35 {
36 return [
37 'multidimensional array input' => [
38 [
39 'foo' => [
40 'bar' => 1,
41 'baz' => [
42 'jane' => 1,
43 'john' => 'doe',
44 ],
45 'fae' => 1,
46 ],
47 'don' => [
48 'dan' => 1,
49 'jim' => [
50 'jon' => 1,
51 'jin' => 'joh',
52 ],
53 ],
54 'one' => [
55 'two' => 1,
56 'three' => [
57 'four' => 1,
58 'five' =>'six',
59 ],
60 ]
61 ],
62 [
63 0 => 'foo',
64 1 => 'bar',
65 ],
66 ],
67 'array with multiple entries input' => [
68 [
69 'foo' => 1,
70 'bar' => 2,
71 'baz' => 3,
72 'don' => 4,
73 ],
74 [
75 0 => 'foo',
76 ],
77 ],
78 'array with one entry input' => [
79 [
80 'foo' => 'bar',
81 ],
82 [
83 0 => 'foo',
84 ],
85 ],
86 'empty array input' => [
87 [],
88 [
89 0 => null,
90 ],
91 ],
92 'empty multidimensional array input' => [
93 [[[[]]], [[]], [[]]],
94 [
95 0 => 0,
96 1 => 0,
97 2 => 0,
98 3 => null,
99 ],
100 ],
101 'null input' => [
102 null,
103 [],
104 ],
105 'string input' => [
106 'foo bar',
107 [],
108 ],
109 'numeric input' => [
110 3.14,
111 [],
112 ],
113 ];
114 }
115
116 /**
117 * @test
118 * @dataProvider getSubscriptReturnsExpectedValuesDataProvider
119 * @param $input
120 * @param array $expectedArray
121 */
122 public function getSubscriptReturnsExpectedValues($input, array $expectedArray)
123 {
124 $subject = new QueryGenerator();
125 $this->assertSame($expectedArray, $subject->getSubscript($input));
126 }
127 }