Skip to content

Commit 95819f2

Browse files
committed
MC-40538: When entering example.com/0 into browser the homepage is shown (example.com)
1 parent 80a3af8 commit 95819f2

File tree

5 files changed

+89
-139
lines changed

5 files changed

+89
-139
lines changed

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public function __construct(
174174
$this->dataObjectHelper = $dataObjectHelper;
175175
$this->compositeValidator = $compositeValidator ?: ObjectManager::getInstance()
176176
->get(CompositeValidator::class);
177-
178177
parent::__construct(
179178
$context,
180179
$registry,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ protected function _getSession()
482482
}
483483

484484
/**
485-
* @inheritDoc
485+
* Validation rules for store
486+
*
487+
* @return \Zend_Validate_Interface|null
488+
* @throws \Zend_Validate_Exception
486489
*/
487490
protected function _getValidationRulesBeforeSave()
488491
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(NotEmptyFactory $notEmptyValidatorFactory)
3333
*/
3434
public function isValid($value)
3535
{
36-
$validator = $this->notEmptyValidatorFactory->create();
36+
$validator = $this->notEmptyValidatorFactory->create(['options' => []]);
3737
$validator->setMessage(__('Name is required'), \Zend_Validate_NotEmpty::IS_EMPTY);
3838

3939
return $validator->isValid($value);

app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php

Lines changed: 84 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
namespace Magento\Store\Test\Unit\App\Request;
99

10-
use Magento\Framework\App\Config\ReinitableConfigInterface;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\App\Request\Http;
1212
use Magento\Framework\App\Request\PathInfo;
1313
use Magento\Framework\Exception\NoSuchEntityException;
1414
use Magento\Store\Api\StoreRepositoryInterface;
1515
use Magento\Store\App\Request\PathInfoProcessor;
1616
use Magento\Store\App\Request\StorePathInfoValidator;
1717
use Magento\Store\Model\Store;
18+
use Magento\Store\Model\Validation\StoreCodeValidator;
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

@@ -26,152 +27,144 @@ class PathInfoProcessorTest extends TestCase
2627
private $model;
2728

2829
/**
29-
* @var MockObject
30+
* @var MockObject|Http
3031
*/
3132
private $requestMock;
3233

3334
/**
34-
* @var MockObject
35+
* @var MockObject|ScopeConfigInterface
3536
*/
3637
private $validatorConfigMock;
3738

3839
/**
39-
* @var MockObject
40+
* @var MockObject|PathInfo
4041
*/
41-
private $processorConfigMock;
42+
private $pathInfoMock;
4243

4344
/**
44-
* @var MockObject
45+
* @var MockObject|StoreCodeValidator
4546
*/
46-
private $pathInfoMock;
47+
private $storeCodeValidator;
4748

4849
/**
49-
* @var MockObject
50+
* @var MockObject|StoreRepositoryInterface
5051
*/
5152
private $storeRepositoryMock;
5253

5354
/**
54-
* @var MockObject
55+
* @var StorePathInfoValidator
5556
*/
5657
private $storePathInfoValidator;
5758

5859
/**
5960
* @var string
6061
*/
61-
protected $pathInfo = '/storeCode/node_one/';
62+
private $pathInfo = '/storeCode/node_one/';
6263

6364
protected function setUp(): void
6465
{
65-
$this->requestMock = $this->getMockBuilder(Http::class)
66-
->disableOriginalConstructor()
67-
->getMock();
68-
69-
$this->validatorConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
70-
71-
$this->processorConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
72-
73-
$this->storeRepositoryMock = $this->getMockForAbstractClass(StoreRepositoryInterface::class);
66+
$this->requestMock = $this->createMock(Http::class);
7467

75-
$this->pathInfoMock = $this->getMockBuilder(PathInfo ::class)
76-
->disableOriginalConstructor()
77-
->getMock();
68+
$this->validatorConfigMock = $this->createMock(ScopeConfigInterface::class);
69+
$this->storeRepositoryMock = $this->createMock(StoreRepositoryInterface::class);
70+
$this->pathInfoMock = $this->createMock(PathInfo ::class);
71+
$this->storeCodeValidator = $this->createMock(StoreCodeValidator::class);
7872

7973
$this->storePathInfoValidator = new StorePathInfoValidator(
8074
$this->validatorConfigMock,
8175
$this->storeRepositoryMock,
82-
$this->pathInfoMock
76+
$this->pathInfoMock,
77+
$this->storeCodeValidator
8378
);
84-
8579
$this->model = new PathInfoProcessor(
86-
$this->storePathInfoValidator,
87-
$this->validatorConfigMock
80+
$this->storePathInfoValidator
8881
);
8982
}
9083

9184
public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName()
9285
{
93-
$this->validatorConfigMock->expects($this->any())->method('getValue')->willReturn(true);
86+
$this->validatorConfigMock->expects($this->atLeastOnce())
87+
->method('getValue')
88+
->willReturn(true);
89+
$this->storeCodeValidator->expects($this->atLeastOnce())
90+
->method('isValid')
91+
->willReturn(true);
9492

9593
$store = $this->createMock(Store::class);
96-
$this->storeRepositoryMock->expects(
97-
$this->atLeastOnce()
98-
)->method(
99-
'getActiveStoreByCode'
100-
)->with(
101-
'storeCode'
102-
)->willReturn($store);
103-
$this->requestMock->expects(
104-
$this->atLeastOnce()
105-
)->method(
106-
'isDirectAccessFrontendName'
107-
)->with(
108-
'storeCode'
109-
)->willReturn(
110-
false
111-
);
112-
$this->assertEquals('/node_one/', $this->model->process($this->requestMock, $this->pathInfo));
94+
$this->storeRepositoryMock->expects($this->once())
95+
->method('getActiveStoreByCode')
96+
->with('storeCode')
97+
->willReturn($store);
98+
$this->requestMock->expects($this->atLeastOnce())
99+
->method('isDirectAccessFrontendName')
100+
->with('storeCode')
101+
->willReturn(false);
102+
103+
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
104+
$this->assertEquals('/node_one/', $pathInfo);
113105
}
114106

115107
public function testProcessIfStoreExistsAndDirectAccessToFrontName()
116108
{
117-
$this->validatorConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturn(true);
118-
119-
$this->storeRepositoryMock->expects(
120-
$this->any()
121-
)->method(
122-
'getActiveStoreByCode'
123-
);
124-
$this->requestMock->expects(
125-
$this->atLeastOnce()
126-
)->method(
127-
'isDirectAccessFrontendName'
128-
)->with(
129-
'storeCode'
130-
)->willReturn(true);
131-
$this->requestMock->expects($this->once())->method('setActionName')->with('noroute');
132-
$this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo));
109+
$this->validatorConfigMock->expects($this->atLeastOnce())
110+
->method('getValue')
111+
->willReturn(true);
112+
$this->storeCodeValidator->expects($this->atLeastOnce())
113+
->method('isValid')
114+
->willReturn(true);
115+
116+
$this->storeRepositoryMock->expects($this->once())
117+
->method('getActiveStoreByCode');
118+
$this->requestMock->expects($this->atLeastOnce())
119+
->method('isDirectAccessFrontendName')
120+
->with('storeCode')
121+
->willReturn(true);
122+
$this->requestMock->expects($this->once())
123+
->method('setActionName')
124+
->with('noroute');
125+
126+
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
127+
$this->assertEquals($this->pathInfo, $pathInfo);
133128
}
134129

