33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Paypal \Test \Unit \Controller \Transparent ;
79
810use Magento \Framework \App \Action \Context ;
911use Magento \Framework \Controller \Result \JsonFactory ;
1012use Magento \Framework \Session \Generic ;
1113use Magento \Framework \Session \SessionManager ;
12- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1314use Magento \Paypal \Controller \Transparent \RequestSecureToken ;
1415use Magento \Paypal \Model \Payflow \Service \Request \SecureToken ;
1516use Magento \Paypal \Model \Payflow \Transparent ;
17+ use PHPUnit \Framework \MockObject \MockObject ;
1618
1719/**
1820 * Class RequestSecureTokenTest
2224class RequestSecureTokenTest extends \PHPUnit \Framework \TestCase
2325{
2426 /**
25- * @var Transparent|\PHPUnit_Framework_MockObject_MockObject
27+ * @var Transparent|MockObject
2628 */
27- protected $ transparentMock ;
29+ private $ transparent ;
2830
2931 /**
30- * @var RequestSecureToken|\PHPUnit_Framework_MockObject_MockObject
32+ * @var RequestSecureToken|MockObject
3133 */
32- protected $ controller ;
34+ private $ controller ;
3335
3436 /**
35- * @var Context|\PHPUnit_Framework_MockObject_MockObject
37+ * @var Context|MockObject
3638 */
37- protected $ contextMock ;
39+ private $ context ;
3840
3941 /**
40- * @var JsonFactory|\PHPUnit_Framework_MockObject_MockObject
42+ * @var JsonFactory|MockObject
4143 */
42- protected $ resultJsonFactoryMock ;
44+ private $ resultJsonFactory ;
4345
4446 /**
45- * @var Generic|\PHPUnit_Framework_MockObject_MockObject
47+ * @var Generic|MockObject
4648 */
47- protected $ sessionTransparentMock ;
49+ private $ sessionTransparent ;
4850
4951 /**
50- * @var SecureToken|\PHPUnit_Framework_MockObject_MockObject
52+ * @var SecureToken|MockObject
5153 */
52- protected $ secureTokenServiceMock ;
54+ private $ secureTokenService ;
5355
5456 /**
55- * @var SessionManager|\PHPUnit_Framework_MockObject_MockObject
57+ * @var SessionManager|MockObject
5658 */
57- protected $ sessionManagerMock ;
59+ private $ sessionManager ;
5860
5961 /**
6062 * Set up
@@ -64,45 +66,46 @@ class RequestSecureTokenTest extends \PHPUnit\Framework\TestCase
6466 protected function setUp ()
6567 {
6668
67- $ this ->contextMock = $ this ->getMockBuilder (\Magento \Framework \App \Action \Context::class)
69+ $ this ->context = $ this ->getMockBuilder (\Magento \Framework \App \Action \Context::class)
6870 ->disableOriginalConstructor ()
6971 ->getMock ();
70- $ this ->resultJsonFactoryMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \JsonFactory::class)
72+ $ this ->resultJsonFactory = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \JsonFactory::class)
7173 ->setMethods (['create ' ])
7274 ->disableOriginalConstructor ()
7375 ->getMock ();
74- $ this ->sessionTransparentMock = $ this ->getMockBuilder (\Magento \Framework \Session \Generic::class)
76+ $ this ->sessionTransparent = $ this ->getMockBuilder (\Magento \Framework \Session \Generic::class)
7577 ->setMethods (['setQuoteId ' ])
7678 ->disableOriginalConstructor ()
7779 ->getMock ();
78- $ this ->secureTokenServiceMock = $ this ->getMockBuilder (
80+ $ this ->secureTokenService = $ this ->getMockBuilder (
7981 \Magento \Paypal \Model \Payflow \Service \Request \SecureToken::class
8082 )
8183 ->setMethods (['requestToken ' ])
8284 ->disableOriginalConstructor ()
8385 ->getMock ();
84- $ this ->sessionManagerMock = $ this ->getMockBuilder (\Magento \Framework \Session \SessionManager::class)
86+ $ this ->sessionManager = $ this ->getMockBuilder (\Magento \Framework \Session \SessionManager::class)
8587 ->setMethods (['getQuote ' ])
8688 ->disableOriginalConstructor ()
8789 ->getMock ();
88- $ this ->transparentMock = $ this ->getMockBuilder (\Magento \Paypal \Model \Payflow \Transparent::class)
89- ->setMethods (['getCode ' ])
90+ $ this ->transparent = $ this ->getMockBuilder (\Magento \Paypal \Model \Payflow \Transparent::class)
91+ ->setMethods (['getCode ' , ' isActive ' ])
9092 ->disableOriginalConstructor ()
9193 ->getMock ();
9294
9395 $ this ->controller = new \Magento \Paypal \Controller \Transparent \RequestSecureToken (
94- $ this ->contextMock ,
95- $ this ->resultJsonFactoryMock ,
96- $ this ->sessionTransparentMock ,
97- $ this ->secureTokenServiceMock ,
98- $ this ->sessionManagerMock ,
99- $ this ->transparentMock
96+ $ this ->context ,
97+ $ this ->resultJsonFactory ,
98+ $ this ->sessionTransparent ,
99+ $ this ->secureTokenService ,
100+ $ this ->sessionManager ,
101+ $ this ->transparent
100102 );
101103 }
102104
103105 public function testExecuteSuccess ()
104106 {
105107 $ quoteId = 99 ;
108+ $ storeId = 2 ;
106109 $ tokenFields = ['fields-1 ' , 'fields-2 ' , 'fields-3 ' ];
107110 $ secureToken = 'token_hash ' ;
108111 $ resultExpectation = [
@@ -116,28 +119,32 @@ public function testExecuteSuccess()
116119 $ quoteMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote::class)
117120 ->disableOriginalConstructor ()
118121 ->getMock ();
122+ $ quoteMock ->method ('getStoreId ' )
123+ ->willReturn ($ storeId );
119124 $ tokenMock = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
120125 ->disableOriginalConstructor ()
121126 ->getMock ();
122127 $ jsonMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \Json::class)
123128 ->disableOriginalConstructor ()
124129 ->getMock ();
125130
126- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
131+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
127132 ->method ('getQuote ' )
128133 ->willReturn ($ quoteMock );
134+ $ this ->transparent ->method ('isActive ' )
135+ ->with ($ storeId )
136+ ->willReturn (true );
129137 $ quoteMock ->expects ($ this ->once ())
130138 ->method ('getId ' )
131139 ->willReturn ($ quoteId );
132- $ this ->sessionTransparentMock ->expects ($ this ->once ())
140+ $ this ->sessionTransparent ->expects ($ this ->once ())
133141 ->method ('setQuoteId ' )
134142 ->with ($ quoteId );
135- $ this ->secureTokenServiceMock ->expects ($ this ->once ())
143+ $ this ->secureTokenService ->expects ($ this ->once ())
136144 ->method ('requestToken ' )
137145 ->with ($ quoteMock )
138146 ->willReturn ($ tokenMock );
139- $ this ->transparentMock ->expects ($ this ->once ())
140- ->method ('getCode ' )
147+ $ this ->transparent ->method ('getCode ' )
141148 ->willReturn ('transparent ' );
142149 $ tokenMock ->expects ($ this ->atLeastOnce ())
143150 ->method ('getData ' )
@@ -147,7 +154,7 @@ public function testExecuteSuccess()
147154 ['securetoken ' , null , $ secureToken ]
148155 ]
149156 );
150- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
157+ $ this ->resultJsonFactory ->expects ($ this ->once ())
151158 ->method ('create ' )
152159 ->willReturn ($ jsonMock );
153160 $ jsonMock ->expects ($ this ->once ())
@@ -161,6 +168,7 @@ public function testExecuteSuccess()
161168 public function testExecuteTokenRequestException ()
162169 {
163170 $ quoteId = 99 ;
171+ $ storeId = 2 ;
164172 $ resultExpectation = [
165173 'success ' => false ,
166174 'error ' => true ,
@@ -170,24 +178,29 @@ public function testExecuteTokenRequestException()
170178 $ quoteMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote::class)
171179 ->disableOriginalConstructor ()
172180 ->getMock ();
181+ $ quoteMock ->method ('getStoreId ' )
182+ ->willReturn ($ storeId );
173183 $ jsonMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \Json::class)
174184 ->disableOriginalConstructor ()
175185 ->getMock ();
176186
177- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
187+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
178188 ->method ('getQuote ' )
179189 ->willReturn ($ quoteMock );
180190 $ quoteMock ->expects ($ this ->once ())
181191 ->method ('getId ' )
182192 ->willReturn ($ quoteId );
183- $ this ->sessionTransparentMock ->expects ($ this ->once ())
193+ $ this ->transparent ->method ('isActive ' )
194+ ->with ($ storeId )
195+ ->willReturn (true );
196+ $ this ->sessionTransparent ->expects ($ this ->once ())
184197 ->method ('setQuoteId ' )
185198 ->with ($ quoteId );
186- $ this ->secureTokenServiceMock ->expects ($ this ->once ())
199+ $ this ->secureTokenService ->expects ($ this ->once ())
187200 ->method ('requestToken ' )
188201 ->with ($ quoteMock )
189202 ->willThrowException (new \Exception ());
190- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
203+ $ this ->resultJsonFactory ->expects ($ this ->once ())
191204 ->method ('create ' )
192205 ->willReturn ($ jsonMock );
193206 $ jsonMock ->expects ($ this ->once ())
@@ -211,10 +224,10 @@ public function testExecuteEmptyQuoteError()
211224 ->disableOriginalConstructor ()
212225 ->getMock ();
213226
214- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
227+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
215228 ->method ('getQuote ' )
216229 ->willReturn ($ quoteMock );
217- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
230+ $ this ->resultJsonFactory ->expects ($ this ->once ())
218231 ->method ('create ' )
219232 ->willReturn ($ jsonMock );
220233 $ jsonMock ->expects ($ this ->once ())
0 commit comments