[TASK] Removes eval() in core tree dataprovider unit test
[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\Tests\UnitTestCase;
20 use TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory;
21
22 /**
23 * Test case
24 */
25 class TreeDataProviderFactoryTest extends UnitTestCase {
26
27 /**
28 * @var TreeDataProviderFactory
29 */
30 protected $subject;
31
32 protected function setUp() {
33 $this->subject = new TreeDataProviderFactory();
34 $GLOBALS['TCA'] = array();
35 $GLOBALS['TCA']['foo'] = array();
36 $GLOBALS['TCA']['foo']['ctrl'] = array();
37 $GLOBALS['TCA']['foo']['ctrl']['label'] = 'labelFoo';
38 $GLOBALS['TCA']['foo']['columns'] = array();
39 }
40
41 /**
42 * @return array
43 */
44 public function invalidConfigurationDataProvider() {
45 return array(
46 'Empty Configuration' => array(array()),
47 'File Configuration' => array(array(
48 'internal_type' => 'file',
49 'treeConfig' => array(),
50 )),
51 'Unknown Type' => array(array(
52 'internal_type' => 'foo',
53 'treeConfig' => array(),
54 )),
55 'No foreign table' => array(array(
56 'internal_type' => 'db',
57 'treeConfig' => array(),
58 )),
59 'No tree configuration' => array(array(
60 'internal_type' => 'db',
61 'foreign_table' => 'foo',
62 )),
63 'Tree configuration not array' => array(array(
64 'internal_type' => 'db',
65 'foreign_table' => 'foo',
66 'treeConfig' => 'bar',
67 )),
68 'Tree configuration missing childer and parent field' => array(array(
69 'internal_type' => 'db',
70 'foreign_table' => 'foo',
71 'treeConfig' => array(),
72 )),
73 );
74 }
75
76 /**
77 * @param array $tcaConfiguration
78 * @test
79 * @dataProvider invalidConfigurationDataProvider
80 * @expectedException \InvalidArgumentException
81 */
82 public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration) {
83 $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
84 }
85
86 /**
87 * @test
88 */
89 public function configuredDataProviderClassIsInstantiated() {
90 $dataProviderMockClassName = TreeDataProviderFixture::class;
91
92 $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
93 $dataProvider = $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
94
95 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
96 }
97
98 /**
99 * @test
100 */
101 public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor() {
102 $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
103
104 $tcaConfiguration = [
105 'treeConfig' => [
106 'dataProvider' => $dataProviderMockClassName,
107 ],
108 'internal_type' => 'foo',
109 ];
110 $this->setExpectedException(\RuntimeException::class, $this->anything(), 1438875249);
111 $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
112 }
113
114 }