135130
public function testProcessIfStoreIsEmpty()
136131
{
137-
$this->validatorConfigMock->expects($this->any())->method('getValue')->willReturn(true);
132+
$this->validatorConfigMock->expects($this->atLeastOnce())
133+
->method('getValue')
134+
->willReturn(true);
135+
$this->storeCodeValidator->expects($this->any())
136+
->method('isValid')
137+
->willReturn(true);
138138

139139
$path = '/0/node_one/';
140-
$this->storeRepositoryMock->expects(
141-
$this->never()
142-
)->method(
143-
'getActiveStoreByCode'
144-
);
145-
$this->requestMock->expects(
146-
$this->never()
147-
)->method(
148-
'isDirectAccessFrontendName'
149-
);
150-
$this->requestMock->expects($this->never())->method('setActionName');
151-
$this->assertEquals($path, $this->model->process($this->requestMock, $path));
140+
$this->storeRepositoryMock->expects($this->never())
141+
->method('getActiveStoreByCode');
142+
$this->requestMock->expects($this->never())
143+
->method('isDirectAccessFrontendName');
144+
$this->requestMock->expects($this->never())
145+
->method('setActionName');
146+
147+
$pathInfo = $this->model->process($this->requestMock, $path);
148+
$this->assertEquals($path, $pathInfo);
152149
}
153150

