Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ResetQuoteAddressesTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
20 class ResetQuoteAddressesTest extends \PHPUnit\Framework\TestCase
21 {
27  public function testAfterRemoveItem(): void
28  {
30  $quote = Bootstrap::getObjectManager()->create(Quote::class);
31  $quote->load('test_order_with_virtual_product', 'reserved_order_id');
33  $quoteBillingAddress = Bootstrap::getObjectManager()->create(QuoteAddress::class);
34  $quoteBillingAddress->setRegion('CA')
35  ->setPostcode('90210')
36  ->setFirstname('a_unique_firstname')
37  ->setLastname('lastname')
38  ->setStreet('street')
39  ->setCity('Beverly Hills')
40  ->setEmail('[email protected]')
41  ->setTelephone('1111111111')
42  ->setCountryId('US')
43  ->setAddressType('billing');
44 
46  $billingAddressManagement = Bootstrap::getObjectManager()->create(BillingAddressManagement::class);
47  $billingAddressManagement->assign($quote->getId(), $quoteBillingAddress);
49  $checkoutSession = Bootstrap::getObjectManager()->create(Session::class);
50  $checkoutSession->setQuoteId($quote->getId());
52  $cart = Bootstrap::getObjectManager()->create(Cart::class);
53 
54  $activeQuote = $cart->getQuote();
55  // Dummy data is still persisted here. This is sufficient to check that it is removed
56  $activeQuote->getExtensionAttributes()->setShippingAssignments(['test']);
57 
58  $cart->removeItem($activeQuote->getAllVisibleItems()[0]->getId());
59  $cart->save();
60 
61  // Check that the shipping assignments were also unset
62  $this->assertEmpty($activeQuote->getExtensionAttributes()->getShippingAssignments());
63 
65  $quote = Bootstrap::getObjectManager()->create(Quote::class);
66  $quote->load('test_order_with_virtual_product', 'reserved_order_id');
67  $quoteBillingAddressUpdated = $quote->getBillingAddress();
68  $customer = $quote->getCustomer();
69 
70  $this->assertEquals($quoteBillingAddressUpdated->getEmail(), $customer->getEmail());
71  $this->assertEmpty($quoteBillingAddressUpdated->getCountryId());
72  $this->assertEmpty($quoteBillingAddressUpdated->getRegionId());
73  $this->assertEmpty($quoteBillingAddressUpdated->getRegion());
74  $this->assertEmpty($quoteBillingAddressUpdated->getPostcode());
75  $this->assertEmpty($quoteBillingAddressUpdated->getCity());
76  }
77 }
$customer
Definition: customers.php:11
$quote