[~TASK] Extbase (Tests): fixed configuration manager tests that were broken in r1269
[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', 'getContextSpecificFrameworkConfiguration'), array(), '', FALSE);
80 $configurationManager->expects($this->any())->method('loadTypoScriptSetup')->will($this->returnValue($typoScriptSetup));
81 $configurationManager->expects($this->any())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue(array()));
82 $expectedResult = array(
83 'persistence' => array(
84 'storagePid' => 'newStoragePid',
85 ),
86 );
87 $actualResult = $configurationManager->getFrameworkConfiguration($pluginConfiguration);
88
89 $this->assertEquals($expectedResult, $actualResult);
90 }
91
92 /**
93 * @test
94 */
95 public function getFrameworkConfigurationCorrectlyMergesPluginConfigurationWithExtbaseConfiguration() {
96 $typoScriptSetup = array(
97 'config.' => array(
98 'tx_extbase.' => array(
99 'foo' => 'bar',
100 'persistence' => array(
101 'some' => 'Default',
102 'storagePid' => 'shouldBeOverwritten'
103 )
104 )
105 )
106 );
107 $pluginConfiguration = array(
108 'settings' => '< settingsReference',
109 'persistence' => '< persistenceReference',
110 'view' => '< viewReference',
111 );
112
113 $mockTypoScriptParser = $this->getMock('t3lib_TSparser');
114 $mockTypoScriptParser->expects($this->at(0))->method('getVal')->with('settingsReference', $typoScriptSetup)->will($this->returnValue(array('', array('resolved' => 'settingsReference'))));
115 $mockTypoScriptParser->expects($this->at(1))->method('getVal')->with('persistenceReference', $typoScriptSetup)->will($this->returnValue(array('', array('storagePid' => 'overwritten'))));
116 $mockTypoScriptParser->expects($this->at(2))->method('getVal')->with('viewReference', $typoScriptSetup)->will($this->returnValue(array('', array('resolved' => 'viewReference'))));
117
118 $configurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_AbstractConfigurationManager'), array('loadTypoScriptSetup', 'getContextSpecificFrameworkConfiguration'), array(), '', FALSE);
119 $configurationManager->_set('typoScriptParser', $mockTypoScriptParser);
120 $configurationManager->expects($this->any())->method('loadTypoScriptSetup')->will($this->returnValue($typoScriptSetup));
121 $configurationManager->expects($this->any())->method('getContextSpecificFrameworkConfiguration')->will($this->returnValue(array()));
122
123 $expectedResult = array(
124 'persistence' => array(
125 'storagePid' => 'overwritten',
126 'some' => 'Default'
127 ),
128 'foo' => 'bar',
129 'settings' => array(
130 'resolved' => 'settingsReference'
131 ),
132 'view' => array(
133 'resolved' => 'viewReference'
134 )
135 );
136 $actualResult = $configurationManager->getFrameworkConfiguration($pluginConfiguration);
137
138 $this->assertEquals($expectedResult, $actualResult);
139 }
140
141 }
142 ?>