fdc9a6016abc09f51eb3d081a15877f328243bd4
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Configuration / AbstractConfigurationManager_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_Configuration_AbstractConfigurationManager_testcase extends Tx_Extbase_Base_testcase {
29
30 /**
31 * @test
32 */
33 public function settingsCanBeLoaded() {
34 $expectedSettings = array(
35 'maxItems' => 3,
36 'Post' => array(
37 'singlePid' => 25,
38 'maxItems' => 8,
39 'index' => array(
40 'maxItems' => 5
41 ),
42 ),
43 'Comment' => array(
44 'content' => array(
45 'crop' => 100
46 )
47 )
48 );
49
50 $configurationSource = $this->getMock('Tx_Extbase_Configuration_Source_TypoScriptSource', array('load'));
51 $configurationSource->expects($this->any())
52 ->method('load')
53 ->with('Tx_Extbase_Foo_Bar')
54 ->will($this->returnValue($expectedSettings));
55 $configurationSources = array();
56 $configurationSources[] = $configurationSource;
57
58 $configurationManager = $this->getMock('Tx_Extbase_Configuration_AbstractConfigurationManager', array('loadTypoScriptSetup', 'getContextSpecificFrameworkConfiguration'), array($configurationSources));
59 $actualSettings = $configurationManager->getSettings('Tx_Extbase_Foo_Bar');
60
61 $this->assertEquals($expectedSettings, $actualSettings, 'The retrieved settings differs from the retrieved settings.');
62 }
63
64 /**
65 * @test
66 */
67 public function storagePidFromExtbaseConfigurationOverridesDefaultStoragePid() {
68 $typoScriptSetup = array(
69 'config.' => array(
70 'tx_extbase.' => array(
71 'persistence' => array(
72 'storagePid' => 'newStoragePid'
73 )
74 )
75 )
76 );
77 $pluginConfiguration = array();
78
79 $configurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_AbstractConfigurationManager'), array('loadTypoScriptSetup'), array(), '', FALSE);
80 $configurationManager->expects($this->any())->method('loadTypoScriptSetup')->will($this->returnValue($typoScriptSetup));
81 $expectedResult = array(
82 'persistence' => array(
83 'storagePid' => 'newStoragePid',
84 ),
85 );
86 $actualResult = $configurationManager->getFrameworkConfiguration($pluginConfiguration);
87
88 $this->assertEquals($expectedResult, $actualResult);
89 }
90
91 /**
92 * @test
93 */
94 public function getFrameworkConfigurationCorrectlyMergesPluginConfigurationWithExtbaseConfiguration() {
95 $typoScriptSetup = array(
96 'config.' => array(
97 'tx_extbase.' => array(
98 'foo' => 'bar',
99 'persistence' => array(
100 'some' => 'Default',
101 'storagePid' => 'shouldBeOverwritten'
102 )
103 )
104 )
105 );
106 $pluginConfiguration = array(
107 'settings' => '< settingsReference',
108 'persistence' => '< persistenceReference',
109 'view' => '< viewReference',
110 );
111
112 $mockTypoScriptParser = $this->getMock('t3lib_TSparser');
113 $mockTypoScriptParser->expects($this->at(0))->method('getVal')->with('settingsReference', $typoScriptSetup)->will($this->returnValue(array('', array('resolved' => 'settingsReference'))));
114 $mockTypoScriptParser->expects($this->at(1))->method('getVal')->with('persistenceReference', $typoScriptSetup)->will($this->returnValue(array('', array('storagePid' => 'overwritten'))));
115 $mockTypoScriptParser->expects($this->at(2))->method('getVal')->with('viewReference', $typoScriptSetup)->will($this->returnValue(array('', array('resolved' => 'viewReference'))));
116
117 $configurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_AbstractConfigurationManager'), array('loadTypoScriptSetup'), array(), '', FALSE);
118 $configurationManager->_set('typoScriptParser', $mockTypoScriptParser);
119 $configurationManager->expects($this->any())->method('loadTypoScriptSetup')->will($this->returnValue($typoScriptSetup));
120
121 $expectedResult = array(
122 'persistence' => array(
123 'storagePid' => 'overwritten',
124 'some' => 'Default'
125 ),
126 'foo' => 'bar',
127 'settings' => array(
128 'resolved' => 'settingsReference'
129 ),
130 'view' => array(
131 'resolved' => 'viewReference'
132 )
133 );
134 $actualResult = $configurationManager->getFrameworkConfiguration($pluginConfiguration);
135
136 $this->assertEquals($expectedResult, $actualResult);
137 }
138
139 }
140 ?>