Skip to content

Commit 6248ef5

Browse files
authored
ENGCOM-4653: Remove direct $_SERVER variable use #20968
2 parents 36a733b + d8faae3 commit 6248ef5

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

app/code/Magento/Store/Model/Store.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@ protected function _updatePathUseRewrites($url)
716716
if ($this->_isCustomEntryPoint()) {
717717
$indexFileName = 'index.php';
718718
} else {
719-
$indexFileName = basename($_SERVER['SCRIPT_FILENAME']);
719+
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME');
720+
$indexFileName = basename($scriptFilename);
720721
}
721722
$url .= $indexFileName . '/';
722723
}

app/code/Magento/Store/Test/Unit/Model/StoreTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testGetWebsite()
160160
/** @var \Magento\Store\Model\Store $model */
161161
$model = $this->objectManagerHelper->getObject(
162162
\Magento\Store\Model\Store::class,
163-
['websiteRepository' => $websiteRepository,]
163+
['websiteRepository' => $websiteRepository]
164164
);
165165
$model->setWebsiteId($websiteId);
166166

@@ -181,7 +181,7 @@ public function testGetWebsiteIfWebsiteIsNotExist()
181181
/** @var \Magento\Store\Model\Store $model */
182182
$model = $this->objectManagerHelper->getObject(
183183
\Magento\Store\Model\Store::class,
184-
['websiteRepository' => $websiteRepository,]
184+
['websiteRepository' => $websiteRepository]
185185
);
186186
$model->setWebsiteId(null);
187187

@@ -207,7 +207,7 @@ public function testGetGroup()
207207
/** @var \Magento\Store\Model\Store $model */
208208
$model = $this->objectManagerHelper->getObject(
209209
\Magento\Store\Model\Store::class,
210-
['groupRepository' => $groupRepository,]
210+
['groupRepository' => $groupRepository]
211211
);
212212
$model->setGroupId($groupId);
213213

@@ -228,7 +228,7 @@ public function testGetGroupIfGroupIsNotExist()
228228
/** @var \Magento\Store\Model\Store $model */
229229
$model = $this->objectManagerHelper->getObject(
230230
\Magento\Store\Model\Store::class,
231-
['groupRepository' => $groupRepository,]
231+
['groupRepository' => $groupRepository]
232232
);
233233
$model->setGroupId(null);
234234

@@ -377,30 +377,31 @@ public function testGetBaseUrlEntryPoint()
377377
$configMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
378378
$configMock->expects($this->atLeastOnce())
379379
->method('getValue')
380-
->will($this->returnCallback(
381-
function ($path, $scope, $scopeCode) use ($expectedPath) {
382-
return $expectedPath == $path ? 'http://domain.com/' . $path . '/' : null;
383-
}
384-
));
380+
->willReturnCallback(function ($path, $scope, $scopeCode) use ($expectedPath) {
381+
return $expectedPath == $path ? 'http://domain.com/' . $path . '/' : null;
382+
});
383+
$this->requestMock->expects($this->once())
384+
->method('getServer')
385+
->with('SCRIPT_FILENAME')
386+
->willReturn('test_script.php');
387+
385388
/** @var \Magento\Store\Model\Store $model */
386389
$model = $this->objectManagerHelper->getObject(
387390
\Magento\Store\Model\Store::class,
388391
[
389392
'config' => $configMock,
390393
'isCustomEntryPoint' => false,
394+
'request' => $this->requestMock
391395
]
392396
);
393397
$model->setCode('scopeCode');
394398

395399
$this->setUrlModifier($model);
396400

397-
$server = $_SERVER;
398-
$_SERVER['SCRIPT_FILENAME'] = 'test_script.php';
399401
$this->assertEquals(
400402
$expectedBaseUrl,
401403
$model->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, false)
402404
);
403-
$_SERVER = $server;
404405
}
405406

406407
/**
@@ -592,7 +593,7 @@ public function testGetAllowedCurrencies()
592593
/** @var \Magento\Store\Model\Store $model */
593594
$model = $this->objectManagerHelper->getObject(
594595
\Magento\Store\Model\Store::class,
595-
['config' => $configMock, 'currencyInstalled' => $currencyPath,]
596+
['config' => $configMock, 'currencyInstalled' => $currencyPath]
596597
);
597598

598599
$this->assertEquals($expectedResult, $model->getAllowedCurrencies());

