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 1 commit
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
9 changes: 6 additions & 3 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,12 @@ protected function _updatePathUseRewrites($url)
if ($this->_isCustomEntryPoint()) {
$indexFileName = 'index.php';
} else {
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$indexFileName = basename($scriptFilename);
$indexFileName = '';
if ($this->_request->getOriginalPathInfo()) {
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$indexFileName = basename($scriptFilename);
}
}
$url .= $indexFileName . '/';
}
Expand Down
41 changes: 41 additions & 0 deletions 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,6 +402,9 @@ public function testGetBaseUrlEntryPoint()
->willReturnCallback(function ($path, $scope, $scopeCode) use ($expectedPath) {
return $expectedPath == $path ? 'http://domain.com/' . $path . '/' : null;
});
$this->requestMock->expects($this->once())
->method('getOriginalPathInfo')
->willReturn('web/unsecure/base_link_url/test_script.php/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like not a real case. Could you add something similar to what we have during the actual code execution?

$this->requestMock->expects($this->once())
->method('getServer')
->with('SCRIPT_FILENAME')
Expand All @@ -425,6 +429,43 @@ public function testGetBaseUrlEntryPoint()
);
}

/**
* @return void
*/
public function testGetBaseUrlFromCli()
{
$expectedPath = 'web/unsecure/base_link_url';
$expectedBaseUrl = 'http://domain.com/web/unsecure/base_link_url/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look real example. Could you fix that?

/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $configMock */
$configMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
$configMock->expects($this->atLeastOnce())
->method('getValue')
->willReturnCallback(function ($path, $scope, $scopeCode) use ($expectedPath) {
return $expectedPath == $path ? 'http://domain.com/' . $path . '/' : null;
});
$this->requestMock->expects($this->once())
->method('getOriginalPathInfo')
->willReturn('');

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

$this->setUrlModifier($model);

$this->assertEquals(
$expectedBaseUrl,
$model->getBaseUrl(UrlInterface::URL_TYPE_LINK, false)
);
}

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