@@ -85,6 +85,9 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
8585 /** @var Quote |\PHPUnit_Framework_MockObject_MockObject */
8686 protected $ quote ;
8787
88+ /** @var \PHPUnit_Framework_MockObject_MockObject */
89+ protected $ collectQuote ;
90+
8891 protected function setUp ()
8992 {
9093 $ this ->prepareContext ();
@@ -117,8 +120,13 @@ protected function setUp()
117120 $ this ->customerRepository = $ this ->getMockBuilder ('Magento\Customer\Api\CustomerRepositoryInterface ' )
118121 ->getMockForAbstractClass ();
119122
123+ $ this ->collectQuote = $ this ->getMockBuilder ('Magento\Checkout\Model\Cart\CollectQuote ' )
124+ ->disableOriginalConstructor ()
125+ ->getMock ();
126+
120127 $ this ->prepareQuoteRepository ();
121128
129+
122130 $ this ->model = new Shipping (
123131 $ this ->context ,
124132 $ this ->customerSession ,
@@ -130,7 +138,8 @@ protected function setUp()
130138 $ this ->shippingMethodManager ,
131139 $ this ->addressReporitory ,
132140 $ this ->customerRepository ,
133- $ this ->quoteRepository
141+ $ this ->quoteRepository ,
142+ $ this ->collectQuote
134143 );
135144 }
136145
@@ -259,182 +268,19 @@ public function testBeforeToHtmlCustomerNotLoggedIn()
259268 ->with ('advanced/modules_disable_output/Magento_Checkout ' , ScopeInterface::SCOPE_STORE )
260269 ->willReturn (false );
261270
262- $ this ->customerSession ->expects ($ this ->once ())
263- ->method ('isLoggedIn ' )
264- ->willReturn (false );
265-
266- $ this ->assertEquals ('' , $ this ->model ->toHtml ());
267- }
268-
269- public function testBeforeToHtmlNoDefaultShippingAddress ()
270- {
271- $ customerId = 1 ;
272- $ defaultShipping = 0 ;
273-
274- $ this ->eventManager ->expects ($ this ->once ())
275- ->method ('dispatch ' )
276- ->with ('view_block_abstract_to_html_before ' , ['block ' => $ this ->model ])
277- ->willReturnSelf ();
278-
279- $ this ->scopeConfig ->expects ($ this ->once ())
280- ->method ('getValue ' )
281- ->with ('advanced/modules_disable_output/Magento_Checkout ' , ScopeInterface::SCOPE_STORE )
282- ->willReturn (false );
283-
284- $ this ->customerSession ->expects ($ this ->once ())
285- ->method ('isLoggedIn ' )
286- ->willReturn (true );
287- $ this ->customerSession ->expects ($ this ->once ())
288- ->method ('getCustomerId ' )
289- ->willReturn ($ customerId );
290-
291- $ customerData = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
292- ->setMethods ([
293- 'getDefaultShipping ' ,
294- ])
295- ->getMockForAbstractClass ();
296- $ customerData ->expects ($ this ->once ())
297- ->method ('getDefaultShipping ' )
298- ->willReturn ($ defaultShipping );
299-
300- $ this ->customerRepository ->expects ($ this ->once ())
301- ->method ('getById ' )
302- ->with ($ customerId )
303- ->willReturn ($ customerData );
304-
305- $ this ->assertEquals ('' , $ this ->model ->toHtml ());
306- }
307-
308- /**
309- * @param int $customerId
310- * @param int $defaultShipping
311- * @param int $countryId
312- * @param string $postcode
313- * @param string $region
314- * @param int $regionId
315- * @param int $quoteId
316- * @dataProvider dataProviderBeforeToHtml
317- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
318- */
319- public function testBeforeToHtml (
320- $ customerId ,
321- $ defaultShipping ,
322- $ countryId ,
323- $ postcode ,
324- $ region ,
325- $ regionId ,
326- $ quoteId
327- ) {
328- $ this ->eventManager ->expects ($ this ->once ())
329- ->method ('dispatch ' )
330- ->with ('view_block_abstract_to_html_before ' , ['block ' => $ this ->model ])
331- ->willReturnSelf ();
332-
333- $ this ->scopeConfig ->expects ($ this ->once ())
334- ->method ('getValue ' )
335- ->with ('advanced/modules_disable_output/Magento_Checkout ' , ScopeInterface::SCOPE_STORE )
336- ->willReturn (false );
337-
338- $ this ->customerSession ->expects ($ this ->once ())
339- ->method ('isLoggedIn ' )
340- ->willReturn (true );
341- $ this ->customerSession ->expects ($ this ->once ())
342- ->method ('getCustomerId ' )
343- ->willReturn ($ customerId );
344-
345- $ customerDataMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
346- ->setMethods ([
347- 'getDefaultShipping ' ,
348- ])
349- ->getMockForAbstractClass ();
350- $ customerDataMock ->expects ($ this ->once ())
351- ->method ('getDefaultShipping ' )
352- ->willReturn ($ defaultShipping );
353-
354- $ this ->customerRepository ->expects ($ this ->once ())
355- ->method ('getById ' )
356- ->with ($ customerId )
357- ->willReturn ($ customerDataMock );
358-
359- $ this ->addressReporitory ->expects ($ this ->once ())
360- ->method ('getById ' )
361- ->with ($ defaultShipping )
362- ->willReturn ($ this ->address );
363-
364- $ regionMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\RegionInterface ' )
365- ->setMethods ([
366- 'getRegion ' ,
367- ])
368- ->getMockForAbstractClass ();
369- $ regionMock ->expects ($ this ->once ())
370- ->method ('getRegion ' )
371- ->willReturn ($ region );
372-
373- $ this ->address ->expects ($ this ->once ())
374- ->method ('getCountryId ' )
375- ->willReturn ($ countryId );
376- $ this ->address ->expects ($ this ->once ())
377- ->method ('getPostcode ' )
378- ->willReturn ($ postcode );
379- $ this ->address ->expects ($ this ->once ())
380- ->method ('getRegion ' )
381- ->willReturn ($ regionMock );
382- $ this ->address ->expects ($ this ->once ())
383- ->method ('getRegionId ' )
384- ->willReturn ($ regionId );
385-
386- $ this ->estimatedAddress ->expects ($ this ->once ())
387- ->method ('setCountryId ' )
388- ->with ($ countryId )
389- ->willReturnSelf ();
390- $ this ->estimatedAddress ->expects ($ this ->once ())
391- ->method ('setPostcode ' )
392- ->with ($ postcode )
393- ->willReturnSelf ();
394- $ this ->estimatedAddress ->expects ($ this ->once ())
395- ->method ('setRegion ' )
396- ->with ($ region )
397- ->willReturnSelf ();
398- $ this ->estimatedAddress ->expects ($ this ->once ())
399- ->method ('setRegionId ' )
400- ->with ($ regionId )
401- ->willReturnSelf ();
402-
403- $ this ->checkoutSession ->expects ($ this ->once ())
271+ $ quote = $ this ->getMockBuilder ('Magento\Quote\Model\Quote ' )
272+ ->disableOriginalConstructor ()
273+ ->getMock ();
274+ $ this ->checkoutSession ->expects ($ this ->any ())
404275 ->method ('getQuote ' )
405- ->willReturn ($ this ->quote );
406-
407- $ this ->quote ->expects ($ this ->once ())
408- ->method ('getId ' )
409- ->willReturn ($ quoteId );
410-
411- $ this ->shippingMethodManager ->expects ($ this ->once ())
412- ->method ('estimateByAddress ' )
413- ->with ($ quoteId , $ this ->estimatedAddress )
414- ->willReturnSelf ();
415-
416- $ this ->quoteRepository ->expects ($ this ->once ())
417- ->method ('save ' )
418- ->with ($ this ->quote )
419- ->willReturnSelf ();
276+ ->willReturn ($ quote );
277+ $ this ->collectQuote ->expects ($ this ->once ())
278+ ->method ('collect ' )
279+ ->with ($ quote );
420280
421281 $ this ->assertEquals ('' , $ this ->model ->toHtml ());
422282 }
423283
424- /**
425- * @return array
426- */
427- public function dataProviderBeforeToHtml ()
428- {
429- return [
430- [1 , 1 , 1 , '12345 ' , '' , 1 , 1 ],
431- [1 , 1 , 1 , '12345 ' , '' , 0 , 1 ],
432- [1 , 1 , 1 , '' , '' , 0 , 1 ],
433- [1 , 1 , 1 , '12345 ' , 'California ' , 0 , 1 ],
434- [1 , 1 , 1 , '12345 ' , 'California ' , 1 , 1 ],
435- ];
436- }
437-
438284 /**
439285 * @param int $count
440286 * @param bool $expectedResult
0 commit comments