dev/tests/integration/testsuite/Magento/Store/App/FrontController/Plugin/RequestPreprocessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testHttpsPassSecureLoginPost()
5656
$this->prepareRequest(true);
5757
$this->dispatch('customer/account/loginPost/');
5858
$redirectUrl = str_replace('http://', 'https://', $this->baseUrl) .
59-
'index.php/customer/account/';
59+
'customer/account/';
6060
$this->assertResponseRedirect($this->getResponse(), $redirectUrl);
6161
$this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
6262
$this->setFrontendCompletelySecureRollback();

dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
use Magento\Catalog\Model\ProductRepository;
1010
use Magento\Framework\App\Bootstrap;
11-
use Magento\Framework\App\Config\ScopeConfigInterface;
1211
use Magento\Framework\App\Filesystem\DirectoryList;
1312
use Magento\Framework\UrlInterface;
1413
use Magento\Store\Api\StoreRepositoryInterface;
1514
use Zend\Stdlib\Parameters;
1615

1716
/**
1817
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* phpcs:disable Magento2.Security.Superglobal
1919
*/
2020
class StoreTest extends \PHPUnit\Framework\TestCase
2121
{
@@ -201,7 +201,7 @@ public function testGetBaseUrlInPub()
201201
*/
202202
public function testGetBaseUrlForCustomEntryPoint($type, $useCustomEntryPoint, $useStoreCode, $expected)
203203
{
204-
/* config operations require store to be loaded */
204+
/* config operations require store to be loaded */
205205
$this->model->load('default');
206206
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
207207
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
@@ -213,6 +213,10 @@ public function testGetBaseUrlForCustomEntryPoint($type, $useCustomEntryPoint, $
213213

214214
// emulate custom entry point
215215
$_SERVER['SCRIPT_FILENAME'] = 'custom_entry.php';
216+
$request = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
217+
->get(\Magento\Framework\App\RequestInterface::class);
218+
$request->setServer(new Parameters($_SERVER));
219+
216220
if ($useCustomEntryPoint) {
217221
$property = new \ReflectionProperty($this->model, '_isCustomEntryPoint');
218222
$property->setAccessible(true);
@@ -298,11 +302,11 @@ public function testGetCurrentUrl()
298302
$url = $product->getUrlInStore();
299303

300304
$this->assertEquals(
301-
$secondStore->getBaseUrl().'catalog/product/view/id/1/s/simple-product/',
305+
$secondStore->getBaseUrl() . 'catalog/product/view/id/1/s/simple-product/',
302306
$url
303307
);
304308
$this->assertEquals(
305-
$secondStore->getBaseUrl().'?___from_store=default',
309+
$secondStore->getBaseUrl() . '?___from_store=default',
306310
$secondStore->getCurrentUrl()
307311
);
308312
$this->assertEquals(
@@ -332,25 +336,25 @@ public function testGetCurrentUrlWithUseStoreInUrlFalse()
332336
$product->setStoreId($secondStore->getId());
333337
$url = $product->getUrlInStore();
334338

335-
/** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */
339+
/** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */
336340
$categoryRepository = $objectManager->get(\Magento\Catalog\Model\CategoryRepository::class);
337341
$category = $categoryRepository->get(333, $secondStore->getStoreId());
338342

339343
$this->assertEquals(
340-
$secondStore->getBaseUrl().'catalog/category/view/s/category-1/id/333/',
344+
$secondStore->getBaseUrl() . 'catalog/category/view/s/category-1/id/333/',
341345
$category->getUrl()
342346
);
343347
$this->assertEquals(
344-
$secondStore->getBaseUrl().
348+
$secondStore->getBaseUrl() .
345349
'catalog/product/view/id/333/s/simple-product-three/?___store=fixture_second_store',
346350
$url
347351
);
348352
$this->assertEquals(
349-
$secondStore->getBaseUrl().'?___store=fixture_second_store&___from_store=default',
353+
$secondStore->getBaseUrl() . '?___store=fixture_second_store&___from_store=default',
350354
$secondStore->getCurrentUrl()
351355
);
352356
$this->assertEquals(
353-
$secondStore->getBaseUrl().'?___store=fixture_second_store',
357+
$secondStore->getBaseUrl() . '?___store=fixture_second_store',
354358
$secondStore->getCurrentUrl(false)
355359
);
356360
}
@@ -405,7 +409,7 @@ public function testSaveValidation($badStoreData)
405409
/**
406410
* @return array
407411
*/
408-
public static function saveValidationDataProvider()
412+
public function saveValidationDataProvider()
409413
{
410414
return [
411415
'empty store name' => [['name' => '']],

0 commit comments

Comments
 (0)