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