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