[TASK] Fix typo in copyright notice
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Helmut Hummel <helmut.hummel@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Testcase for TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
32 */
33 class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
34
35 /**
36 * @var \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
37 */
38 protected $fixture;
39
40 public function setUp() {
41 $this->fixture = new \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory();
42 $GLOBALS['TCA'] = array();
43 $GLOBALS['TCA']['foo'] = array();
44 $GLOBALS['TCA']['foo']['ctrl'] = array();
45 $GLOBALS['TCA']['foo']['ctrl']['label'] = 'labelFoo';
46 $GLOBALS['TCA']['foo']['columns'] = array();
47 }
48
49 /**
50 * @return array
51 */
52 public function invalidConfigurationDataProvider() {
53 return array(
54 'Empty Configuration' => array(array()),
55 'File Configuration' => array(array(
56 'internal_type' => 'file',
57 'treeConfig' => array(),
58 )),
59 'Unknown Type' => array(array(
60 'internal_type' => 'foo',
61 'treeConfig' => array(),
62 )),
63 'No foreign table' => array(array(
64 'internal_type' => 'db',
65 'treeConfig' => array(),
66 )),
67 'No tree configuration' => array(array(
68 'internal_type' => 'db',
69 'foreign_table' => 'foo',
70 )),
71 'Tree configuration not array' => array(array(
72 'internal_type' => 'db',
73 'foreign_table' => 'foo',
74 'treeConfig' => 'bar',
75 )),
76 'Tree configuration missing childer and parent field' => array(array(
77 'internal_type' => 'db',
78 'foreign_table' => 'foo',
79 'treeConfig' => array(),
80 )),
81 );
82 }
83
84 /**
85 * @param array $tcaConfiguration
86 * @test
87 * @dataProvider invalidConfigurationDataProvider
88 * @expectedException \InvalidArgumentException
89 */
90 public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration) {
91 $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
92 }
93
94 /**
95 * @test
96 */
97 public function configuredDataProviderClassIsInstantiated() {
98 $dataProviderMockClassName = uniqid('tx_coretest_tree_data_provider');
99 eval('class ' . $dataProviderMockClassName . ' {
100 function __construct($configuration) {
101 }
102 }');
103
104 $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
105 $dataProvider = $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
106
107 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
108 }
109
110 /**
111 * @test
112 */
113 public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor() {
114 $dataProviderMockClassName = uniqid('tx_coretest_tree_data_provider');
115 $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
116 $classCode = 'class ' . $dataProviderMockClassName . ' {
117 function __construct($configuration) {
118 if (!is_array($configuration)) throw new Exception(\'Failed asserting that the contructor arguments are an array\');
119 if ($configuration !== ' . var_export($tcaConfiguration, TRUE) . ') throw new Exception(\'Failed asserting that the contructor arguments are correctly passed\');
120 }
121 }';
122 eval($classCode);
123 $dataProvider = $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
124
125 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
126 }
127 }