[TASK] Make Tests/Unit/Tree/ notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Tree / TableConfiguration / TreeDataProviderFactoryTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
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\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture;
19 use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture;
20 use TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class TreeDataProviderFactoryTest extends UnitTestCase
27 {
28 /**
29 * @var TreeDataProviderFactory
30 */
31 protected $subject;
32
33 protected function setUp(): void
34 {
35 $this->subject = new TreeDataProviderFactory();
36 $GLOBALS['TCA'] = [];
37 $GLOBALS['TCA']['foo'] = [];
38 $GLOBALS['TCA']['foo']['ctrl'] = [];
39 $GLOBALS['TCA']['foo']['ctrl']['label'] = 'labelFoo';
40 $GLOBALS['TCA']['foo']['columns'] = [];
41 }
42
43 /**
44 * @return array
45 */
46 public function invalidConfigurationDataProvider(): array
47 {
48 return [
49 'Empty Configuration' => [[], 1288215890],
50 'File Configuration' => [
51 [
52 'internal_type' => 'file',
53 'treeConfig' => [],
54 ],
55 1288215891
56 ],
57 'Unknown Type' => [
58 [
59 'internal_type' => 'foo',
60 'treeConfig' => [],
61 ],
62 1288215892
63 ],
64 'No foreign table' => [
65 [
66 'internal_type' => 'db',
67 'treeConfig' => [],
68 ],
69 1288215888
70 ],
71 'No tree configuration' => [
72 [
73 'internal_type' => 'db',
74 'foreign_table' => 'foo',
75 ],
76 1288215890
77 ],
78 'Tree configuration not array' => [
79 [
80 'internal_type' => 'db',
81 'foreign_table' => 'foo',
82 'treeConfig' => 'bar',
83 ],
84 1288215890
85 ],
86 'Tree configuration missing childer and parent field' => [
87 [
88 'internal_type' => 'db',
89 'foreign_table' => 'foo',
90 'treeConfig' => [],
91 ],
92 1288215889
93 ],
94 ];
95 }
96
97 /**
98 * @param array $tcaConfiguration
99 * @param int $expectedExceptionCode
100 * @test
101 * @dataProvider invalidConfigurationDataProvider
102 */
103 public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode): void
104 {
105 $this->expectException(\InvalidArgumentException::class);
106 $this->expectExceptionCode($expectedExceptionCode);
107
108 $this->subject::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
109 }
110
111 /**
112 * @test
113 */
114 public function configuredDataProviderClassIsInstantiated(): void
115 {
116 $dataProviderMockClassName = TreeDataProviderFixture::class;
117
118 $tcaConfiguration = [
119 'treeConfig' => ['dataProvider' => $dataProviderMockClassName],
120 'internal_type' => 'foo'
121 ];
122 $dataProvider = $this->subject::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
123
124 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
125 }
126
127 /**
128 * @test
129 */
130 public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor(): void
131 {
132 $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
133
134 $tcaConfiguration = [
135 'treeConfig' => [
136 'dataProvider' => $dataProviderMockClassName,
137 ],
138 'internal_type' => 'foo',
139 ];
140 $this->expectException(\RuntimeException::class);
141 $this->expectExceptionCode(1438875249);
142 $this->subject::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
143 }
144 }