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