TYPO3 CMS  TYPO3_8-7
TreeDataProviderFactoryTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class TreeDataProviderFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
29  protected $subject;
30 
31  protected function setUp()
32  {
33  $this->subject = new TreeDataProviderFactory();
34  $GLOBALS['TCA'] = [];
35  $GLOBALS['TCA']['foo'] = [];
36  $GLOBALS['TCA']['foo']['ctrl'] = [];
37  $GLOBALS['TCA']['foo']['ctrl']['label'] = 'labelFoo';
38  $GLOBALS['TCA']['foo']['columns'] = [];
39  }
40 
45  {
46  return [
47  'Empty Configuration' => [[], 1288215890],
48  'File Configuration' => [
49  [
50  'internal_type' => 'file',
51  'treeConfig' => [],
52  ],
53  1288215891
54  ],
55  'Unknown Type' => [
56  [
57  'internal_type' => 'foo',
58  'treeConfig' => [],
59  ],
60  1288215892
61  ],
62  'No foreign table' => [
63  [
64  'internal_type' => 'db',
65  'treeConfig' => [],
66  ],
67  1288215888
68  ],
69  'No tree configuration' => [
70  [
71  'internal_type' => 'db',
72  'foreign_table' => 'foo',
73  ],
74  1288215890
75  ],
76  'Tree configuration not array' => [
77  [
78  'internal_type' => 'db',
79  'foreign_table' => 'foo',
80  'treeConfig' => 'bar',
81  ],
82  1288215890
83  ],
84  'Tree configuration missing childer and parent field' => [
85  [
86  'internal_type' => 'db',
87  'foreign_table' => 'foo',
88  'treeConfig' => [],
89  ],
90  1288215889
91  ],
92  ];
93  }
94 
101  public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, $expectedExceptionCode)
102  {
103  $this->expectException(\InvalidArgumentException::class);
104  $this->expectExceptionCode($expectedExceptionCode);
105 
106  $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
107  }
108 
113  {
114  $dataProviderMockClassName = TreeDataProviderFixture::class;
115 
116  $tcaConfiguration = [
117  'treeConfig' => ['dataProvider' => $dataProviderMockClassName],
118  'internal_type' => 'foo'
119  ];
120  $dataProvider = $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
121 
122  $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
123  }
124 
129  {
130  $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
131 
132  $tcaConfiguration = [
133  'treeConfig' => [
134  'dataProvider' => $dataProviderMockClassName,
135  ],
136  'internal_type' => 'foo',
137  ];
138  $this->expectException(\RuntimeException::class);
139  $this->expectExceptionCode(1438875249);
140  $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', ['uid' => 1]);
141  }
142 }
factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, $expectedExceptionCode)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']