7
7
8
8
namespace Magento \Store \Test \Unit \App \Request ;
9
9
10
- use Magento \Framework \App \Config \ReinitableConfigInterface ;
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
11
use Magento \Framework \App \Request \Http ;
12
12
use Magento \Framework \App \Request \PathInfo ;
13
13
use Magento \Framework \Exception \NoSuchEntityException ;
14
14
use Magento \Store \Api \StoreRepositoryInterface ;
15
15
use Magento \Store \App \Request \PathInfoProcessor ;
16
16
use Magento \Store \App \Request \StorePathInfoValidator ;
17
17
use Magento \Store \Model \Store ;
18
+ use Magento \Store \Model \Validation \StoreCodeValidator ;
18
19
use PHPUnit \Framework \MockObject \MockObject ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
@@ -26,152 +27,144 @@ class PathInfoProcessorTest extends TestCase
26
27
private $ model ;
27
28
28
29
/**
29
- * @var MockObject
30
+ * @var MockObject|Http
30
31
*/
31
32
private $ requestMock ;
32
33
33
34
/**
34
- * @var MockObject
35
+ * @var MockObject|ScopeConfigInterface
35
36
*/
36
37
private $ validatorConfigMock ;
37
38
38
39
/**
39
- * @var MockObject
40
+ * @var MockObject|PathInfo
40
41
*/
41
- private $ processorConfigMock ;
42
+ private $ pathInfoMock ;
42
43
43
44
/**
44
- * @var MockObject
45
+ * @var MockObject|StoreCodeValidator
45
46
*/
46
- private $ pathInfoMock ;
47
+ private $ storeCodeValidator ;
47
48
48
49
/**
49
- * @var MockObject
50
+ * @var MockObject|StoreRepositoryInterface
50
51
*/
51
52
private $ storeRepositoryMock ;
52
53
53
54
/**
54
- * @var MockObject
55
+ * @var StorePathInfoValidator
55
56
*/
56
57
private $ storePathInfoValidator ;
57
58
58
59
/**
59
60
* @var string
60
61
*/
61
- protected $ pathInfo = '/storeCode/node_one/ ' ;
62
+ private $ pathInfo = '/storeCode/node_one/ ' ;
62
63
63
64
protected function setUp (): void
64
65
{
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);
74
67
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);
78
72
79
73
$ this ->storePathInfoValidator = new StorePathInfoValidator (
80
74
$ this ->validatorConfigMock ,
81
75
$ this ->storeRepositoryMock ,
82
- $ this ->pathInfoMock
76
+ $ this ->pathInfoMock ,
77
+ $ this ->storeCodeValidator
83
78
);
84
-
85
79
$ this ->model = new PathInfoProcessor (
86
- $ this ->storePathInfoValidator ,
87
- $ this ->validatorConfigMock
80
+ $ this ->storePathInfoValidator
88
81
);
89
82
}
90
83
91
84
public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName ()
92
85
{
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 );
94
92
95
93
$ 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 );
113
105
}
114
106
115
107
public function testProcessIfStoreExistsAndDirectAccessToFrontName ()
116
108
{
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 );
133
128
}
134
129
135
130
public function testProcessIfStoreIsEmpty ()
136
131
{
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 );
138
138
139
139
$ 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 );
152
149
}
153
150
154
151
public function testProcessIfStoreCodeIsNotExist ()
155
152
{
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 ' )
159
163
->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 ' );
174
166
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 );
176
169
}
177
170
}
0 commit comments