TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ConfigurationItemRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Repository;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 {
27 
32 
38  protected function setUp()
39  {
40  // Mock system under test to make protected methods accessible
41  $this->configurationItemRepository = $this->getAccessibleMock(
42  \TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository::class,
43  ['dummy']
44  );
45 
46  $this->injectedObjectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
47  $this->configurationItemRepository->_set(
48  'objectManager',
49  $this->injectedObjectManagerMock
50  );
51  }
52 
57  {
58  $flatConfigurationItemArray = [
59  'item1' => [
60  'cat' => 'basic',
61  'subcat_name' => 'enable',
62  'subcat' => 'a/enable/10z',
63  'type' => 'string',
64  'label' => 'Item 1: This is the first configuration item',
65  'name' =>'item1',
66  'value' => 'one',
67  'default_value' => 'one',
68  'subcat_label' => 'Enable features',
69  ],
70  'integerValue' => [
71  'cat' => 'basic',
72  'subcat_name' => 'enable',
73  'subcat' => 'a/enable/20z',
74  'type' => 'int+',
75  'label' => 'Integer Value: Please insert a positive integer value',
76  'name' =>'integerValue',
77  'value' => '1',
78  'default_value' => '1',
79  'subcat_label' => 'Enable features',
80  ],
81  'enableJquery' => [
82  'cat' => 'advanced',
83  'subcat_name' => 'file',
84  'subcat' => 'c/file/10z',
85  'type' => 'boolean',
86  'label' => 'enableJquery: Insert jQuery plugin',
87  'name' =>'enableJquery',
88  'value' => '1',
89  'default_value' => '1',
90  'subcat_label' => 'Files',
91  ],
92  ];
93 
95  \TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository::class,
96  ['mergeWithExistingConfiguration', 'translate']
97  );
99  'objectManager',
100  $this->injectedObjectManagerMock
101  );
102  $configurationUtilityMock = $this->createMock(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
103  $configurationUtilityMock
104  ->expects($this->once())
105  ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
106  ->will($this->returnValue($flatConfigurationItemArray));
107  $this->injectedObjectManagerMock
108  ->expects($this->any())
109  ->method('get')
110  ->will($this->returnValue($configurationUtilityMock));
112  ->expects($this->any())
113  ->method('mergeWithExistingConfiguration')
114  ->will($this->returnValue($flatConfigurationItemArray));
115 
116  $expectedArray = [
117  'basic' => [
118  'enable' => [
119  'item1' => [
120  'cat' => 'basic',
121  'subcat_name' => 'enable',
122  'subcat' => 'a/enable/10z',
123  'type' => 'string',
124  'label' => 'Item 1: This is the first configuration item',
125  'name' =>'item1',
126  'value' => 'one',
127  'default_value' => 'one',
128  'subcat_label' => 'Enable features',
129  'labels' => [
130  0 => 'Item 1',
131  1 => 'This is the first configuration item'
132  ]
133  ],
134  'integerValue' => [
135  'cat' => 'basic',
136  'subcat_name' => 'enable',
137  'subcat' => 'a/enable/20z',
138  'type' => 'int+',
139  'label' => 'Integer Value: Please insert a positive integer value',
140  'name' =>'integerValue',
141  'value' => '1',
142  'default_value' => '1',
143  'subcat_label' => 'Enable features',
144  'labels' => [
145  0 => 'Integer Value',
146  1 => 'Please insert a positive integer value'
147  ]
148  ]
149  ]
150  ],
151  'advanced' => [
152  'file' => [
153  'enableJquery' => [
154  'cat' => 'advanced',
155  'subcat_name' => 'file',
156  'subcat' => 'c/file/10z',
157  'type' => 'boolean',
158  'label' => 'enableJquery: Insert jQuery plugin',
159  'name' =>'enableJquery',
160  'value' => '1',
161  'default_value' => '1',
162  'subcat_label' => 'Files',
163  'labels' => [
164  0 => 'enableJquery',
165  1 => 'Insert jQuery plugin'
166  ]
167  ],
168  ]
169  ]
170  ];
171 
172  $this->assertSame(
173  $expectedArray,
174  $configurationItemRepository->_call('getConfigurationArrayFromExtensionKey', $this->getUniqueId('some_extension'))
175  );
176  }
177 
183  {
184  $configuration = [
185  '__meta__' => 'metaInformation',
186  'test123' => 'test123'
187  ];
188  $this->configurationItemRepository->_callRef('addMetaInformation', $configuration);
189  $this->assertEquals(['test123' => 'test123'], $configuration);
190  }
191 
197  {
198  $configuration = [
199  '__meta__' => 'metaInformation',
200  'test123' => 'test123'
201  ];
202  $meta = $this->configurationItemRepository->_callRef('addMetaInformation', $configuration);
203  $this->assertEquals('metaInformation', $meta);
204  }
205 
210  {
211  return [
212  [
213  [
214  'cat' => 'basic',
215  'subcat_name' => 'enable',
216  'subcat' => 'a/enable/z',
217  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
218  'label' => 'Frontend configuration check',
219  'name' => 'checkConfigurationFE',
220  'value' => 0,
221  'default_value' => 0,
222  'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend'
223  ]
224  ],
225  [
226  [
227  'cat' => 'basic',
228  'subcat_name' => 'enable',
229  'subcat' => 'a/enable/z',
230  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend]',
231  'label' => 'Backend configuration check',
232  'name' => 'checkConfigurationBE',
233  'value' => 0,
234  'default_value' => 0,
235  'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend'
236  ]
237  ],
238  [
239  [
240  'cat' => 'basic',
241  'subcat_name' => 'enable',
242  'subcat' => 'a/enable/z',
243  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]',
244  '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).',
245  'name' => 'FE.saltedPWHashingMethod',
246  'value' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt::class,
247  'default_value' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt::class,
248  'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE'
249  ]
250  ]
251  ];
252  }
253 
261  {
262  $configurationOptionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeUser', $configurationOption);
263  $this->assertEquals('user', $configurationOptionModified['type']);
264  $this->assertEquals($configurationOption['comparisonGeneric'], $configurationOptionModified['generic']);
265  }
266 
272  {
273  $option = [
274  'cat' => 'basic',
275  'subcat_name' => 'enable',
276  'subcat' => 'a/enable/100z',
277  '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.)]',
278  'label' => 'Default configuration settings',
279  'name' => 'defaultConfiguration',
280  'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
281  'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
282  'genericComparisonValue' => [
283  '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.)',
284  '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.)',
285  'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)'
286  ],
287  'typeComparisonValue' => 'options'
288  ];
289  $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
290  $this->assertArrayHasKey('generic', $optionModified);
291  $this->assertArrayHasKey('type', $optionModified);
292  $this->assertArrayHasKey('label', $optionModified);
293  $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
294  $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
295  }
296 
302  {
303  $option = [
304  'cat' => 'basic',
305  'subcat_name' => 'enable',
306  'subcat' => 'a/enable/100z',
307  '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]',
308  'label' => 'Default configuration settings',
309  'name' => 'defaultConfiguration',
310  'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
311  'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
312  'genericComparisonValue' => [
313  'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'MINIMAL',
314  'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'TYPICAL',
315  'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'DEMO'
316  ],
317  'typeComparisonValue' => 'options'
318  ];
319  $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
320  $this->assertArrayHasKey('generic', $optionModified);
321  $this->assertArrayHasKey('type', $optionModified);
322  $this->assertArrayHasKey('label', $optionModified);
323  $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
324  $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
325  }
326 
332  {
333  $exception = $this->getMockBuilder('RuntimeException')->getMock();
334  $configurationManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class)->getMock();
335  $configurationManagerMock
336  ->expects($this->once())
337  ->method('getConfigurationValueByPath')
338  ->will($this->throwException($exception));
339  $this->injectedObjectManagerMock
340  ->expects($this->any())
341  ->method('get')
342  ->will($this->returnValue($configurationManagerMock));
343 
344  $this->configurationItemRepository->_call(
345  'mergeWithExistingConfiguration',
346  [],
347  $this->getUniqueId('not_existing_extension')
348  );
349  }
350 
356  {
357  $exception = $this->getMockBuilder('RuntimeException')->getMock();
358  $configurationManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class)->getMock();
359  $configurationManagerMock
360  ->expects($this->once())
361  ->method('getConfigurationValueByPath')
362  ->will($this->throwException($exception));
363  $this->injectedObjectManagerMock
364  ->expects($this->any())
365  ->method('get')
366  ->will($this->returnValue($configurationManagerMock));
367  $defaultConfiguration = [
368  'foo' => 'bar'
369  ];
370  $configuration = $this->configurationItemRepository->_call(
371  'mergeWithExistingConfiguration',
372  $defaultConfiguration,
373  $this->getUniqueId('not_existing_extension')
374  );
375  $this->assertEquals($defaultConfiguration, $configuration);
376  }
377 
383  {
384  $localConfiguration = serialize([
385  'FE.' => [
386  'enabled' => '1',
387  'saltedPWHashingMethod' => \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface_sha1::class
388  ],
389  'CLI.' => [
390  'enabled' => '0'
391  ]
392  ]);
393 
394  $configurationManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class)->getMock();
395  $configurationManagerMock
396  ->expects($this->once())
397  ->method('getConfigurationValueByPath')
398  ->with('EXT/extConf/testextensionkey')
399  ->will($this->returnValue($localConfiguration));
400 
401  $this->injectedObjectManagerMock
402  ->expects($this->any())
403  ->method('get')
404  ->will($this->returnValue($configurationManagerMock));
405 
406  $defaultConfiguration = [
407  'FE.enabled' => [
408  'value' => '0'
409  ],
410  'FE.saltedPWHashingMethod' => [
411  'value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class
412  ],
413  'BE.enabled' => [
414  'value' => '1'
415  ],
416  'BE.saltedPWHashingMethod' => [
417  'value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class
418  ]
419  ];
420 
421  $expectedResult = [
422  'FE.enabled' => [
423  'value' => '1'
424  ],
425  'FE.saltedPWHashingMethod' => [
426  'value' => \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface_sha1::class
427  ],
428  'BE.enabled' => [
429  'value' => '1'
430  ],
431  'BE.saltedPWHashingMethod' => [
432  'value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class
433  ],
434  'CLI.enabled' => [
435  'value' => '0'
436  ]
437  ];
438 
439  $actualResult = $this->configurationItemRepository->_call(
440  'mergeWithExistingConfiguration',
441  $defaultConfiguration,
442  'testextensionkey'
443  );
444 
445  $this->assertEquals($expectedResult, $actualResult);
446  }
447 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)