@@ -76,95 +76,40 @@ public function testGetAddress()
76
76
$ this ->assertEquals ($ addressMock , $ this ->model ->get ('cartId ' ));
77
77
}
78
78
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
79
/**
102
80
* @return void
103
81
*/
104
82
public function testSetAddress ()
105
83
{
106
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
107
84
$ cartId = 100 ;
108
85
$ useForShipping = true ;
109
86
$ addressId = 1 ;
110
- $ customerAddressId = 10 ;
111
87
112
88
$ address = $ this ->getMock (
113
89
\Magento \Quote \Model \Quote \Address::class,
114
- ['setSaveInAddressBook ' , ' getCustomerAddressId ' , ' getSaveInAddressBook ' ],
90
+ ['getId ' ],
115
91
[],
116
92
'' ,
117
93
false
118
94
);
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 ' ],
95
+ $ quoteMock = $ this ->getMock (
96
+ \Magento \Quote \Model \Quote::class,
97
+ ['removeAddress ' , 'getBillingAddress ' , 'setBillingAddress ' , 'setDataChanges ' ],
149
98
[],
150
99
'' ,
151
100
false
152
101
);
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
102
160
- $ quoteBillingAddress ->expects ($ this ->once ())->method ('setSaveInAddressBook ' )->with (1 )->willReturnSelf ();
161
- $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ quoteBillingAddress )->willReturnSelf ();
162
-
163
- $ quoteShippingAddress ->expects ($ this ->once ())->method ('setSameAsBilling ' )->with (1 )->willReturnSelf ();
164
- $ quoteShippingAddress ->expects ($ this ->once ())->method ('setCollectShippingRates ' )->with (true )->willReturnSelf ();
103
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
104
+ ->method ('getActive ' )
105
+ ->with ($ cartId )
106
+ ->willReturn ($ quoteMock );
165
107
166
- $ quoteMock ->expects ($ this ->once ())->method ('setShippingAddress ' )->with ($ quoteShippingAddress );
167
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
108
+ $ address ->expects ($ this ->exactly (2 ))->method ('getId ' )->willReturn ($ addressId );
109
+ $ quoteMock ->expects ($ this ->exactly (2 ))->method ('getBillingAddress ' )->willReturn ($ address );
110
+ $ quoteMock ->expects ($ this ->once ())->method ('removeAddress ' )->with ($ addressId )->willReturnSelf ();
111
+ $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address )->willReturnSelf ();
112
+ $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (1 )->willReturnSelf ();
168
113
169
114
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
170
115
$ this ->assertEquals ($ addressId , $ this ->model ->assign ($ cartId , $ address , $ useForShipping ));
@@ -177,27 +122,41 @@ public function testSetAddress()
177
122
*/
178
123
public function testSetAddressWithInabilityToSaveQuote ()
179
124
{
180
- $ this ->markTestSkipped ('MAGETWO-48531 ' );
181
- $ address = $ this ->getMock (\Magento \Quote \Model \Quote \Address::class, [], [], '' , false , false );
125
+ $ cartId = 100 ;
126
+ $ addressId = 1 ;
127
+
128
+ $ address = $ this ->getMock (
129
+ \Magento \Quote \Model \Quote \Address::class,
130
+ ['getId ' ],
131
+ [],
132
+ '' ,
133
+ false
134
+ );
135
+ $ quoteMock = $ this ->getMock (
136
+ \Magento \Quote \Model \Quote::class,
137
+ ['removeAddress ' , 'getBillingAddress ' , 'setBillingAddress ' , 'setDataChanges ' ],
138
+ [],
139
+ '' ,
140
+ false
141
+ );
182
142
183
- $ quoteMock = $ this ->getMock (\Magento \Quote \Model \Quote::class, [], [], '' , false );
184
143
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
185
144
->method ('getActive ' )
186
- ->with (' cartId ' )
187
- ->will ( $ this -> returnValue ( $ quoteMock) );
145
+ ->with ($ cartId )
146
+ ->willReturn ( $ quoteMock );
188
147
189
- $ this ->validatorMock ->expects ($ this ->once ())->method ('validate ' )
190
- ->with ($ address )
191
- ->will ($ this ->returnValue (true ));
148
+ $ address ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ addressId );
149
+ $ quoteMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ address );
150
+ $ quoteMock ->expects ($ this ->once ())->method ('removeAddress ' )->with ($ addressId )->willReturnSelf ();
151
+ $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address )->willReturnSelf ();
152
+ $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (1 )->willReturnSelf ();
192
153
193
- $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address );
194
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
195
154
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
196
155
->method ('save ' )
197
156
->with ($ quoteMock )
198
157
->willThrowException (
199
158
new \Exception ('Some DB Error ' )
200
159
);
201
- $ this ->model ->assign (' cartId ' , $ address );
160
+ $ this ->model ->assign ($ cartId , $ address );
202
161
}
203
162
}
0 commit comments