Skip to content

Commit ccd77b8

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

File tree

8 files changed

+584
-187
lines changed

8 files changed

+584
-187
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\Validator\AbstractValidator;
1111
use Magento\Framework\Validator\DataObjectFactory;
12+
use Magento\Framework\Validator\ValidatorInterface;
1213

1314
/**
1415
* Store model validator.
@@ -21,15 +22,15 @@ class StoreValidator extends AbstractValidator
2122
private $dataObjectValidatorFactory;
2223

2324
/**
24-
* @var array
25+
* @var ValidatorInterface[]
2526
*/
2627
private $rules;
2728

2829
/**
2930
* @param DataObjectFactory $dataObjectValidatorFactory
30-
* @param array $rules
31+
* @param ValidatorInterface[] $rules
3132
*/
32-
public function __construct(DataObjectFactory $dataObjectValidatorFactory, array $rules)
33+
public function __construct(DataObjectFactory $dataObjectValidatorFactory, array $rules = [])
3334
{
3435
$this->dataObjectValidatorFactory = $dataObjectValidatorFactory;
3536
$this->rules = $rules;

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

Lines changed: 32 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,117 +7,81 @@
77

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

10-
use Magento\Framework\App\Config\ScopeConfigInterface;
1110
use Magento\Framework\App\Request\Http;
12-
use Magento\Framework\App\Request\PathInfo;
13-
use Magento\Framework\Exception\NoSuchEntityException;
14-
use Magento\Store\Api\StoreRepositoryInterface;
1511
use Magento\Store\App\Request\PathInfoProcessor;
1612
use Magento\Store\App\Request\StorePathInfoValidator;
17-
use Magento\Store\Model\Store;
18-
use Magento\Store\Model\Validation\StoreCodeValidator;
1913
use PHPUnit\Framework\MockObject\MockObject;
2014
use PHPUnit\Framework\TestCase;
2115

2216
class PathInfoProcessorTest extends TestCase
2317
{
2418
/**
25-
* @var PathInfoProcessor
26-
*/
27-
private $model;
28-
29-
/**
30-
* @var MockObject|Http
31-
*/
32-
private $requestMock;
33-
34-
/**
35-
* @var MockObject|ScopeConfigInterface
36-
*/
37-
private $validatorConfigMock;
38-
39-
/**
40-
* @var MockObject|PathInfo
19+
* @var StorePathInfoValidator|MockObject
4120
*/
42-
private $pathInfoMock;
21+
private $storePathInfoValidatorMock;
4322

4423
/**
45-
* @var MockObject|StoreCodeValidator
24+
* @var PathInfoProcessor
4625
*/
47-
private $storeCodeValidator;
26+
private $model;
4827

4928
/**
50-
* @var MockObject|StoreRepositoryInterface
29+
* @var Http|MockObject
5130
*/
52-
private $storeRepositoryMock;
31+
private $requestMock;
5332

5433
/**
55-
* @var StorePathInfoValidator
34+
* @var string
5635
*/
57-
private $storePathInfoValidator;
36+
private $storeCode;
5837

5938
/**
6039
* @var string
6140
*/
62-
private $pathInfo = '/storeCode/node_one/';
41+
private $pathInfo;
6342

6443
protected function setUp(): void
6544
{
45+
$this->storePathInfoValidatorMock = $this->createMock(StorePathInfoValidator::class);
46+
$this->model = new PathInfoProcessor($this->storePathInfoValidatorMock);
47+
6648
$this->requestMock = $this->createMock(Http::class);
49+
$this->storeCode = 'storeCode';
50+
$this->pathInfo = '/' . $this->storeCode . '/node_one/';
51+
}
6752

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);
53+
public function testProcessIfStoreIsEmpty(): void
54+
{
55+
$this->storePathInfoValidatorMock->expects($this->once())
56+
->method('getValidStoreCode')
57+
->willReturn(null);
7258

73-
$this->storePathInfoValidator = new StorePathInfoValidator(
74-
$this->validatorConfigMock,
75-
$this->storeRepositoryMock,
76-
$this->pathInfoMock,
77-
$this->storeCodeValidator
78-
);
79-
$this->model = new PathInfoProcessor(
80-
$this->storePathInfoValidator
81-
);
59+
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
60+
$this->assertEquals($this->pathInfo, $pathInfo);
8261
}
8362

84-
public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName()
63+
public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName(): void
8564
{
86-
$this->validatorConfigMock->expects($this->atLeastOnce())
87-
->method('getValue')
88-
->willReturn(true);
89-
$this->storeCodeValidator->expects($this->atLeastOnce())
90-
->method('isValid')
91-
->willReturn(true);
92-
93-
$store = $this->createMock(Store::class);
94-
$this->storeRepositoryMock->expects($this->once())
95-
->method('getActiveStoreByCode')
96-
->with('storeCode')
97-
->willReturn($store);
65+
$this->storePathInfoValidatorMock->expects($this->once())
66+
->method('getValidStoreCode')
67+
->willReturn($this->storeCode);
9868
$this->requestMock->expects($this->atLeastOnce())
9969
->method('isDirectAccessFrontendName')
100-
->with('storeCode')
70+
->with($this->storeCode)
10171
->willReturn(false);
10272

10373
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
10474
$this->assertEquals('/node_one/', $pathInfo);
10575
}
10676

107-
public function testProcessIfStoreExistsAndDirectAccessToFrontName()
77+
public function testProcessIfStoreExistsAndDirectAccessToFrontName(): void
10878
{
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');
79+
$this->storePathInfoValidatorMock->expects($this->once())
80+
->method('getValidStoreCode')
81+
->willReturn($this->storeCode);
11882
$this->requestMock->expects($this->atLeastOnce())
11983
->method('isDirectAccessFrontendName')
120-
->with('storeCode')
84+
->with($this->storeCode)
12185
->willReturn(true);
12286
$this->requestMock->expects($this->once())
12387
->method('setActionName')
@@ -126,45 +90,4 @@ public function testProcessIfStoreExistsAndDirectAccessToFrontName()
12690
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
12791
$this->assertEquals($this->pathInfo, $pathInfo);
12892
}
129-
130-
public function testProcessIfStoreIsEmpty()
131-
{
132-
$this->validatorConfigMock->expects($this->atLeastOnce())
133-
->method('getValue')
134-
->willReturn(true);
135-
$this->storeCodeValidator->expects($this->any())
136-
->method('isValid')
137-
->willReturn(true);
138-
139-
$path = '/0/node_one/';
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);
149-
}
150-
151-
public function testProcessIfStoreCodeIsNotExist()
152-
{
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')
163-
->willThrowException(new NoSuchEntityException());
164-
$this->requestMock->expects($this->never())
165-
->method('isDirectAccessFrontendName');
166-
167-
$pathInfo = $this->model->process($this->requestMock, $this->pathInfo);
168-
$this->assertEquals($this->pathInfo, $pathInfo);
169-
}
17093
}

0 commit comments

Comments
 (0)