@@ -40,6 +40,11 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase
40
40
*/
41
41
protected $ addressRepository ;
42
42
43
+ /**
44
+ * @var \PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ private $ shippingAssignmentMock ;
47
+
43
48
/**
44
49
* @return void
45
50
*/
@@ -59,6 +64,19 @@ protected function setUp()
59
64
'addressRepository ' => $ this ->addressRepository
60
65
]
61
66
);
67
+
68
+ $ this ->shippingAssignmentMock = $ this ->getMock (
69
+ \Magento \Quote \Model \ShippingAddressAssignment::class,
70
+ ['setAddress ' ],
71
+ [],
72
+ '' ,
73
+ false
74
+ );
75
+ $ this ->objectManager ->setBackwardCompatibleProperty (
76
+ $ this ->model ,
77
+ 'shippingAddressAssignment ' ,
78
+ $ this ->shippingAssignmentMock
79
+ );
62
80
}
63
81
64
82
/**
@@ -76,95 +94,44 @@ public function testGetAddress()
76
94
$ this ->assertEquals ($ addressMock , $ this ->model ->get ('cartId ' ));
77
95
}
78
96
79
- /**
80
- * @return void
81
- * @expectedException \Magento\Framework\Exception\NoSuchEntityException
82
- * @expectedExceptionMessage error123
83
- */
84
- public function testSetAddressValidationFailed ()
85
- {
86
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
87
- $ address = $ this ->getMock (\Magento \Quote \Api \Data \AddressInterface::class);
88
- $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class, [], [], '' , false );
89
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
90
- ->method ('getActive ' )
91
- ->with ('cartId ' )
92
- ->will ($ this ->returnValue ($ quoteMock ));
93
-
94
- $ this ->validatorMock ->expects ($ this ->once ())
95
- ->method ('validate ' )
96
- ->will ($ this ->throwException (new \Magento \Framework \Exception \NoSuchEntityException (__ ('error123 ' ))));
97
-
98
- $ this ->model ->assign ('cartId ' , $ address );
99
- }
100
-
101
97
/**
102
98
* @return void
103
99
*/
104
100
public function testSetAddress ()
105
101
{
106
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
107
102
$ cartId = 100 ;
108
103
$ useForShipping = true ;
109
104
$ addressId = 1 ;
110
- $ customerAddressId = 10 ;
111
105
112
106
$ address = $ this ->getMock (
113
107
\Magento \Quote \Model \Quote \Address::class,
114
- ['setSaveInAddressBook ' , ' getCustomerAddressId ' , ' getSaveInAddressBook ' ],
108
+ ['getId ' ],
115
109
[],
116
110
'' ,
117
111
false
118
112
);
119
- $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class, [], [], '' , false );
120
-
121
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
122
- ->method ('getActive ' )
123
- ->with ($ cartId )
124
- ->willReturn ($ quoteMock );
125
- $ this ->validatorMock ->expects ($ this ->once ())->method ('validate ' )
126
- ->with ($ address )
127
- ->willReturn (true );
128
-
129
- $ address ->expects ($ this ->once ())->method ('getCustomerAddressId ' )->willReturn ($ customerAddressId );
130
- $ address ->expects ($ this ->once ())->method ('getSaveInAddressBook ' )->willReturn (1 );
131
-
132
- $ customerAddressMock = $ this ->getMock (\Magento \Customer \Api \Data \AddressInterface::class, [], [], '' , false );
133
- $ this ->addressRepository ->expects ($ this ->once ())
134
- ->method ('getById ' )
135
- ->with ($ customerAddressId )
136
- ->willReturn ($ customerAddressMock );
137
-
138
- $ quoteBillingAddress = $ this ->getMock (\Magento \Quote \Model \Quote \Address::class, [], [], '' , false );
139
- $ quoteBillingAddress ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ addressId ));
140
- $ quoteMock ->expects ($ this ->exactly (2 ))->method ('getBillingAddress ' )->willReturn ($ quoteBillingAddress );
141
- $ quoteBillingAddress ->expects ($ this ->once ())
142
- ->method ('importCustomerAddressData ' )
143
- ->with ($ customerAddressMock )
144
- ->willReturnSelf ();
145
-
146
- $ quoteShippingAddress = $ this ->getMock (
147
- \Magento \Quote \Model \Quote \Address::class,
148
- ['setSaveInAddressBook ' , 'setSameAsBilling ' , 'setCollectShippingRates ' , 'importCustomerAddressData ' ],
113
+ $ quoteMock = $ this ->getMock (
114
+ \Magento \Quote \Model \Quote::class,
115
+ ['removeAddress ' , 'getBillingAddress ' , 'setBillingAddress ' , 'setDataChanges ' ],
149
116
[],
150
117
'' ,
151
118
false
152
119
);
153
- $ quoteMock ->expects ($ this ->once ())->method ('getShippingAddress ' )->willReturn ($ quoteShippingAddress );
154
- $ quoteShippingAddress ->expects ($ this ->once ())
155
- ->method ('importCustomerAddressData ' )
156
- ->with ($ customerAddressMock )
157
- ->willReturnSelf ();
158
- $ quoteShippingAddress ->expects ($ this ->once ())->method ('setSaveInAddressBook ' )->with (1 )->willReturnSelf ();
159
120
160
- $ quoteBillingAddress ->expects ($ this ->once ())->method ('setSaveInAddressBook ' )->with (1 )->willReturnSelf ();
161
- $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ quoteBillingAddress )->willReturnSelf ();
121
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
122
+ ->method ('getActive ' )
123
+ ->with ($ cartId )
124
+ ->willReturn ($ quoteMock );
162
125
163
- $ quoteShippingAddress ->expects ($ this ->once ())->method ('setSameAsBilling ' )->with (1 )->willReturnSelf ();
164
- $ quoteShippingAddress ->expects ($ this ->once ())->method ('setCollectShippingRates ' )->with (true )->willReturnSelf ();
126
+ $ address ->expects ($ this ->exactly (2 ))->method ('getId ' )->willReturn ($ addressId );
127
+ $ quoteMock ->expects ($ this ->exactly (2 ))->method ('getBillingAddress ' )->willReturn ($ address );
128
+ $ quoteMock ->expects ($ this ->once ())->method ('removeAddress ' )->with ($ addressId )->willReturnSelf ();
129
+ $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address )->willReturnSelf ();
130
+ $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (1 )->willReturnSelf ();
165
131
166
- $ quoteMock ->expects ($ this ->once ())->method ('setShippingAddress ' )->with ($ quoteShippingAddress );
167
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
132
+ $ this ->shippingAssignmentMock ->expects ($ this ->once ())
133
+ ->method ('setAddress ' )
134
+ ->with ($ quoteMock , $ address , $ useForShipping );
168
135
169
136
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
170
137
$ this ->assertEquals ($ addressId , $ this ->model ->assign ($ cartId , $ address , $ useForShipping ));
@@ -177,27 +144,45 @@ public function testSetAddress()
177
144
*/
178
145
public function testSetAddressWithInabilityToSaveQuote ()
179
146
{
180
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
181
- $ address = $ this ->getMock (\Magento \Quote \Model \Quote \Address::class, [], [], '' , false , false );
147
+ $ cartId = 100 ;
148
+ $ addressId = 1 ;
149
+
150
+ $ address = $ this ->getMock (
151
+ \Magento \Quote \Model \Quote \Address::class,
152
+ ['getId ' ],
153
+ [],
154
+ '' ,
155
+ false
156
+ );
157
+ $ quoteMock = $ this ->getMock (
158
+ \Magento \Quote \Model \Quote::class,
159
+ ['removeAddress ' , 'getBillingAddress ' , 'setBillingAddress ' , 'setDataChanges ' ],
160
+ [],
161
+ '' ,
162
+ false
163
+ );
182
164
183
- $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class, [], [], '' , false );
184
165
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
185
166
->method ('getActive ' )
186
- ->with ('cartId ' )
187
- ->will ($ this ->returnValue ($ quoteMock ));
167
+ ->with ($ cartId )
168
+ ->willReturn ($ quoteMock );
169
+
170
+ $ address ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ addressId );
171
+ $ quoteMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ address );
172
+ $ quoteMock ->expects ($ this ->once ())->method ('removeAddress ' )->with ($ addressId )->willReturnSelf ();
173
+ $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address )->willReturnSelf ();
174
+ $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (1 )->willReturnSelf ();
188
175
189
- $ this ->validatorMock ->expects ($ this ->once ())-> method ( ' validate ' )
190
- ->with ( $ address )
191
- ->will ( $ this -> returnValue ( true ) );
176
+ $ this ->shippingAssignmentMock ->expects ($ this ->once ())
177
+ ->method ( ' setAddress ' )
178
+ ->with ( $ quoteMock , $ address , false );
192
179
193
- $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address );
194
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
195
180
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
196
181
->method ('save ' )
197
182
->with ($ quoteMock )
198
183
->willThrowException (
199
184
new \Exception ('Some DB Error ' )
200
185
);
201
- $ this ->model ->assign (' cartId ' , $ address );
186
+ $ this ->model ->assign ($ cartId , $ address );
202
187
}
203
188
}
0 commit comments