TYPO3 CMS  TYPO3_7-6
SilentConfigurationUpgradeServiceTest.php
Go to the documentation of this file.
1 <?php
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 
21 
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 [
51  ['', 'rsa', true, false],
52  ['normal', 'rsa', true, true],
53  ['rsa', 'normal', false, true],
54  ];
55  }
56 
65  public function configureBackendLoginSecurity($current, $setting, $isPackageActive, $hasLocalConfig)
66  {
68  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
69  SilentConfigurationUpgradeService::class,
70  ['dummy'],
71  [],
72  '',
73  false
74  );
75 
77  $packageManager = $this->getMock(PackageManager::class, [], [], '', false);
78  $packageManager->expects($this->any())
79  ->method('isPackageActive')
80  ->will($this->returnValue($isPackageActive));
82 
83  $currentLocalConfiguration = [
84  ['BE/loginSecurityLevel', $current]
85  ];
86  $closure = function () {
87  throw new \RuntimeException('Path does not exist in array', 1341397869);
88  };
89 
91  [
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  ['dummy'],
125  [],
126  '',
127  false
128  );
129 
130  $obsoleteLocalConfigurationSettings = [
131  'SYS/form_enctype',
132  ];
133 
134  $currentLocalConfiguration = [
135  [$obsoleteLocalConfigurationSettings, true]
136  ];
138  [
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  ['dummy'],
163  [],
164  '',
165  false
166  );
167 
168  $obsoleteLocalConfigurationSettings = [
169  'SYS/form_enctype',
170  ];
171 
172  $currentLocalConfiguration = [
173  [$obsoleteLocalConfigurationSettings, false]
174  ];
176  [
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  ['dummy'],
199  [],
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 = [];
205  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
206 
207  $closure = function () {
208  throw new \RuntimeException('Path does not exist in array', 1341397869);
209  };
210 
212  [
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  ['dummy'],
244  [],
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 = [];
250  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
251 
252  $currentLocalConfiguration = [
253  ['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  [
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  ['dummy'],
289  [],
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 = [];
295  $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
296 
297  $currentLocalConfiguration = [
298  ['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  [
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  ['dummy'],
334  [],
335  '',
336  false
337  );
338 
339  $closure = function () {
340  throw new \RuntimeException('Path does not exist in array', 1341397869);
341  };
342 
344  [
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  ['dummy'],
369  [],
370  '',
371  false
372  );
373 
374  $currentLocalConfiguration = [
375  ['HTTP/proxy_auth_scheme', 'digest']
376  ];
377 
379  [
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  ['dummy'],
404  [],
405  '',
406  false
407  );
408 
409  $currentLocalConfiguration = [
410  ['HTTP/proxy_auth_scheme', 'basic']
411  ];
412 
414  [
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(['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  ['dummy'],
442  [],
443  '',
444  false
445  );
446 
447  $currentLocalConfiguration = [
448  ['SYS/encryptionKey', 'EnCrYpTiOnKeY']
449  ];
450 
452  [
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  ['dummy'],
477  [],
478  '',
479  false
480  );
481 
482  $closure = function () {
483  throw new \RuntimeException('Path does not exist in array', 1341397869);
484  };
485 
487  [
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 [
514  ['http://proxy:3128/', 'proxy', '3128'],
515  ['http://proxy:3128', 'proxy', '3128'],
516  ['proxy:3128', 'proxy', '3128'],
517  ['https://proxy:3128/', 'proxy', '3128'],
518  ];
519  }
520 
528  public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort)
529  {
531  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
532  SilentConfigurationUpgradeService::class,
533  ['dummy'],
534  [],
535  '',
536  false
537  );
538 
539  $currentLocalConfiguration = [
540  ['SYS/curlProxyServer', $curlProxyServer],
541  ['HTTP/proxy_host', ''],
542  ['SYS/curlProxyUserPass', ''],
543  ['HTTP/proxy_user', ''],
544  ['SYS/curlUse', false]
545  ];
547  [
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  ['HTTP/proxy_host', $proxyHost],
560  ['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  ['dummy'],
579  [],
580  '',
581  false
582  );
583 
584  $currentLocalConfiguration = [
585  ['SYS/curlProxyServer', 'http://proxyOld:3128/'],
586  ['SYS/curlProxyUserPass', 'userOld:passOld'],
587  ['HTTP/proxy_host', 'proxyNew'],
588  ['HTTP/proxy_port', '3128'],
589  ['HTTP/proxy_user', 'userNew'],
590  ['HTTP/proxy_pass', 'passNew'],
591  ['SYS/curlUse', false]
592  ];
594  [
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  ['dummy'],
620  [],
621  '',
622  false
623  );
624 
625  $currentLocalConfiguration = [
626  ['SYS/curlProxyServer', ''],
627  ['SYS/curlProxyUserPass', ''],
628  ['HTTP/proxy_host', 'proxyNew'],
629  ['HTTP/proxy_user', 'userNew'],
630  ['SYS/curlUse', true]
631  ];
633  [
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  ['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  ['dummy'],
664  [],
665  '',
666  false
667  );
668 
669  $currentLocalConfiguration = [
670  ['GFX/image_processing', 0],
671  ['GFX/im', 1],
672  ['GFX/gdlib', 0]
673  ];
675  [
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  [['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  ['dummy'],
708  [],
709  '',
710  false
711  );
712 
713  $currentLocalConfiguration = [
714  ['GFX/image_processing', 0],
715  ['GFX/im', 0],
716  ['GFX/gdlib', 1]
717  ];
719  [
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  [['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  ['dummy'],
752  [],
753  '',
754  false
755  );
756 
757  $currentLocalConfiguration = [
758  ['GFX/image_processing', 1],
759  ['GFX/im', 1],
760  ['GFX/gdlib', 1]
761  ];
763  [
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  ['dummy'],
791  [],
792  '',
793  false
794  );
795 
796  $currentDefaultConfiguration = [
797  ['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  [
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  [['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  ['dummy'],
847  [],
848  '',
849  false
850  );
851 
852  $currentLocalConfiguration = [
853  ['GFX/im', 0],
854  ['GFX/im_path', ''],
855  ['GFX/im_path_lzw', ''],
856  ['GFX/imagefile_ext', 'gif,jpg,png'],
857  ['GFX/thumbnails', 0]
858  ];
860  [
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  [['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  ['dummy'],
893  [],
894  '',
895  false
896  );
897 
898  $currentLocalConfiguration = [
899  ['GFX/im', 1],
900  ['GFX/im_path', ''],
901  ['GFX/im_path_lzw', ''],
902  ['GFX/imagefile_ext', 'gif,jpg,jpeg,png'],
903  ['GFX/thumbnails', 0]
904  ];
906  [
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  ['dummy'],
934  [],
935  '',
936  false
937  );
938 
939  $currentLocalConfiguration = [
940  ['GFX/im_version_5', 'gm'],
941  ['GFX/im_mask_temp_ext_gif', 0],
942  ['GFX/im_v5effects', 0]
943  ];
945  [
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  [['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  ['dummy'],
979  [],
980  '',
981  false
982  );
983 
984  $currentLocalConfiguration = [
985  ['GFX/im_version_5', ''],
986  ['GFX/im_mask_temp_ext_gif', 0],
987  ['GFX/im_v5effects', 0]
988  ];
990  [
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 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static setPackageManager(PackageManager $packageManager)