TYPO3  7.6
SilentConfigurationUpgradeServiceTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Service;
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 
19 use TYPO3\CMS\Install\Controller\Exception\RedirectException;
21 
25 class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
26 {
31 
35  protected function createConfigurationManagerWithMockedMethods(array $methods)
36  {
37  $this->configurationManager = $this->getMock(
38  ConfigurationManager::class,
39  $methods
40  );
41  }
42 
49  {
50  return array(
51  array('', 'rsa', true, false),
52  array('normal', 'rsa', true, true),
53  array('rsa', 'normal', false, true),
54  );
55  }
56 
65  public function configureBackendLoginSecurity($current, $setting, $isPackageActive, $hasLocalConfig)
66  {
68  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
69  SilentConfigurationUpgradeService::class,
70  array('dummy'),
71  array(),
72  '',
73  false
74  );
75 
77  $packageManager = $this->getMock(PackageManager::class, array(), array(), '', false);
78  $packageManager->expects($this->any())
79  ->method('isPackageActive')
80  ->will($this->returnValue($isPackageActive));
82 
83  $currentLocalConfiguration = array(
84  array('BE/loginSecurityLevel', $current)
85  );
86  $closure = function () {
87  throw new \RuntimeException('Path does not exist in array', 1341397869);
88  };
89 
91  array(
92  'getLocalConfigurationValueByPath',
93  'setLocalConfigurationValueByPath',
94  )
95  );
96  if ($hasLocalConfig) {
97  $this->configurationManager->expects($this->once())
98  ->method('getLocalConfigurationValueByPath')
99  ->will($this->returnValueMap($currentLocalConfiguration));
100  } else {
101  $this->configurationManager->expects($this->once())
102  ->method('getLocalConfigurationValueByPath')
103  ->will($this->returnCallback($closure));
104  }
105  $this->configurationManager->expects($this->once())
106  ->method('setLocalConfigurationValueByPath')
107  ->with($this->equalTo('BE/loginSecurityLevel'), $this->equalTo($setting));
108 
109  $this->setExpectedException(RedirectException::class);
110 
111  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
112 
113  $silentConfigurationUpgradeServiceInstance->_call('configureBackendLoginSecurity');
114  }
115 
119  public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings()
120  {
122  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
123  SilentConfigurationUpgradeService::class,
124  array('dummy'),
125  array(),
126  '',
127  false
128  );
129 
130  $obsoleteLocalConfigurationSettings = array(
131  'SYS/form_enctype',
132  );
133 
134  $currentLocalConfiguration = array(
135  array($obsoleteLocalConfigurationSettings, true)
136  );
138  array(
139  'removeLocalConfigurationKeysByPath',
140  )
141  );
142  $this->configurationManager->expects($this->exactly(1))
143  ->method('removeLocalConfigurationKeysByPath')
144  ->will($this->returnValueMap($currentLocalConfiguration));
145 
146  $this->setExpectedException(RedirectException::class);
147 
148  $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
149  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
150 
151  $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
152  }
153 
157  public function doNotRemoveObsoleteLocalConfigurationSettingsIfThereAreNoOldSettings()
158  {
160  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
161  SilentConfigurationUpgradeService::class,
162  array('dummy'),
163  array(),
164  '',
165  false
166  );
167 
168  $obsoleteLocalConfigurationSettings = array(
169  'SYS/form_enctype',
170  );
171 
172  $currentLocalConfiguration = array(
173  array($obsoleteLocalConfigurationSettings, false)
174  );
176  array(
177  'removeLocalConfigurationKeysByPath',
178  )
179  );
180  $this->configurationManager->expects($this->exactly(1))
181  ->method('removeLocalConfigurationKeysByPath')
182  ->will($this->returnValueMap($currentLocalConfiguration));
183 
184  $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
185  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
186 
187  $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
188  }
189 
193  public function configureSaltedPasswordsWithDefaultConfiguration()
194  {
196  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
197  SilentConfigurationUpgradeService::class,
198  array('dummy'),
199  array(),
200  '',
201  false
202  );
203  $config = 'a:2:{s:3:"BE.";a:3:{s:11:"forceSalted";i:0;s:15:"onlyAuthService";i:0;s:12:"updatePasswd";i:1;}s:3:"FE.";a:4:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;s:15:"onlyAuthService";i:0;s:12:"updatePasswd";i:1;}}';
204  $defaultConfiguration = array();
205  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
206 
207  $closure = function () {
208  throw new \RuntimeException('Path does not exist in array', 1341397869);
209  };
210 
212  array(
213  'getDefaultConfiguration',
214  'getLocalConfigurationValueByPath',
215  'setLocalConfigurationValueByPath',
216  )
217  );
218  $this->configurationManager->expects($this->exactly(1))
219  ->method('getDefaultConfiguration')
220  ->will($this->returnValue($defaultConfiguration));
221  $this->configurationManager->expects($this->exactly(1))
222  ->method('getLocalConfigurationValueByPath')
223  ->will($this->returnCallback($closure));
224  $this->configurationManager->expects($this->once())
225  ->method('setLocalConfigurationValueByPath')
226  ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($config));
227 
228  $this->setExpectedException(RedirectException::class);
229 
230  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
231 
232  $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
233  }
234 
238  public function configureSaltedPasswordsWithExtensionConfigurationBeEnabled()
239  {
241  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
242  SilentConfigurationUpgradeService::class,
243  array('dummy'),
244  array(),
245  '',
246  false
247  );
248  $config = 'a:2:{s:3:"BE.";a:1:{s:21:"saltedPWHashingMethod";}s:3:"FE.";a:2:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;}}';
249  $defaultConfiguration = array();
250  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
251 
252  $currentLocalConfiguration = array(
253  array('EXT/extConf/saltedpasswords', 'a:2:{s:3:"BE.";a:1:{s:7:"enabled";i:1;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}')
254  );
255  $newConfig = 'a:2:{s:3:"BE.";a:0:{}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}';
257  array(
258  'getDefaultConfiguration',
259  'getLocalConfigurationValueByPath',
260  'setLocalConfigurationValueByPath',
261  )
262  );
263  $this->configurationManager->expects($this->exactly(1))
264  ->method('getDefaultConfiguration')
265  ->will($this->returnValue($defaultConfiguration));
266  $this->configurationManager->expects($this->exactly(1))
267  ->method('getLocalConfigurationValueByPath')
268  ->will($this->returnValueMap($currentLocalConfiguration));
269  $this->configurationManager->expects($this->once())
270  ->method('setLocalConfigurationValueByPath')
271  ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($newConfig));
272 
273  $this->setExpectedException(RedirectException::class);
274 
275  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
276 
277  $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
278  }
279 
283  public function configureSaltedPasswordsWithExtensionConfigurationBeNotEnabled()
284  {
286  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
287  SilentConfigurationUpgradeService::class,
288  array('dummy'),
289  array(),
290  '',
291  false
292  );
293  $config = 'a:2:{s:3:"BE.";a:1:{s:15:"onlyAuthService";i:0;}s:3:"FE.";a:2:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;}}';
294  $defaultConfiguration = array();
295  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
296 
297  $currentLocalConfiguration = array(
298  array('EXT/extConf/saltedpasswords', 'a:2:{s:3:"BE.";a:2:{s:7:"enabled";i:0;s:12:"updatePasswd";i:1;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}')
299  );
300  $newConfig = 'a:2:{s:3:"BE.";a:1:{s:15:"onlyAuthService";i:0;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}';
302  array(
303  'getDefaultConfiguration',
304  'getLocalConfigurationValueByPath',
305  'setLocalConfigurationValueByPath',
306  )
307  );
308  $this->configurationManager->expects($this->exactly(1))
309  ->method('getDefaultConfiguration')
310  ->will($this->returnValue($defaultConfiguration));
311  $this->configurationManager->expects($this->exactly(1))
312  ->method('getLocalConfigurationValueByPath')
313  ->will($this->returnValueMap($currentLocalConfiguration));
314  $this->configurationManager->expects($this->once())
315  ->method('setLocalConfigurationValueByPath')
316  ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($newConfig));
317 
318  $this->setExpectedException(RedirectException::class);
319 
320  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
321 
322  $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
323  }
324 
328  public function noProxyAuthSchemeSetInLocalConfiguration()
329  {
331  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
332  SilentConfigurationUpgradeService::class,
333  array('dummy'),
334  array(),
335  '',
336  false
337  );
338 
339  $closure = function () {
340  throw new \RuntimeException('Path does not exist in array', 1341397869);
341  };
342 
344  array(
345  'getLocalConfigurationValueByPath',
346  'removeLocalConfigurationKeysByPath',
347  )
348  );
349  $this->configurationManager->expects($this->exactly(1))
350  ->method('getLocalConfigurationValueByPath')
351  ->will($this->returnCallback($closure));
352  $this->configurationManager->expects($this->never())
353  ->method('removeLocalConfigurationKeysByPath');
354 
355  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
356 
357  $silentConfigurationUpgradeServiceInstance->_call('setProxyAuthScheme');
358  }
359 
363  public function proxyAuthSchemeIsDigest()
364  {
366  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
367  SilentConfigurationUpgradeService::class,
368  array('dummy'),
369  array(),
370  '',
371  false
372  );
373 
374  $currentLocalConfiguration = array(
375  array('HTTP/proxy_auth_scheme', 'digest')
376  );
377 
379  array(
380  'getLocalConfigurationValueByPath',
381  'removeLocalConfigurationKeysByPath',
382  )
383  );
384  $this->configurationManager->expects($this->exactly(1))
385  ->method('getLocalConfigurationValueByPath')
386  ->will($this->returnValueMap($currentLocalConfiguration));
387  $this->configurationManager->expects($this->never())
388  ->method('removeLocalConfigurationKeysByPath');
389 
390  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
391 
392  $silentConfigurationUpgradeServiceInstance->_call('setProxyAuthScheme');
393  }
394 
398  public function proxyAuthSchemeIsBasic()
399  {
401  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
402  SilentConfigurationUpgradeService::class,
403  array('dummy'),
404  array(),
405  '',
406  false
407  );
408 
409  $currentLocalConfiguration = array(
410  array('HTTP/proxy_auth_scheme', 'basic')
411  );
412 
414  array(
415  'getLocalConfigurationValueByPath',
416  'removeLocalConfigurationKeysByPath',
417  )
418  );
419  $this->configurationManager->expects($this->exactly(1))
420  ->method('getLocalConfigurationValueByPath')
421  ->will($this->returnValueMap($currentLocalConfiguration));
422  $this->configurationManager->expects($this->once())
423  ->method('removeLocalConfigurationKeysByPath')
424  ->with($this->equalTo(array('HTTP/proxy_auth_scheme')));
425 
426  $this->setExpectedException(RedirectException::class);
427 
428  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
429 
430  $silentConfigurationUpgradeServiceInstance->_call('setProxyAuthScheme');
431  }
432 
436  public function doNotGenerateEncryptionKeyIfExists()
437  {
439  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
440  SilentConfigurationUpgradeService::class,
441  array('dummy'),
442  array(),
443  '',
444  false
445  );
446 
447  $currentLocalConfiguration = array(
448  array('SYS/encryptionKey', 'EnCrYpTiOnKeY')
449  );
450 
452  array(
453  'getLocalConfigurationValueByPath',
454  'setLocalConfigurationValueByPath',
455  )
456  );
457  $this->configurationManager->expects($this->exactly(1))
458  ->method('getLocalConfigurationValueByPath')
459  ->will($this->returnValueMap($currentLocalConfiguration));
460  $this->configurationManager->expects($this->never())
461  ->method('setLocalConfigurationValueByPath');
462 
463  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
464 
465  $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
466  }
467 
471  public function generateEncryptionKeyIfNotExists()
472  {
474  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
475  SilentConfigurationUpgradeService::class,
476  array('dummy'),
477  array(),
478  '',
479  false
480  );
481 
482  $closure = function () {
483  throw new \RuntimeException('Path does not exist in array', 1341397869);
484  };
485 
487  array(
488  'getLocalConfigurationValueByPath',
489  'setLocalConfigurationValueByPath',
490  )
491  );
492  $this->configurationManager->expects($this->exactly(1))
493  ->method('getLocalConfigurationValueByPath')
494  ->will($this->returnCallback($closure));
495  $this->configurationManager->expects($this->once())
496  ->method('setLocalConfigurationValueByPath')
497  ->with($this->equalTo('SYS/encryptionKey'), $this->isType('string'));
498 
499  $this->setExpectedException(RedirectException::class);
500 
501  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
502 
503  $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
504  }
505 
512  {
513  return array(
514  array('http://proxy:3128/', 'proxy', '3128'),
515  array('http://proxy:3128', 'proxy', '3128'),
516  array('proxy:3128', 'proxy', '3128'),
517  array('https://proxy:3128/', 'proxy', '3128'),
518  );
519  }
520 
528  public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort)
529  {
531  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
532  SilentConfigurationUpgradeService::class,
533  array('dummy'),
534  array(),
535  '',
536  false
537  );
538 
539  $currentLocalConfiguration = array(
540  array('SYS/curlProxyServer', $curlProxyServer),
541  array('HTTP/proxy_host', ''),
542  array('SYS/curlProxyUserPass', ''),
543  array('HTTP/proxy_user', ''),
544  array('SYS/curlUse', false)
545  );
547  array(
548  'getLocalConfigurationValueByPath',
549  'setLocalConfigurationValueByPath',
550  'getConfigurationValueByPath'
551  )
552  );
553  $this->configurationManager->expects($this->exactly(5))
554  ->method('getLocalConfigurationValueByPath')
555  ->will($this->returnValueMap($currentLocalConfiguration));
556  $this->configurationManager->expects($this->exactly(2))
557  ->method('setLocalConfigurationValueByPath')
558  ->withConsecutive(
559  array('HTTP/proxy_host', $proxyHost),
560  array('HTTP/proxy_port', $proxyPort)
561  );
562 
563  $this->setExpectedException(RedirectException::class);
564 
565  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
566 
567  $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
568  }
569 
573  public function curlProxyServerDoesNotOverwriteHttpSettings()
574  {
576  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
577  SilentConfigurationUpgradeService::class,
578  array('dummy'),
579  array(),
580  '',
581  false
582  );
583 
584  $currentLocalConfiguration = array(
585  array('SYS/curlProxyServer', 'http://proxyOld:3128/'),
586  array('SYS/curlProxyUserPass', 'userOld:passOld'),
587  array('HTTP/proxy_host', 'proxyNew'),
588  array('HTTP/proxy_port', '3128'),
589  array('HTTP/proxy_user', 'userNew'),
590  array('HTTP/proxy_pass', 'passNew'),
591  array('SYS/curlUse', false)
592  );
594  array(
595  'getLocalConfigurationValueByPath',
596  'setLocalConfigurationValueByPath',
597  'getConfigurationValueByPath'
598  )
599  );
600  $this->configurationManager->expects($this->exactly(5))
601  ->method('getLocalConfigurationValueByPath')
602  ->will($this->returnValueMap($currentLocalConfiguration));
603  $this->configurationManager->expects($this->never())
604  ->method('setLocalConfigurationValueByPath');
605 
606  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
607 
608  $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
609  }
610 
614  public function curlAdapterUsedIfCurlUse()
615  {
617  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
618  SilentConfigurationUpgradeService::class,
619  array('dummy'),
620  array(),
621  '',
622  false
623  );
624 
625  $currentLocalConfiguration = array(
626  array('SYS/curlProxyServer', ''),
627  array('SYS/curlProxyUserPass', ''),
628  array('HTTP/proxy_host', 'proxyNew'),
629  array('HTTP/proxy_user', 'userNew'),
630  array('SYS/curlUse', true)
631  );
633  array(
634  'getLocalConfigurationValueByPath',
635  'getConfigurationValueByPath',
636  'setLocalConfigurationValueByPath',
637  )
638  );
639  $this->configurationManager->expects($this->exactly(5))
640  ->method('getLocalConfigurationValueByPath')
641  ->will($this->returnValueMap($currentLocalConfiguration));
642  $this->configurationManager->expects($this->once())
643  ->method('setLocalConfigurationValueByPath')
644  ->withConsecutive(
645  array('HTTP/adapter', 'curl')
646  );
647 
648  $this->setExpectedException(RedirectException::class);
649 
650  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
651 
652  $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
653  }
654 
658  public function disableImageMagickIfImageProcessingIsDisabled()
659  {
661  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
662  SilentConfigurationUpgradeService::class,
663  array('dummy'),
664  array(),
665  '',
666  false
667  );
668 
669  $currentLocalConfiguration = array(
670  array('GFX/image_processing', 0),
671  array('GFX/im', 1),
672  array('GFX/gdlib', 0)
673  );
675  array(
676  'getLocalConfigurationValueByPath',
677  'getDefaultConfigurationValueByPath',
678  'setLocalConfigurationValuesByPathValuePairs',
679  )
680  );
681  $this->configurationManager->expects($this->exactly(3))
682  ->method('getLocalConfigurationValueByPath')
683  ->will($this->returnValueMap($currentLocalConfiguration));
684  $this->configurationManager->expects($this->never())
685  ->method('getDefaultConfigurationValueByPath');
686  $this->configurationManager->expects($this->once())
687  ->method('setLocalConfigurationValuesByPathValuePairs')
688  ->withConsecutive(
689  array(array('GFX/im' => 0))
690  );
691 
692  $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
693 
694  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
695 
696  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickAndGdlibIfImageProcessingIsDisabled');
697  }
698 
702  public function disableGdlibIfImageProcessingIsDisabled()
703  {
705  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
706  SilentConfigurationUpgradeService::class,
707  array('dummy'),
708  array(),
709  '',
710  false
711  );
712 
713  $currentLocalConfiguration = array(
714  array('GFX/image_processing', 0),
715  array('GFX/im', 0),
716  array('GFX/gdlib', 1)
717  );
719  array(
720  'getLocalConfigurationValueByPath',
721  'getDefaultConfigurationValueByPath',
722  'setLocalConfigurationValuesByPathValuePairs',
723  )
724  );
725  $this->configurationManager->expects($this->exactly(3))
726  ->method('getLocalConfigurationValueByPath')
727  ->will($this->returnValueMap($currentLocalConfiguration));
728  $this->configurationManager->expects($this->never())
729  ->method('getDefaultConfigurationValueByPath');
730  $this->configurationManager->expects($this->once())
731  ->method('setLocalConfigurationValuesByPathValuePairs')
732  ->withConsecutive(
733  array(array('GFX/gdlib' => 0))
734  );
735 
736  $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
737 
738  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
739 
740  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickAndGdlibIfImageProcessingIsDisabled');
741  }
742 
746  public function doNotDisableImageMagickAndGdlibIfImageProcessingIsEnabled()
747  {
749  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
750  SilentConfigurationUpgradeService::class,
751  array('dummy'),
752  array(),
753  '',
754  false
755  );
756 
757  $currentLocalConfiguration = array(
758  array('GFX/image_processing', 1),
759  array('GFX/im', 1),
760  array('GFX/gdlib', 1)
761  );
763  array(
764  'getLocalConfigurationValueByPath',
765  'getDefaultConfigurationValueByPath',
766  'setLocalConfigurationValuesByPathValuePairs',
767  )
768  );
769  $this->configurationManager->expects($this->exactly(3))
770  ->method('getLocalConfigurationValueByPath')
771  ->will($this->returnValueMap($currentLocalConfiguration));
772  $this->configurationManager->expects($this->never())
773  ->method('getDefaultConfigurationValueByPath');
774  $this->configurationManager->expects($this->never())
775  ->method('setLocalConfigurationValuesByPathValuePairs');
776 
777  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
778 
779  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickAndGdlibIfImageProcessingIsDisabled');
780  }
781 
785  public function disableImageMagickIfDefaultImageProcessingIsDisabled()
786  {
788  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
789  SilentConfigurationUpgradeService::class,
790  array('dummy'),
791  array(),
792  '',
793  false
794  );
795 
796  $currentDefaultConfiguration = array(
797  array('GFX/image_processing', 0),
798  );
799  $closure = function ($param) {
800  switch ($param) {
801  case 'GFX/im':
802  return '1';
803  break;
804  case 'GFX/gdlib':
805  return '0';
806  break;
807  default:
808  throw new \RuntimeException('Path does not exist in array', 1341397869);
809  }
810  };
811 
813  array(
814  'getLocalConfigurationValueByPath',
815  'getDefaultConfigurationValueByPath',
816  'setLocalConfigurationValuesByPathValuePairs',
817  )
818  );
819  $this->configurationManager->expects($this->exactly(3))
820  ->method('getLocalConfigurationValueByPath')
821  ->will($this->returnCallback($closure));
822  $this->configurationManager->expects($this->exactly(1))
823  ->method('getDefaultConfigurationValueByPath')
824  ->will($this->returnValueMap($currentDefaultConfiguration));
825  $this->configurationManager->expects($this->once())
826  ->method('setLocalConfigurationValuesByPathValuePairs')
827  ->withConsecutive(
828  array(array('GFX/im' => 0))
829  );
830 
831  $this->setExpectedException(RedirectException::class);
832 
833  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
834 
835  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickAndGdlibIfImageProcessingIsDisabled');
836  }
837 
841  public function disableImageMagickDetailSettingsIfImageMagickIsDisabled()
842  {
844  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
845  SilentConfigurationUpgradeService::class,
846  array('dummy'),
847  array(),
848  '',
849  false
850  );
851 
852  $currentLocalConfiguration = array(
853  array('GFX/im', 0),
854  array('GFX/im_path', ''),
855  array('GFX/im_path_lzw', ''),
856  array('GFX/imagefile_ext', 'gif,jpg,png'),
857  array('GFX/thumbnails', 0)
858  );
860  array(
861  'getLocalConfigurationValueByPath',
862  'getDefaultConfigurationValueByPath',
863  'setLocalConfigurationValuesByPathValuePairs',
864  )
865  );
866  $this->configurationManager->expects($this->exactly(5))
867  ->method('getLocalConfigurationValueByPath')
868  ->will($this->returnValueMap($currentLocalConfiguration));
869  $this->configurationManager->expects($this->never())
870  ->method('getDefaultConfigurationValueByPath');
871  $this->configurationManager->expects($this->once())
872  ->method('setLocalConfigurationValuesByPathValuePairs')
873  ->withConsecutive(
874  array(array('GFX/imagefile_ext' => 'gif,jpg,jpeg,png'))
875  );
876 
877  $this->setExpectedException(RedirectException::class);
878 
879  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
880 
881  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
882  }
883 
887  public function doNotDisableImageMagickDetailSettingsIfImageMagickIsEnabled()
888  {
890  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
891  SilentConfigurationUpgradeService::class,
892  array('dummy'),
893  array(),
894  '',
895  false
896  );
897 
898  $currentLocalConfiguration = array(
899  array('GFX/im', 1),
900  array('GFX/im_path', ''),
901  array('GFX/im_path_lzw', ''),
902  array('GFX/imagefile_ext', 'gif,jpg,jpeg,png'),
903  array('GFX/thumbnails', 0)
904  );
906  array(
907  'getLocalConfigurationValueByPath',
908  'getDefaultConfigurationValueByPath',
909  'setLocalConfigurationValuesByPathValuePairs',
910  )
911  );
912  $this->configurationManager->expects($this->exactly(5))
913  ->method('getLocalConfigurationValueByPath')
914  ->will($this->returnValueMap($currentLocalConfiguration));
915  $this->configurationManager->expects($this->never())
916  ->method('getDefaultConfigurationValueByPath');
917  $this->configurationManager->expects($this->never())
918  ->method('setLocalConfigurationValuesByPathValuePairs');
919 
920  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
921 
922  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
923  }
924 
928  public function setImageMagickDetailSettings()
929  {
931  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
932  SilentConfigurationUpgradeService::class,
933  array('dummy'),
934  array(),
935  '',
936  false
937  );
938 
939  $currentLocalConfiguration = array(
940  array('GFX/im_version_5', 'gm'),
941  array('GFX/im_mask_temp_ext_gif', 0),
942  array('GFX/im_v5effects', 0)
943  );
945  array(
946  'getLocalConfigurationValueByPath',
947  'getDefaultConfigurationValueByPath',
948  'setLocalConfigurationValuesByPathValuePairs',
949  )
950  );
951  $this->configurationManager->expects($this->exactly(3))
952  ->method('getLocalConfigurationValueByPath')
953  ->will($this->returnValueMap($currentLocalConfiguration));
954  $this->configurationManager->expects($this->never())
955  ->method('getDefaultConfigurationValueByPath');
956  $this->configurationManager->expects($this->once())
957  ->method('setLocalConfigurationValuesByPathValuePairs')
958  ->withConsecutive(
959  array(array('GFX/im_mask_temp_ext_gif' => 1,
960  'GFX/im_v5effects' => -1))
961  );
962 
963  $this->setExpectedException(RedirectException::class);
964 
965  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
966 
967  $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
968  }
969 
973  public function doNotSetImageMagickDetailSettings()
974  {
976  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
977  SilentConfigurationUpgradeService::class,
978  array('dummy'),
979  array(),
980  '',
981  false
982  );
983 
984  $currentLocalConfiguration = array(
985  array('GFX/im_version_5', ''),
986  array('GFX/im_mask_temp_ext_gif', 0),
987  array('GFX/im_v5effects', 0)
988  );
990  array(
991  'getLocalConfigurationValueByPath',
992  'getDefaultConfigurationValueByPath',
993  'setLocalConfigurationValuesByPathValuePairs',
994  )
995  );
996  $this->configurationManager->expects($this->exactly(3))
997  ->method('getLocalConfigurationValueByPath')
998  ->will($this->returnValueMap($currentLocalConfiguration));
999  $this->configurationManager->expects($this->never())
1000  ->method('getDefaultConfigurationValueByPath');
1001  $this->configurationManager->expects($this->never())
1002  ->method('setLocalConfigurationValuesByPathValuePairs');
1003 
1004  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
1005 
1006  $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
1007  }
1008 }