1+ <?php
2+ /**
3+ * Copyright © 2016 Magento. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ namespace Magento \Paypal \Test \Unit \Model \Payment \Method \Billing ;
7+
8+ use Magento \Framework \DataObject ;
9+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10+ use Magento \Paypal \Model \Billing \Agreement ;
11+ use Magento \Paypal \Model \Payment \Method \Billing \AbstractAgreement ;
12+ use Magento \Quote \Api \Data \PaymentInterface ;
13+ use Magento \Quote \Model \Quote ;
14+ use Magento \Quote \Model \Quote \Payment ;
15+
16+ class AbstractAgreementTest extends \PHPUnit_Framework_TestCase
17+ {
18+ /**
19+ * @var \Magento\Paypal\Model\Billing\AgreementFactory|\PHPUnit_Framework_MockObject_MockObject
20+ */
21+ private $ agreementFactory ;
22+
23+ /**
24+ * @var AbstractAgreementStub
25+ */
26+ private $ payment ;
27+
28+ public function setUp ()
29+ {
30+ $ helper = new ObjectManager ($ this );
31+
32+ $ this ->agreementFactory = $ this ->getMockBuilder ('Magento\Paypal\Model\Billing\AgreementFactory ' )
33+ ->disableOriginalConstructor ()
34+ ->setMethods (['create ' ])
35+ ->getMock ();
36+ $ this ->payment = $ helper ->getObject (
37+ AbstractAgreementStub::class,
38+ [
39+ 'agreementFactory ' => $ this ->agreementFactory
40+ ]
41+ );
42+ }
43+ public function testAssignData ()
44+ {
45+ $ baId = '1678235 ' ;
46+ $ customerId = 67 ;
47+ $ referenceId = '1234124 ' ;
48+
49+ $ data = new DataObject (
50+ [
51+ PaymentInterface::KEY_ADDITIONAL_DATA => [
52+ AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID => $ baId
53+ ]
54+ ]
55+ );
56+
57+ $ paymentInfo = $ this ->getMockBuilder (Payment::class)
58+ ->disableOriginalConstructor ()
59+ ->getMock ();
60+ $ quote = $ this ->getMockBuilder (Quote::class)
61+ ->disableOriginalConstructor ()
62+ ->setMethods (['__wakeup ' , 'getCustomerId ' ])
63+ ->getMock ();
64+
65+ $ this ->payment ->setInfoInstance ($ paymentInfo );
66+
67+ $ agreementModel = $ this ->getMockBuilder (Agreement::class)
68+ ->disableOriginalConstructor ()
69+ ->setMethods (['__wakeup ' , 'load ' , 'getCustomerId ' , 'getId ' , 'getReferenceId ' ])
70+ ->getMock ();
71+
72+ $ this ->agreementFactory ->expects (static ::once ())
73+ ->method ('create ' )
74+ ->willReturn ($ agreementModel );
75+
76+ $ paymentInfo ->expects (static ::once ())
77+ ->method ('getQuote ' )
78+ ->willReturn ($ quote );
79+
80+ $ agreementModel ->expects (static ::once ())
81+ ->method ('load ' )
82+ ->with ($ baId );
83+ $ agreementModel ->expects (static ::once ())
84+ ->method ('getId ' )
85+ ->willReturn ($ baId );
86+ $ agreementModel ->expects (static ::atLeastOnce ())
87+ ->method ('getCustomerId ' )
88+ ->willReturn ($ customerId );
89+ $ agreementModel ->expects (static ::atLeastOnce ())
90+ ->method ('getReferenceId ' )
91+ ->willReturn ($ referenceId );
92+
93+ $ quote ->expects (static ::once ())
94+ ->method ('getCustomerId ' )
95+ ->willReturn ($ customerId );
96+
97+ $ paymentInfo ->expects (static ::exactly (2 ))
98+ ->method ('setAdditionalInformation ' )
99+ ->willReturnMap (
100+ [
101+ AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID , $ baId ,
102+ AbstractAgreement::PAYMENT_INFO_REFERENCE_ID , $ referenceId
103+ ]
104+ );
105+ $ this ->payment ->assignData ($ data );
106+ }
107+ }
0 commit comments