‪TYPO3CMS  9.5
TreeDataProviderFactoryTest.php
Go to the documentation of this file.
1 <?php
2 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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪TreeDataProviderFactoryTest extends UnitTestCase
27 {
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 
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 
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 
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 
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 }
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration
Definition: DatabaseTreeDataProviderTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\$subject
‪TreeDataProviderFactory $subject
Definition: TreeDataProviderFactoryTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\configuredDataProviderClassIsInstantiated
‪configuredDataProviderClassIsInstantiated()
Definition: TreeDataProviderFactoryTest.php:113
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\setUp
‪setUp()
Definition: TreeDataProviderFactoryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture
Definition: TreeDataProviderFixture.php:21
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture
Definition: TreeDataProviderWithConfigurationFixture.php:21
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\invalidConfigurationDataProvider
‪array invalidConfigurationDataProvider()
Definition: TreeDataProviderFactoryTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\factoryThrowsExceptionIfInvalidConfigurationIsGiven
‪factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode)
Definition: TreeDataProviderFactoryTest.php:102
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest
Definition: TreeDataProviderFactoryTest.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
Definition: TreeDataProviderFactory.php:22
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor
‪configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor()
Definition: TreeDataProviderFactoryTest.php:129