c4ef6c066c60bcd73f0539c2126744ab320c0b07
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Tree / TableConfiguration / TreeDataProviderFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture;
18 use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture;
19 use TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory;
20
21 /**
22 * Test case
23 */
24 class TreeDataProviderFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
26 /**
27 * Subject is not notice free, disable E_NOTICES
28 */
29 protected static $suppressNotices = true;
30
31 /**
32 * @var TreeDataProviderFactory
33 */
34 protected $subject;
35
36 protected function setUp()
37 {
38 $this->subject = new TreeDataProviderFactory();
39 $GLOBALS['TCA'] = [];
40 $GLOBALS['TCA']['foo'] = [];
41 $GLOBALS['TCA']['foo']['ctrl'] = [];
42 $GLOBALS['TCA']['foo']['ctrl']['label'] = 'labelFoo';
43 $GLOBALS['TCA']['foo']['columns'] = [];
44 }
45
46 /**
47 * @return array
48 */
49 public function invalidConfigurationDataProvider()
50 {
51 return [
52 'Empty Configuration' => [[], 1288215890],
53 'File Configuration' => [
54 [
55 'internal_type' => 'file',
56 'treeConfig' => [],
57 ],
58 1288215891
59 ],
60 'Unknown Type' => [
61 [
62 'internal_type' => 'foo',
63 'treeConfig' => [],
64 ],
65 1288215892
66 ],
67 'No foreign table' => [
68 [
69 'internal_type' => 'db',
70 'treeConfig' => [],
71 ],
72 1288215888
73 ],
74 'No tree configuration' => [
75 [
76 'internal_type' => 'db',
77 'foreign_table' => 'foo',
78 ],
79 1288215890
80 ],
81 'Tree configuration not array' => [
82 [
83 'internal_type' => 'db',
84 'foreign_table' => 'foo',
85 'treeConfig' => 'bar',
86 ],
87 1288215890
88 ],
89 'Tree configuration missing childer and parent field' => [
90 [
91 'internal_type' => 'db',
92 'foreign_table' => 'foo',
93 'treeConfig' => [],
94 ],
95 1288215889
96 ],
97 ];
98 }
99
100 /**
101 * @param array $tcaConfiguration
102 * @param string $expectedExceptionCode
103 * @test
104 * @dataProvider invalidConfigurationDataProvider
105 */
106 public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, $expectedExceptionCode)
107 {
108 $this->expectException(\InvalidArgumentException::class);
109 $this->expectExceptionCode($expectedExceptionCode);
110
111 $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
112 }
113
114 /**
115 * @test
116 */
117 public function configuredDataProviderClassIsInstantiated()
118 {
119 $dataProviderMockClassName = TreeDataProviderFixture::class;
120
121 $tcaConfiguration = [
122 'treeConfig' => ['dataProvider' => $dataProviderMockClassName],
123 'internal_type' => 'foo'
124 ];
125 $dataProvider = $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
126
127 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
128 }
129
130 /**
131 * @test
132 */
133 public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor()
134 {
135 $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
136
137 $tcaConfiguration = [
138 'treeConfig' => [
139 'dataProvider' => $dataProviderMockClassName,
140 ],
141 'internal_type' => 'foo',
142 ];
143 $this->expectException(\RuntimeException::class);
144 $this->expectExceptionCode(1438875249);
145 $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
146 }
147 }