3
3
* Copyright © 2015 Magento. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
namespace Magento \Sales \Test \Unit \Helper ;
8
7
9
- use \Magento \Sales \Helper \Guest ;
10
-
8
+ use Magento \Sales \Helper \Guest ;
11
9
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
12
10
13
11
/**
14
- * Class GuestTest
15
12
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
13
*/
17
14
class GuestTest extends \PHPUnit_Framework_TestCase
@@ -49,6 +46,12 @@ class GuestTest extends \PHPUnit_Framework_TestCase
49
46
/** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
50
47
protected $ viewInterfaceMock ;
51
48
49
+ /** @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */
50
+ protected $ storeModelMock ;
51
+
52
+ /** @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject */
53
+ protected $ salesOrderMock ;
54
+
52
55
protected function setUp ()
53
56
{
54
57
$ this ->appContextHelperMock = $ this ->getMock ('Magento\Framework\App\Helper\Context ' , [], [], '' , false );
@@ -66,6 +69,19 @@ protected function setUp()
66
69
$ this ->managerInterfaceMock = $ this ->getMock ('Magento\Framework\Message\ManagerInterface ' );
67
70
$ this ->orderFactoryMock = $ this ->getMock ('Magento\Sales\Model\OrderFactory ' , ['create ' ], [], '' , false );
68
71
$ this ->viewInterfaceMock = $ this ->getMock ('Magento\Framework\App\ViewInterface ' );
72
+ $ this ->storeModelMock = $ this ->getMockBuilder ('Magento\Store\Model\Store ' )
73
+ ->disableOriginalConstructor ()
74
+ ->getMock ();
75
+ $ this ->salesOrderMock = $ this ->getMock (
76
+ 'Magento\Sales\Model\Order ' ,
77
+ [
78
+ 'getProtectCode ' , 'loadByIncrementIdAndStoreId ' , 'loadByIncrementId ' ,
79
+ 'getId ' , 'getBillingAddress ' , '__wakeup '
80
+ ],
81
+ [],
82
+ '' ,
83
+ false
84
+ );
69
85
70
86
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
71
87
$ this ->guest = $ this ->objectManagerHelper ->getObject (
@@ -86,8 +102,6 @@ protected function setUp()
86
102
87
103
public function testLoadValidOrderNotEmptyPost ()
88
104
{
89
- $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->will ($ this ->returnValue (false ));
90
-
91
105
$ post = [
92
106
'oar_order_id ' => 1 ,
93
107
'oar_type ' => 'email ' ,
@@ -96,20 +110,17 @@ public function testLoadValidOrderNotEmptyPost()
96
110
'oar_zip ' => 'oar_zip ' ,
97
111
98
112
];
113
+ $ storeId = '1 ' ;
99
114
$ incrementId = $ post ['oar_order_id ' ];
115
+ $ protectedCode = 'protectedCode ' ;
116
+ $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
100
117
$ requestMock = $ this ->getMock ('Magento\Framework\App\Request\Http ' , [], [], '' , false );
101
- $ requestMock ->expects ($ this ->once ())->method ('getPostValue ' )->will ($ this ->returnValue ($ post ));
102
-
103
- $ orderMock = $ this ->getMock (
104
- 'Magento\Sales\Model\Order ' ,
105
- ['getProtectCode ' , 'loadByIncrementId ' , 'getId ' , 'getBillingAddress ' , '__wakeup ' ],
106
- [],
107
- '' ,
108
- false
109
- );
110
- $ this ->orderFactoryMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ orderMock ));
111
- $ orderMock ->expects ($ this ->once ())->method ('loadByIncrementId ' )->with ($ incrementId );
112
- $ orderMock ->expects ($ this ->exactly (2 ))->method ('getId ' )->will ($ this ->returnValue ($ incrementId ));
118
+ $ requestMock ->expects ($ this ->once ())->method ('getPostValue ' )->willReturn ($ post );
119
+ $ this ->storeManagerInterfaceMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ this ->storeModelMock );
120
+ $ this ->storeModelMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ storeId );
121
+ $ this ->orderFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->salesOrderMock );
122
+ $ this ->salesOrderMock ->expects ($ this ->once ())->method ('loadByIncrementIdAndStoreId ' )->willReturnSelf ();
123
+ $ this ->salesOrderMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ incrementId );
113
124
114
125
$ billingAddressMock = $ this ->getMock (
115
126
'Magento\Sales\Model\Order\Address ' ,
@@ -118,33 +129,27 @@ public function testLoadValidOrderNotEmptyPost()
118
129
'' ,
119
130
false
120
131
);
121
- $ billingAddressMock ->expects ($ this ->once ())->method ('getLastname ' )->will (
122
- $ this ->returnValue ($ post ['oar_billing_lastname ' ])
123
- );
124
- $ billingAddressMock ->expects ($ this ->once ())->method ('getEmail ' )->will (
125
- $ this ->returnValue ($ post ['oar_email ' ])
126
- );
127
- $ orderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->will ($ this ->returnValue ($ billingAddressMock ));
128
- $ protectedCode = 'protectedCode ' ;
129
- $ orderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->will ($ this ->returnValue ($ protectedCode ));
132
+ $ billingAddressMock ->expects ($ this ->once ())->method ('getLastname ' )->willReturn (($ post ['oar_billing_lastname ' ]));
133
+ $ billingAddressMock ->expects ($ this ->once ())->method ('getEmail ' )->willReturn (($ post ['oar_email ' ]));
134
+ $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
135
+ $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->willReturn ($ protectedCode );
130
136
$ metaDataMock = $ this ->getMock (
131
137
'Magento\Framework\Stdlib\Cookie\PublicCookieMetadata ' ,
132
138
[],
133
139
[],
134
140
'' ,
135
141
false
136
142
);
137
- $ metaDataMock ->expects ($ this ->once ())
138
- ->method ('setPath ' )
143
+ $ metaDataMock ->expects ($ this ->once ())->method ('setPath ' )
139
144
->with (Guest::COOKIE_PATH )
140
- ->will ( $ this -> returnSelf () );
145
+ ->willReturnSelf ( );
141
146
$ metaDataMock ->expects ($ this ->once ())
142
147
->method ('setHttpOnly ' )
143
148
->with (true )
144
- ->will ( $ this -> returnSelf () );
149
+ ->willReturnSelf ( );
145
150
$ this ->cookieMetadataFactoryMock ->expects ($ this ->once ())
146
151
->method ('createPublicCookieMetadata ' )
147
- ->will ( $ this -> returnValue ( $ metaDataMock) );
152
+ ->willReturn ( $ metaDataMock );
148
153
$ this ->cookieManagerMock ->expects ($ this ->once ())
149
154
->method ('setPublicCookie ' )
150
155
->with (Guest::COOKIE_NAME , $ this ->anything (), $ metaDataMock );
@@ -153,26 +158,22 @@ public function testLoadValidOrderNotEmptyPost()
153
158
154
159
public function testLoadValidOrderStoredCookie ()
155
160
{
156
- $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->will ($ this ->returnValue (false ));
157
- $ orderMock = $ this ->getMock (
158
- 'Magento\Sales\Model\Order ' ,
159
- ['getProtectCode ' , 'loadByIncrementId ' , 'getId ' , 'getBillingAddress ' , '__wakeup ' ],
160
- [],
161
- '' ,
162
- false
163
- );
164
161
$ protectedCode = 'protectedCode ' ;
165
162
$ incrementId = 1 ;
166
163
$ cookieData = $ protectedCode . ': ' . $ incrementId ;
167
164
$ cookieDataHash = base64_encode ($ cookieData );
168
- $ this ->orderFactoryMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ orderMock ));
169
-
170
- $ this ->cookieManagerMock ->expects ($ this ->once ())->method ('getCookie ' )->with (Guest::COOKIE_NAME )->will (
171
- $ this ->returnValue ($ cookieDataHash )
172
- );
173
- $ orderMock ->expects ($ this ->once ())->method ('loadByIncrementId ' )->with ($ incrementId );
174
- $ orderMock ->expects ($ this ->exactly (1 ))->method ('getId ' )->will ($ this ->returnValue ($ incrementId ));
175
- $ orderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->will ($ this ->returnValue ($ protectedCode ));
165
+ $ this ->sessionMock ->expects ($ this ->once ())->method ('isLoggedIn ' )->willReturn (false );
166
+ $ this ->orderFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->salesOrderMock );
167
+ $ this ->cookieManagerMock ->expects ($ this ->once ())
168
+ ->method ('getCookie ' )
169
+ ->with (Guest::COOKIE_NAME )
170
+ ->willReturn ($ cookieDataHash );
171
+ $ this ->salesOrderMock ->expects ($ this ->once ())
172
+ ->method ('loadByIncrementId ' )
173
+ ->with ($ incrementId )
174
+ ->willReturnSelf ();
175
+ $ this ->salesOrderMock ->expects ($ this ->exactly (1 ))->method ('getId ' )->willReturn ($ incrementId );
176
+ $ this ->salesOrderMock ->expects ($ this ->once ())->method ('getProtectCode ' )->willReturn ($ protectedCode );
176
177
$ metaDataMock = $ this ->getMock (
177
178
'Magento\Framework\Stdlib\Cookie\PublicCookieMetadata ' ,
178
179
[],
@@ -183,18 +184,17 @@ public function testLoadValidOrderStoredCookie()
183
184
$ metaDataMock ->expects ($ this ->once ())
184
185
->method ('setPath ' )
185
186
->with (Guest::COOKIE_PATH )
186
- ->will ( $ this -> returnSelf () );
187
+ ->willReturnSelf ( );
187
188
$ metaDataMock ->expects ($ this ->once ())
188
189
->method ('setHttpOnly ' )
189
190
->with (true )
190
- ->will ( $ this -> returnSelf () );
191
+ ->willReturnSelf ( );
191
192
$ this ->cookieMetadataFactoryMock ->expects ($ this ->once ())
192
193
->method ('createPublicCookieMetadata ' )
193
- ->will ( $ this -> returnValue ( $ metaDataMock) );
194
+ ->willReturn ( $ metaDataMock );
194
195
$ this ->cookieManagerMock ->expects ($ this ->once ())
195
196
->method ('setPublicCookie ' )
196
197
->with (Guest::COOKIE_NAME , $ this ->anything (), $ metaDataMock );
197
-
198
198
$ requestMock = $ this ->getMock ('Magento\Framework\App\Request\Http ' , [], [], '' , false );
199
199
$ this ->assertTrue ($ this ->guest ->loadValidOrder ($ requestMock ));
200
200
}
0 commit comments