7
7
8
8
namespace Magento \Store \Test \Unit \App \Request ;
9
9
10
- use Magento \Framework \App \Config \ScopeConfigInterface ;
11
10
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 ;
15
11
use Magento \Store \App \Request \PathInfoProcessor ;
16
12
use Magento \Store \App \Request \StorePathInfoValidator ;
17
- use Magento \Store \Model \Store ;
18
- use Magento \Store \Model \Validation \StoreCodeValidator ;
19
13
use PHPUnit \Framework \MockObject \MockObject ;
20
14
use PHPUnit \Framework \TestCase ;
21
15
22
16
class PathInfoProcessorTest extends TestCase
23
17
{
24
18
/**
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
41
20
*/
42
- private $ pathInfoMock ;
21
+ private $ storePathInfoValidatorMock ;
43
22
44
23
/**
45
- * @var MockObject|StoreCodeValidator
24
+ * @var PathInfoProcessor
46
25
*/
47
- private $ storeCodeValidator ;
26
+ private $ model ;
48
27
49
28
/**
50
- * @var MockObject|StoreRepositoryInterface
29
+ * @var Http|MockObject
51
30
*/
52
- private $ storeRepositoryMock ;
31
+ private $ requestMock ;
53
32
54
33
/**
55
- * @var StorePathInfoValidator
34
+ * @var string
56
35
*/
57
- private $ storePathInfoValidator ;
36
+ private $ storeCode ;
58
37
59
38
/**
60
39
* @var string
61
40
*/
62
- private $ pathInfo = ' /storeCode/node_one/ ' ;
41
+ private $ pathInfo ;
63
42
64
43
protected function setUp (): void
65
44
{
45
+ $ this ->storePathInfoValidatorMock = $ this ->createMock (StorePathInfoValidator::class);
46
+ $ this ->model = new PathInfoProcessor ($ this ->storePathInfoValidatorMock );
47
+
66
48
$ this ->requestMock = $ this ->createMock (Http::class);
49
+ $ this ->storeCode = 'storeCode ' ;
50
+ $ this ->pathInfo = '/ ' . $ this ->storeCode . '/node_one/ ' ;
51
+ }
67
52
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 );
72
58
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 );
82
61
}
83
62
84
- public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName ()
63
+ public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName (): void
85
64
{
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 );
98
68
$ this ->requestMock ->expects ($ this ->atLeastOnce ())
99
69
->method ('isDirectAccessFrontendName ' )
100
- ->with (' storeCode ' )
70
+ ->with ($ this -> storeCode )
101
71
->willReturn (false );
102
72
103
73
$ pathInfo = $ this ->model ->process ($ this ->requestMock , $ this ->pathInfo );
104
74
$ this ->assertEquals ('/node_one/ ' , $ pathInfo );
105
75
}
106
76
107
- public function testProcessIfStoreExistsAndDirectAccessToFrontName ()
77
+ public function testProcessIfStoreExistsAndDirectAccessToFrontName (): void
108
78
{
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 );
118
82
$ this ->requestMock ->expects ($ this ->atLeastOnce ())
119
83
->method ('isDirectAccessFrontendName ' )
120
- ->with (' storeCode ' )
84
+ ->with ($ this -> storeCode )
121
85
->willReturn (true );
122
86
$ this ->requestMock ->expects ($ this ->once ())
123
87
->method ('setActionName ' )
@@ -126,45 +90,4 @@ public function testProcessIfStoreExistsAndDirectAccessToFrontName()
126
90
$ pathInfo = $ this ->model ->process ($ this ->requestMock , $ this ->pathInfo );
127
91
$ this ->assertEquals ($ this ->pathInfo , $ pathInfo );
128
92
}
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
- }
170
93
}
0 commit comments