fcbca61fd474c689c459b61925076706b5ad30ec
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Service / SilentConfigurationUpgradeServiceTest.php
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
17 use TYPO3\CMS\Install\Controller\Exception\RedirectException;
18
19 /**
20 * Test case
21 */
22 class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject
26 */
27 protected $configurationManager;
28
29 /**
30 * @param array $methods
31 */
32 protected function createConfigurationManagerWithMockedMethods(array $methods) {
33 $this->configurationManager = $this->getMock(
34 \TYPO3\CMS\Core\Configuration\ConfigurationManager::class,
35 $methods
36 );
37 }
38
39 /**
40 * Dataprovider for transferDeprecatedCurlSettings
41 *
42 * @return array
43 */
44 public function curlProxySettingsToHttpSettingsMapping() {
45 return array(
46 array('http://proxy:3128/', 'proxy', '3128'),
47 array('http://proxy:3128', 'proxy', '3128'),
48 array('proxy:3128', 'proxy', '3128'),
49 array('https://proxy:3128/', 'proxy', '3128'),
50 );
51 }
52
53 /**
54 * @test
55 * @dataProvider curlProxySettingsToHttpSettingsMapping
56 */
57 public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort) {
58 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
59 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
60 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
61 array('dummy'),
62 array(),
63 '',
64 FALSE
65 );
66
67 $currentLocalConfiguration = array(
68 array('SYS/curlProxyServer', $curlProxyServer),
69 array('HTTP/proxy_host', ''),
70 array('SYS/curlProxyUserPass', ''),
71 array('HTTP/proxy_user', ''),
72 array('SYS/curlUse', FALSE)
73 );
74 $this->createConfigurationManagerWithMockedMethods(
75 array(
76 'getLocalConfigurationValueByPath',
77 'setLocalConfigurationValueByPath',
78 )
79 );
80 $this->configurationManager->expects($this->exactly(5))
81 ->method('getLocalConfigurationValueByPath')
82 ->will($this->returnValueMap($currentLocalConfiguration));
83 $this->configurationManager->expects($this->exactly(2))
84 ->method('setLocalConfigurationValueByPath')
85 ->withConsecutive(
86 array('HTTP/proxy_host', $proxyHost),
87 array('HTTP/proxy_port', $proxyPort)
88 );
89
90 $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
91
92 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
93
94 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
95 }
96
97 /**
98 * @test
99 */
100 public function curlProxyServerDoesNotOverwriteHttpSettings() {
101 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
102 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
103 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
104 array('dummy'),
105 array(),
106 '',
107 FALSE
108 );
109
110 $currentLocalConfiguration = array(
111 array('SYS/curlProxyServer', 'http://proxyOld:3128/'),
112 array('SYS/curlProxyUserPass', 'userOld:passOld'),
113 array('HTTP/proxy_host', 'proxyNew'),
114 array('HTTP/proxy_port', '3128'),
115 array('HTTP/proxy_user', 'userNew'),
116 array('HTTP/proxy_pass', 'passNew'),
117 array('SYS/curlUse', FALSE)
118 );
119 $this->createConfigurationManagerWithMockedMethods(
120 array(
121 'getLocalConfigurationValueByPath',
122 'setLocalConfigurationValueByPath',
123 )
124 );
125 $this->configurationManager->expects($this->exactly(5))
126 ->method('getLocalConfigurationValueByPath')
127 ->will($this->returnValueMap($currentLocalConfiguration));
128 $this->configurationManager->expects($this->never())
129 ->method('setLocalConfigurationValueByPath');
130
131 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
132
133 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
134 }
135
136 /**
137 * @test
138 */
139 public function curlAdapterUsedIfCurlUse() {
140 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
141 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
142 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
143 array('dummy'),
144 array(),
145 '',
146 FALSE
147 );
148
149 $currentLocalConfiguration = array(
150 array('SYS/curlProxyServer', ''),
151 array('SYS/curlProxyUserPass', ''),
152 array('HTTP/proxy_host', 'proxyNew'),
153 array('HTTP/proxy_user', 'userNew'),
154 array('SYS/curlUse', TRUE)
155 );
156 $this->createConfigurationManagerWithMockedMethods(
157 array(
158 'getLocalConfigurationValueByPath',
159 'setLocalConfigurationValueByPath',
160 )
161 );
162 $this->configurationManager->expects($this->exactly(5))
163 ->method('getLocalConfigurationValueByPath')
164 ->will($this->returnValueMap($currentLocalConfiguration));
165 $this->configurationManager->expects($this->once())
166 ->method('setLocalConfigurationValueByPath')
167 ->withConsecutive(
168 array('HTTP/adapter', 'curl')
169 );
170
171 $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
172
173 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
174
175 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
176 }
177
178 }