Skip to content
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: 4 additions & 0 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ protected function _updatePathUseRewrites($url)
$scriptFilename = $this->_request->getServer('SCRIPT_FILENAME');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$indexFileName = is_string($scriptFilename) ? basename($scriptFilename) : '';
if (!str_ends_with(strtolower($indexFileName), '.php')) {
// The running script is not a web entry point (CLI, cron, unknown) - use the default one
$indexFileName = 'index.php';
}
}
$url .= $indexFileName . '/';
}
Expand Down
90 changes: 90 additions & 0 deletions app/code/Magento/Store/Test/Unit/Model/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,96 @@ public function testGetBaseUrlEntryPoint()
);
}

/**
* Entry point appended to the base URL when web server rewrites are disabled
*
* @covers \Magento\Store\Model\Store::getBaseUrl
* @covers \Magento\Store\Model\Store::_updatePathUseRewrites
*
* @param string|null $scriptFilename
* @param bool $isCustomEntryPoint
* @param string $expectedBaseUrl
* @return void
*/
#[DataProvider('getBaseUrlEntryPointDataProvider')]
public function testGetBaseUrlEntryPointResolution(
$scriptFilename,
$isCustomEntryPoint,
$expectedBaseUrl
) {
$expectedPath = 'web/unsecure/base_link_url';
/** @var ReinitableConfigInterface $configMock */
$configMock = $this->createMock(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->any())
->method('getServer')
->with('SCRIPT_FILENAME')
->willReturn($scriptFilename);

/** @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(UrlInterface::URL_TYPE_LINK, false)
);
}

/**
* @return array
*/
public static function getBaseUrlEntryPointDataProvider()
{
$baseUrl = 'http://domain.com/web/unsecure/base_link_url/';

return [
'web request through the default entry point' => [
'/var/www/html/pub/index.php',
false,
$baseUrl . 'index.php/',
],
'web request through a custom entry point script' => [
'/var/www/html/pub/custom_entry.php',
false,
$baseUrl . 'custom_entry.php/',
],
'console command executed via bin/magento' => [
'/var/www/html/bin/magento',
false,
$baseUrl . 'index.php/',
],
'entry point forced by the custom_entry_point parameter' => [
'/var/www/html/bin/magento',
true,
$baseUrl . 'index.php/',
],
'empty SCRIPT_FILENAME' => [
'',
false,
$baseUrl . 'index.php/',
],
'missing SCRIPT_FILENAME' => [
null,
false,
$baseUrl . 'index.php/',
],
];
}

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