154151
public function testProcessIfStoreCodeIsNotExist()
155152
{
156-
$this->validatorConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturn(true);
157-
158-
$this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->with('storeCode')
153+
$this->validatorConfigMock->expects($this->atLeastOnce())
154+
->method('getValue')
155+
->willReturn(true);
156+
$this->storeCodeValidator->expects($this->atLeastOnce())
157+
->method('isValid')
158+
->willReturn(true);
159+
160+
$this->storeRepositoryMock->expects($this->once())
161+
->method('getActiveStoreByCode')
162+
->with('storeCode')
159163
->willThrowException(new NoSuchEntityException());
160-
$this->requestMock->expects($this->never())->method('isDirectAccessFrontendName');
161-
162-
$this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo));
163-
}
164-
165-
public function testProcessIfStoreUrlNotEnabled()
166-
{
167-
$this->validatorConfigMock->expects($this->at(0))->method('getValue')->willReturn(true);
168-
169-
$this->validatorConfigMock->expects($this->at(1))->method('getValue')->willReturn(true);
170-
171-
$this->validatorConfigMock->expects($this->at(2))->method('getValue')->willReturn(false);
172-
173-
$this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->willReturn(1);
164+
$this->requestMock->expects($this->never())
165+
->method('isDirectAccessFrontendName');
174166

175-
$this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo));
167+
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
168+
$this->assertEquals($this->pathInfo, $pathInfo);
176169
}
177170
}

dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@ public function notValidStoreCodeDataProvider()
4646
];
4747
}
4848

49-
/**
50-
* @covers \Magento\Store\App\Request\PathInfoProcessor::process
51-
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
52-
*/
53-
public function testProcessValidStoreDisabledStoreUrl()
54-
{
55-
/** @var \Magento\Store\Model\Store $store */
56-
$store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class);
57-
$store->load('fixturestore', 'code');
58-
59-
/** @var \Magento\Framework\App\RequestInterface $request */
60-
$request = Bootstrap::getObjectManager()->create(\Magento\Framework\App\RequestInterface::class);
61-
62-
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
63-
$config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
64-
$config->setValue(Store::XML_PATH_STORE_IN_URL, true);
65-
$config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode());
66-
$pathInfo = sprintf('/%s/m/c/a', $store->getCode());
67-
$this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo));
68-
}
69-
7049
/**
7150
* @covers \Magento\Store\App\Request\PathInfoProcessor::process
7251
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
@@ -113,30 +92,6 @@ public function testProcessValidStoreCodeWhenStoreIsDirectFrontNameWithFrontName
11392
$this->assertEquals(\Magento\Framework\App\Router\Base::NO_ROUTE, $request->getActionName());
11493
}
11594

116-
/**
117-
* @covers \Magento\Store\App\Request\PathInfoProcessor::process
118-
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
119-
*/
120-
public function testProcessValidStoreCodeWhenStoreCodeInUrlIsDisabledWithFrontName()
121-
{
122-
/** @var \Magento\Store\Model\Store $store */
123-
$store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class);
124-
$store->load('fixturestore', 'code');
125-
126-
/** @var \Magento\Framework\App\RequestInterface $request */
127-
$request = Bootstrap::getObjectManager()->create(
128-
\Magento\Framework\App\RequestInterface::class,
129-
['directFrontNames' => ['someFrontName' => true]]
130-
);
131-
132-
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
133-
$config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
134-
$config->setValue(Store::XML_PATH_STORE_IN_URL, true);
135-
$config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode());
136-
$pathInfo = sprintf('/%s/m/c/a', $store->getCode());
137-
$this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo));
138-
}
139-
14095
/**
14196
* @covers \Magento\Store\App\Request\PathInfoProcessor::process
14297
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php

0 commit comments

Comments
 (0)