Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RestoreCustomerGroupIdTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class RestoreCustomerGroupIdTest extends \PHPUnit\Framework\TestCase
14 {
19 
23  protected $quote;
24 
25  protected function setUp()
26  {
27  $this->customerAddressHelperMock = $this->createMock(\Magento\Customer\Helper\Address::class);
28  $this->quote = new RestoreCustomerGroupId($this->customerAddressHelperMock);
29  }
30 
35  public function testExecute($configAddressType)
36  {
37  $eventMock = $this->createPartialMock(\Magento\Framework\Event::class, ['getShippingAssignment', 'getQuote']);
38  $observer = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getEvent']);
39  $observer->expects($this->exactly(2))->method('getEvent')->willReturn($eventMock);
40 
41  $shippingAssignmentMock = $this->createMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class);
42  $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
43 
44  $eventMock->expects($this->once())->method('getShippingAssignment')->willReturn($shippingAssignmentMock);
45  $eventMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
46 
47  $shippingMock = $this->createMock(\Magento\Quote\Api\Data\ShippingInterface::class);
48  $shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
49 
50  $quoteAddress = $this->createPartialMock(
51  \Magento\Quote\Model\Quote\Address::class,
52  [
53  'getPrevQuoteCustomerGroupId',
54  'unsPrevQuoteCustomerGroupId',
55  'hasPrevQuoteCustomerGroupId',
56  'setCustomerGroupId',
57  'getQuote'
58  ]
59  );
60  $shippingMock->expects($this->once())->method('getAddress')->willReturn($quoteAddress);
61 
62  $this->customerAddressHelperMock->expects($this->once())
63  ->method('getTaxCalculationAddressType')
64  ->will($this->returnValue($configAddressType));
65 
66  $quoteAddress->expects($this->once())->method('hasPrevQuoteCustomerGroupId');
67  $id = $quoteAddress->expects($this->any())->method('getPrevQuoteCustomerGroupId');
68  $quoteAddress->expects($this->any())->method('setCustomerGroupId')->with($id);
69  $quoteAddress->expects($this->any())->method('getQuote');
70  $quoteAddress->expects($this->any())->method('unsPrevQuoteCustomerGroupId');
71 
72  $this->quote->execute($observer);
73  }
74 
79  {
80  return [
81  [\Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING],
82  [null],
83  [\Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING],
84  ];
85  }
86 }
$id
Definition: fieldset.phtml:14