TYPO3 CMS  TYPO3_6-2
ConfigurationItemRepositoryTest.php
Go to the documentation of this file.
1 <?php
3 
22 
27 
32 
38  public function setUp() {
39  // Mock system under test to make protected methods accessible
40  $this->configurationItemRepository = $this->getAccessibleMock(
41  'TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ConfigurationItemRepository',
42  array('dummy')
43  );
44 
45  $this->injectedObjectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
46  $this->configurationItemRepository->_set(
47  'objectManager',
48  $this->injectedObjectManagerMock
49  );
50  }
51 
56  $flatConfigurationItemArray = array(
57  'item1' => array(
58  'cat' => 'basic',
59  'subcat_name' => 'enable',
60  'subcat' => 'a/enable/10z',
61  'type' => 'string',
62  'label' => 'Item 1: This is the first configuration item',
63  'name' =>'item1',
64  'value' => 'one',
65  'default_value' => 'one',
66  'subcat_label' => 'Enable features',
67  ),
68  'integerValue' => array(
69  'cat' => 'basic',
70  'subcat_name' => 'enable',
71  'subcat' => 'a/enable/20z',
72  'type' => 'int+',
73  'label' => 'Integer Value: Please insert a positive integer value',
74  'name' =>'integerValue',
75  'value' => '1',
76  'default_value' => '1',
77  'subcat_label' => 'Enable features',
78  ),
79  'enableJquery' => array(
80  'cat' => 'advanced',
81  'subcat_name' => 'file',
82  'subcat' => 'c/file/10z',
83  'type' => 'boolean',
84  'label' => 'enableJquery: Insert jQuery plugin',
85  'name' =>'enableJquery',
86  'value' => '1',
87  'default_value' => '1',
88  'subcat_label' => 'Files',
89  ),
90  );
91 
93  'TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ConfigurationItemRepository',
94  array('mergeWithExistingConfiguration', 'translate')
95  );
97  'objectManager',
98  $this->injectedObjectManagerMock
99  );
100  $configurationUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility', array(), array(), '', FALSE);
101  $configurationUtilityMock
102  ->expects($this->once())
103  ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
104  ->will($this->returnValue($flatConfigurationItemArray));
105  $this->injectedObjectManagerMock
106  ->expects($this->any())
107  ->method('get')
108  ->will($this->returnValue($configurationUtilityMock));
110  ->expects($this->any())
111  ->method('mergeWithExistingConfiguration')
112  ->will($this->returnValue($flatConfigurationItemArray));
113 
114  $expectedArray = array(
115  'basic' => array(
116  'enable' => array(
117  'item1' => array(
118  'cat' => 'basic',
119  'subcat_name' => 'enable',
120  'subcat' => 'a/enable/10z',
121  'type' => 'string',
122  'label' => 'Item 1: This is the first configuration item',
123  'name' =>'item1',
124  'value' => 'one',
125  'default_value' => 'one',
126  'subcat_label' => 'Enable features',
127  'labels' => array(
128  0 => 'Item 1',
129  1 => 'This is the first configuration item'
130  )
131  ),
132  'integerValue' => array(
133  'cat' => 'basic',
134  'subcat_name' => 'enable',
135  'subcat' => 'a/enable/20z',
136  'type' => 'int+',
137  'label' => 'Integer Value: Please insert a positive integer value',
138  'name' =>'integerValue',
139  'value' => '1',
140  'default_value' => '1',
141  'subcat_label' => 'Enable features',
142  'labels' => array(
143  0 => 'Integer Value',
144  1 => 'Please insert a positive integer value'
145  )
146  )
147  )
148  ),
149  'advanced' => array(
150  'file' => array(
151  'enableJquery' => array(
152  'cat' => 'advanced',
153  'subcat_name' => 'file',
154  'subcat' => 'c/file/10z',
155  'type' => 'boolean',
156  'label' => 'enableJquery: Insert jQuery plugin',
157  'name' =>'enableJquery',
158  'value' => '1',
159  'default_value' => '1',
160  'subcat_label' => 'Files',
161  'labels' => array(
162  0 => 'enableJquery',
163  1 => 'Insert jQuery plugin'
164  )
165  ),
166  )
167  )
168  );
169 
170  $this->assertSame(
171  $expectedArray,
172  $configurationItemRepository->_call('getConfigurationArrayFromExtensionKey', $this->getUniqueId('some_extension'))
173  );
174  }
175 
181  $configuration = array(
182  '__meta__' => 'metaInformation',
183  'test123' => 'test123'
184  );
185  $this->configurationItemRepository->_callRef('addMetaInformation', $configuration);
186  $this->assertEquals(array('test123' => 'test123'), $configuration);
187  }
188 
194  $configuration = array(
195  '__meta__' => 'metaInformation',
196  'test123' => 'test123'
197  );
198  $meta = $this->configurationItemRepository->_callRef('addMetaInformation', $configuration);
199  $this->assertEquals('metaInformation', $meta);
200  }
201 
206  return array(
207  array(
208  array(
209  'cat' => 'basic',
210  'subcat_name' => 'enable',
211  'subcat' => 'a/enable/z',
212  'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
213  'label' => 'Frontend configuration check',
214  'name' => 'checkConfigurationFE',
215  'value' => 0,
216  'default_value' => 0,
217  'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend'
218  )
219  ),
220  array(
221  array(
222  'cat' => 'basic',
223  'subcat_name' => 'enable',
224  'subcat' => 'a/enable/z',
225  'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend]',
226  'label' => 'Backend configuration check',
227  'name' => 'checkConfigurationBE',
228  'value' => 0,
229  'default_value' => 0,
230  'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend'
231  )
232  ),
233  array(
234  array(
235  'cat' => 'basic',
236  'subcat_name' => 'enable',
237  'subcat' => 'a/enable/z',
238  'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]',
239  'label' => 'Hashing method for the frontend: Defines salted hashing method to use. Choose "Portable PHP password hashing" to stay compatible with other CMS (e.g. Drupal, Wordpress). Choose "MD5 salted hashing" to reuse TYPO3 passwords for OS level authentication (other servers could use TYPO3 passwords). Choose "Blowfish salted hashing" for advanced security to reuse passwords on OS level (Blowfish might not be supported on your system TODO).',
240  'name' => 'FE.saltedPWHashingMethod',
241  'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt',
242  'default_value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt',
243  'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE'
244  )
245  )
246  );
247  }
248 
256  $configurationOptionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeUser', $configurationOption);
257  $this->assertEquals('user', $configurationOptionModified['type']);
258  $this->assertEquals($configurationOption['comparisonGeneric'], $configurationOptionModified['generic']);
259  }
260 
266  $option = array(
267  'cat' => 'basic',
268  'subcat_name' => 'enable',
269  'subcat' => 'a/enable/100z',
270  'type' => 'options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.),Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.),Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)]',
271  'label' => 'Default configuration settings',
272  'name' => 'defaultConfiguration',
273  'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
274  'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
275  'genericComparisonValue' => array(
276  'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)',
277  'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
278  'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)'
279  ),
280  'typeComparisonValue' => 'options'
281  );
282  $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
283  $this->assertArrayHasKey('generic', $optionModified);
284  $this->assertArrayHasKey('type', $optionModified);
285  $this->assertArrayHasKey('label', $optionModified);
286  $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
287  $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
288  }
289 
295  $option = array(
296  'cat' => 'basic',
297  'subcat_name' => 'enable',
298  'subcat' => 'a/enable/100z',
299  'type' => 'options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)=MINIMAL,Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.) = TYPICAL,Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)=DEMO]',
300  'label' => 'Default configuration settings',
301  'name' => 'defaultConfiguration',
302  'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
303  'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
304  'genericComparisonValue' => array(
305  'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'MINIMAL',
306  'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'TYPICAL',
307  'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'DEMO'
308  ),
309  'typeComparisonValue' => 'options'
310  );
311  $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
312  $this->assertArrayHasKey('generic', $optionModified);
313  $this->assertArrayHasKey('type', $optionModified);
314  $this->assertArrayHasKey('label', $optionModified);
315  $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
316  $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
317  }
318 
324  $exception = $this->getMock('RuntimeException');
325  $configurationManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
326  $configurationManagerMock
327  ->expects($this->once())
328  ->method('getConfigurationValueByPath')
329  ->will($this->throwException($exception));
330  $this->injectedObjectManagerMock
331  ->expects($this->any())
332  ->method('get')
333  ->will($this->returnValue($configurationManagerMock));
334 
335  $this->configurationItemRepository->_call(
336  'mergeWithExistingConfiguration',
337  array(),
338  $this->getUniqueId('not_existing_extension')
339  );
340  }
341 
347  $exception = $this->getMock('RuntimeException');
348  $configurationManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
349  $configurationManagerMock
350  ->expects($this->once())
351  ->method('getConfigurationValueByPath')
352  ->will($this->throwException($exception));
353  $this->injectedObjectManagerMock
354  ->expects($this->any())
355  ->method('get')
356  ->will($this->returnValue($configurationManagerMock));
357  $defaultConfiguration = array(
358  'foo' => 'bar'
359  );
360  $configuration = $this->configurationItemRepository->_call(
361  'mergeWithExistingConfiguration',
362  $defaultConfiguration,
363  $this->getUniqueId('not_existing_extension')
364  );
365  $this->assertEquals($defaultConfiguration, $configuration);
366  }
367 
373  $localConfiguration = serialize(array(
374  'FE.' => array(
375  'enabled' => '1',
376  'saltedPWHashingMethod' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface_sha1'
377  ),
378  'CLI.' => array(
379  'enabled' => '0'
380  )
381  ));
382 
383  $configurationManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
384  $configurationManagerMock
385  ->expects($this->once())
386  ->method('getConfigurationValueByPath')
387  ->with('EXT/extConf/testextensionkey')
388  ->will($this->returnValue($localConfiguration));
389 
390  $this->injectedObjectManagerMock
391  ->expects($this->any())
392  ->method('get')
393  ->will($this->returnValue($configurationManagerMock));
394 
395  $defaultConfiguration = array(
396  'FE.enabled' => array(
397  'value' => '0'
398  ),
399  'FE.saltedPWHashingMethod' => array(
400  'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
401  ),
402  'BE.enabled' => array(
403  'value' => '1'
404  ),
405  'BE.saltedPWHashingMethod' => array(
406  'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
407  )
408  );
409 
410  $expectedResult = array(
411  'FE.enabled' => array(
412  'value' => '1'
413  ),
414  'FE.saltedPWHashingMethod' => array(
415  'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface_sha1'
416  ),
417  'BE.enabled' => array(
418  'value' => '1'
419  ),
420  'BE.saltedPWHashingMethod' => array(
421  'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
422  ),
423  'CLI.enabled' => array(
424  'value' => '0'
425  )
426  );
427 
428  $actualResult = $this->configurationItemRepository->_call(
429  'mergeWithExistingConfiguration',
430  $defaultConfiguration,
431  'testextensionkey'
432  );
433 
434  $this->assertEquals($expectedResult, $actualResult);
435  }
436 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)