33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Vault \Test \Unit \Observer ;
78
89use Magento \Framework \App \DeploymentConfig ;
1516use Magento \Sales \Model \Order \Payment ;
1617use Magento \Vault \Model \PaymentToken ;
1718use Magento \Vault \Model \PaymentTokenManagement ;
19+ use Magento \Vault \Model \Ui \VaultConfigProvider ;
1820use Magento \Vault \Observer \AfterPaymentSaveObserver ;
1921use PHPUnit_Framework_MockObject_MockObject as MockObject ;
2022
23+ /**
24+ * Tests for AfterPaymentSaveObserver.
25+ */
2126class AfterPaymentSaveObserverTest extends \PHPUnit \Framework \TestCase
2227{
2328 /**
@@ -93,7 +98,7 @@ protected function setUp()
9398
9499 // Sales Order Payment Model
95100 $ this ->salesOrderPaymentMock = $ this ->getMockBuilder (Payment::class)
96- ->setMethods (null )
101+ ->setMethods ([ ' getAdditionalInformation ' ] )
97102 ->disableOriginalConstructor ()
98103 ->getMock ();
99104 $ this ->salesOrderPaymentMock ->setOrder ($ this ->salesOrderMock );
@@ -122,9 +127,10 @@ protected function setUp()
122127 * @param string $token
123128 * @param bool $isActive
124129 * @param string $method
130+ * @param array $additionalInfo
125131 * @dataProvider positiveCaseDataProvider
126132 */
127- public function testPositiveCase ($ customerId , $ createdAt , $ token , $ isActive , $ method )
133+ public function testPositiveCase ($ customerId , $ createdAt , $ token , $ isActive , $ method, $ additionalInfo )
128134 {
129135 $ this ->paymentTokenMock ->setGatewayToken ($ token );
130136 $ this ->paymentTokenMock ->setCustomerId ($ customerId );
@@ -136,6 +142,8 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
136142 ->method ('getVaultPaymentToken ' )
137143 ->willReturn ($ this ->paymentTokenMock );
138144
145+ $ this ->salesOrderPaymentMock ->method ('getAdditionalInformation ' )->willReturn ($ additionalInfo );
146+
139147 if (!empty ($ token )) {
140148 $ this ->paymentTokenManagementMock ->expects ($ this ->once ())
141149 ->method ('saveTokenWithPaymentLink ' )
@@ -158,6 +166,10 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
158166 static ::assertEquals ($ token , $ paymentToken ->getGatewayToken ());
159167 static ::assertEquals ($ isActive , $ paymentToken ->getIsActive ());
160168 static ::assertEquals ($ createdAt , $ paymentToken ->getCreatedAt ());
169+ static ::assertEquals (
170+ $ additionalInfo [VaultConfigProvider::IS_ACTIVE_CODE ] ?? false ,
171+ $ paymentToken ->getIsVisible ()
172+ );
161173 }
162174
163175 /**
@@ -171,14 +183,32 @@ public function positiveCaseDataProvider()
171183 '10\20\2015 ' ,
172184 'asdfg ' ,
173185 true ,
174- 'paypal '
186+ 'paypal ' ,
187+ [],
188+ ],
189+ [
190+ 1 ,
191+ '10\20\2015 ' ,
192+ 'asdfg ' ,
193+ true ,
194+ 'paypal ' ,
195+ [VaultConfigProvider::IS_ACTIVE_CODE => true ],
196+ ],
197+ [
198+ 1 ,
199+ '10\20\2015 ' ,
200+ 'asdfg ' ,
201+ true ,
202+ 'paypal ' ,
203+ [VaultConfigProvider::IS_ACTIVE_CODE => false ],
175204 ],
176205 [
177206 null ,
178207 null ,
179208 null ,
180209 false ,
181- null
210+ null ,
211+ [],
182212 ],
183213 ];
184214 }
0 commit comments