2 namespace TYPO3\CMS\Core\Tests\Tree\TableConfiguration
;
4 /***************************************************************
7 * (c) 2012 Helmut Hummel <helmut.hummel@typo3.org>
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.
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 textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
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.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
31 * Testcase for TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
33 class TreeDataProviderFactoryTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
36 * @var \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
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();
52 public function invalidConfigurationDataProvider() {
54 'Empty Configuration' => array(array()),
55 'File Configuration' => array(array(
56 'internal_type' => 'file',
57 'treeConfig' => array(),
59 'Unknown Type' => array(array(
60 'internal_type' => 'foo',
61 'treeConfig' => array(),
63 'No foreign table' => array(array(
64 'internal_type' => 'db',
65 'treeConfig' => array(),
67 'No tree configuration' => array(array(
68 'internal_type' => 'db',
69 'foreign_table' => 'foo',
71 'Tree configuration not array' => array(array(
72 'internal_type' => 'db',
73 'foreign_table' => 'foo',
74 'treeConfig' => 'bar',
76 'Tree configuration missing childer and parent field' => array(array(
77 'internal_type' => 'db',
78 'foreign_table' => 'foo',
79 'treeConfig' => array(),
85 * @param array $tcaConfiguration
87 * @dataProvider invalidConfigurationDataProvider
88 * @expectedException \InvalidArgumentException
90 public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration) {
91 $this->fixture
->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
97 public function configuredDataProviderClassIsInstantiated() {
98 $dataProviderMockClassName = uniqid('tx_coretest_tree_data_provider');
99 eval('class ' . $dataProviderMockClassName . ' {
100 function __construct($configuration) {
104 $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
105 $dataProvider = $this->fixture
->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
107 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
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\');
123 $dataProvider = $this->fixture
->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
125 $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);