5
5
*/
6
6
namespace Magento \Store \Test \Unit \Controller \Store ;
7
7
8
+ use Magento \Framework \App \RequestInterface ;
9
+ use Magento \Framework \App \Response \RedirectInterface ;
10
+ use Magento \Framework \App \ResponseInterface ;
8
11
use Magento \Store \Api \StoreRepositoryInterface ;
9
12
use Magento \Store \Api \StoreResolverInterface ;
13
+ use Magento \Store \Controller \Store \Redirect ;
10
14
use Magento \Store \Model \StoreManagerInterface ;
11
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
16
use Magento \Store \Model \StoreResolver ;
17
+ use Magento \Store \Api \Data \StoreInterface ;
18
+ use PHPUnit \Framework \TestCase ;
13
19
14
20
/**
15
21
* Test class for \Magento\Store\Controller\Store\SwitchAction
16
22
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
23
*/
18
- class RedirectTest extends \ PHPUnit \ Framework \ TestCase
24
+ class RedirectTest extends TestCase
19
25
{
26
+
27
+ const STUB_STORE_TO_SWITCH_TO_CODE = 'sv2 ' ;
28
+ const STUB_DEFAULT_STORE_VIEW = 'default ' ;
29
+
20
30
/**
21
31
* @var \Magento\Store\Controller\Store\SwitchAction
22
32
*/
@@ -58,21 +68,21 @@ class RedirectTest extends \PHPUnit\Framework\TestCase
58
68
*/
59
69
protected function setUp ()
60
70
{
61
- $ this ->storeManagerMock = $ this ->getMockBuilder (\ Magento \ Store \ Model \ StoreManagerInterface::class)->getMock ();
62
- $ this ->storeRepositoryMock = $ this ->getMockBuilder (\ Magento \ Store \ Api \ StoreRepositoryInterface::class)->getMock ();
63
- $ this ->requestMock = $ this ->getMockBuilder (\ Magento \ Framework \ App \ RequestInterface::class)
71
+ $ this ->storeManagerMock = $ this ->getMockBuilder (StoreManagerInterface::class)->getMock ();
72
+ $ this ->storeRepositoryMock = $ this ->getMockBuilder (StoreRepositoryInterface::class)->getMock ();
73
+ $ this ->requestMock = $ this ->getMockBuilder (RequestInterface::class)
64
74
->disableOriginalConstructor ()
65
75
->setMethods (['getHttpHost ' ])
66
76
->getMockForAbstractClass ();
67
- $ this ->responseMock = $ this ->getMockBuilder (\ Magento \ Framework \ App \ ResponseInterface::class)
77
+ $ this ->responseMock = $ this ->getMockBuilder (ResponseInterface::class)
68
78
->disableOriginalConstructor ()
69
79
->setMethods (['setRedirect ' ])
70
80
->getMockForAbstractClass ();
71
81
$ this ->storeResolverMock = $ this ->getMockBuilder (StoreResolverInterface::class)->getMock ();
72
- $ this ->redirectMock = $ this ->getMockBuilder (\ Magento \ Framework \ App \ Response \ RedirectInterface::class)->getMock ();
82
+ $ this ->redirectMock = $ this ->getMockBuilder (RedirectInterface::class)->getMock ();
73
83
74
84
$ this ->model = (new ObjectManager ($ this ))->getObject (
75
- \ Magento \ Store \ Controller \ Store \ Redirect::class,
85
+ Redirect::class,
76
86
[
77
87
'storeRepository ' => $ this ->storeRepositoryMock ,
78
88
'storeManager ' => $ this ->storeManagerMock ,
@@ -89,10 +99,8 @@ protected function setUp()
89
99
*/
90
100
public function testExecute ()
91
101
{
92
- $ storeToSwitchToCode = 'sv2 ' ;
93
- $ defaultStoreViewCode = 'default ' ;
94
- $ defaultStoreViewMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)->getMock ();
95
- $ storeToSwitchToMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)
102
+ $ defaultStoreViewMock = $ this ->getMockBuilder (StoreInterface::class)->getMock ();
103
+ $ storeToSwitchToMock = $ this ->getMockBuilder (StoreInterface::class)
96
104
->disableOriginalConstructor ()
97
105
->setMethods (['isUseStoreInUrl ' ])
98
106
->getMockForAbstractClass ();
@@ -106,20 +114,20 @@ public function testExecute()
106
114
->expects ($ this ->once ())
107
115
->method ('getById ' )
108
116
->with (1 )
109
- ->willReturn ($ defaultStoreViewCode );
117
+ ->willReturn (self :: STUB_DEFAULT_STORE_VIEW );
110
118
$ this ->requestMock ->expects ($ this ->any ())->method ('getParam ' )->willReturnMap (
111
119
[
112
- [StoreResolver::PARAM_NAME , null , $ storeToSwitchToCode ],
113
- ['___from_store ' , null , $ defaultStoreViewCode ]
120
+ [StoreResolver::PARAM_NAME , null , self :: STUB_STORE_TO_SWITCH_TO_CODE ],
121
+ ['___from_store ' , null , self :: STUB_DEFAULT_STORE_VIEW ]
114
122
]
115
123
);
116
124
$ this ->storeRepositoryMock
117
125
->expects ($ this ->any ())
118
126
->method ('get ' )
119
127
->willReturnMap (
120
128
[
121
- [$ defaultStoreViewCode , $ defaultStoreViewMock ],
122
- [$ storeToSwitchToCode , $ storeToSwitchToMock ]
129
+ [self :: STUB_DEFAULT_STORE_VIEW , $ defaultStoreViewMock ],
130
+ [self :: STUB_STORE_TO_SWITCH_TO_CODE , $ storeToSwitchToMock ]
123
131
]
124
132
);
125
133
0 commit comments