Skip to content

Fix 'magento' adding in the URL when Use Web Server Rewrites set to NO using Console Command #34639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ protected function _updatePathUseRewrites($url)
if ($this->_isCustomEntryPoint()) {
$indexFileName = 'index.php';
} else {
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME');
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME') !== 'bin/magento' ?
$this->_request->getServer('SCRIPT_FILENAME') :
'';
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$indexFileName = is_string($scriptFilename) ? basename($scriptFilename) : '';
}
Expand Down
91 changes: 90 additions & 1 deletion app/code/Magento/Store/Test/Unit/Model/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected function setUp(): void
'getDistroBaseUrl',
'isSecure',
'getServer',
'getOriginalPathInfo'
]);

$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
Expand Down Expand Up @@ -401,7 +402,8 @@ public function testGetBaseUrlEntryPoint()
->willReturnCallback(function ($path, $scope, $scopeCode) use ($expectedPath) {
return $expectedPath == $path ? 'http://domain.com/' . $path . '/' : null;
});
$this->requestMock->expects($this->once())

$this->requestMock->expects($this->exactly(2))
->method('getServer')
->with('SCRIPT_FILENAME')
->willReturn('test_script.php');
Expand All @@ -425,6 +427,93 @@ public function testGetBaseUrlEntryPoint()
);
}

/**
* @dataProvider getCliBaseUrlDataProvider
*
* @covers \Magento\Store\Model\Store::getBaseUrl
* @covers \Magento\Store\Model\Store::getCode
* @covers \Magento\Store\Model\Store::_updatePathUseRewrites
* @covers \Magento\Store\Model\Store::getConfig
*
* @param string $type
* @param boolean $secure
* @param boolean $isCustomEntryPoint
* @param string $expectedPath
* @param string $expectedBaseUrl
*/
public function testGetBaseUrlFromCli(
$type,
$secure,
$isCustomEntryPoint,
$expectedPath,
$expectedBaseUrl
) {
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $configMock */
$configMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
$configMock->expects($this->atLeastOnce())
->method('getValue')
->willReturnCallback(function ($path, $scope, $scopeCode) use ($secure, $expectedPath) {
$url = $secure ? '{{base_url}}' : 'http://domain.com/';
return $expectedPath == $path ? $url . $path . '/' : null;
});
$this->requestMock->expects($this->any())
->method('getDistroBaseUrl')
->willReturn('http://distro.com/');

$this->requestMock->expects($this->any())
->method('getServer')
->with('SCRIPT_FILENAME')
->willReturn('bin/magento');

/** @var Store $model */
$model = $this->objectManagerHelper->getObject(
Store::class,
[
'config' => $configMock,
'isCustomEntryPoint' => $isCustomEntryPoint,
'request' => $this->requestMock
]
);
$model->setCode('scopeCode');

$this->setUrlModifier($model);

$this->assertEquals(
$expectedBaseUrl,
$model->getBaseUrl($type, $secure)
);
}

/**
* @return array
*/
public function getCliBaseUrlDataProvider()
{
return [
[
UrlInterface::URL_TYPE_LINK,
false,
false,
'web/unsecure/base_link_url',
'http://domain.com/web/unsecure/base_link_url/'
],
[
UrlInterface::URL_TYPE_DIRECT_LINK,
false,
false,
'web/unsecure/base_link_url',
'http://domain.com/web/unsecure/base_link_url/'
],
[
UrlInterface::URL_TYPE_LINK,
true,
false,
'web/secure/base_link_url',
'http://distro.com/web/secure/base_link_url/'
],
];
}

public function testGetBaseUrlWrongType()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down