‪TYPO3CMS  11.5
TreeDataProviderFactoryTest.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 
20 use Prophecy\PhpUnit\ProphecyTrait;
21 use Psr\EventDispatcher\EventDispatcherInterface;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪TreeDataProviderFactoryTest extends UnitTestCase
33 {
34  use ProphecyTrait;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
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 
49  public function ‪invalidConfigurationDataProvider(): array
50  {
51  return [
52  'Empty Configuration' => [[], 1288215890],
53  'Unknown Type' => [
54  [
55  'internal_type' => 'foo',
56  'treeConfig' => [],
57  ],
58  1288215892,
59  ],
60  'No foreign table' => [
61  [
62  'treeConfig' => [],
63  ],
64  1288215888,
65  ],
66  'No tree configuration' => [
67  [
68  'foreign_table' => 'foo',
69  ],
70  1288215890,
71  ],
72  'Tree configuration not array' => [
73  [
74  'foreign_table' => 'foo',
75  'treeConfig' => 'bar',
76  ],
77  1288215890,
78  ],
79  'Tree configuration missing children and parent field' => [
80  [
81  'foreign_table' => 'foo',
82  'treeConfig' => [],
83  ],
84  1288215889,
85  ],
86  ];
87  }
88 
95  public function ‪factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode): void
96  {
97  if (($tcaConfiguration['internal_type'] ?? 'db') === 'db' && is_array($tcaConfiguration['treeConfig'] ?? null)) {
98  $treeDataProvider = $this->prophesize(DatabaseTreeDataProvider::class);
99  GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProvider->reveal());
100  }
101 
102  $this->expectException(\InvalidArgumentException::class);
103  $this->expectExceptionCode($expectedExceptionCode);
104 
105  ‪TreeDataProviderFactory::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
106  }
107 
111  public function ‪configuredDataProviderClassIsInstantiated(): void
112  {
113  $dataProviderMockClassName = TreeDataProviderFixture::class;
114  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
115  GeneralUtility::addInstance(EventDispatcherInterface::class, $eventDispatcher->reveal());
116 
117  $tcaConfiguration = [
118  'treeConfig' => ['dataProvider' => $dataProviderMockClassName],
119  'internal_type' => 'foo',
120  ];
121  $dataProvider = ‪TreeDataProviderFactory::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
122 
123  self::assertInstanceOf($dataProviderMockClassName, $dataProvider);
124  }
125 
130  {
131  $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
132  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
133  GeneralUtility::addInstance(EventDispatcherInterface::class, $eventDispatcher->reveal());
134 
135  $tcaConfiguration = [
136  'treeConfig' => [
137  'dataProvider' => $dataProviderMockClassName,
138  ],
139  ];
140  $this->expectException(\RuntimeException::class);
141  $this->expectExceptionCode(1438875249);
142  ‪TreeDataProviderFactory::getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
143  }
144 }
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration
Definition: DatabaseTreeDataProviderTest.php:18
‪TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider
Definition: DatabaseTreeDataProvider.php:37
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\configuredDataProviderClassIsInstantiated
‪configuredDataProviderClassIsInstantiated()
Definition: TreeDataProviderFactoryTest.php:110
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\setUp
‪setUp()
Definition: TreeDataProviderFactoryTest.php:35
‪TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory\getDataProvider
‪static DatabaseTreeDataProvider getDataProvider(array $tcaConfiguration, $table, $field, $currentValue)
Definition: TreeDataProviderFactory.php:37
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture
Definition: TreeDataProviderFixture.php:24
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture
Definition: TreeDataProviderWithConfigurationFixture.php:24
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\invalidConfigurationDataProvider
‪array invalidConfigurationDataProvider()
Definition: TreeDataProviderFactoryTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\factoryThrowsExceptionIfInvalidConfigurationIsGiven
‪factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode)
Definition: TreeDataProviderFactoryTest.php:94
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest
Definition: TreeDataProviderFactoryTest.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
Definition: TreeDataProviderFactory.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\TreeDataProviderFactoryTest\configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor
‪configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor()
Definition: TreeDataProviderFactoryTest.php:128