43 $this->storeManagerMock = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
44 ->disableOriginalConstructor()
46 $this->configMock = $this->getMockBuilder(\
Magento\Customer\Model\Config\Share::class)
47 ->disableOriginalConstructor()
49 $this->quoteRepositoryMock = $this->createMock(\
Magento\Quote\Api\CartRepositoryInterface::class);
50 $this->observerMock = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
51 ->disableOriginalConstructor()
53 $this->eventMock = $this->getMockBuilder(\
Magento\Framework\Event::class)
54 ->disableOriginalConstructor()
55 ->setMethods([
'getCustomerDataObject',
'getOrigCustomerDataObject'])
57 $this->observerMock->expects($this->any())->method(
'getEvent')->will($this->returnValue($this->eventMock));
58 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60 \
Magento\Quote\Observer\Backend\CustomerQuoteObserver::class,
62 'storeManager' => $this->storeManagerMock,
63 'config' => $this->configMock,
64 'quoteRepository' => $this->quoteRepositoryMock,
71 $customerDataObjectMock = $this->getMockBuilder(\
Magento\Customer\Api\Data\CustomerInterface::class)
72 ->disableOriginalConstructor()
74 $customerDataObjectMock->expects($this->any())
75 ->method(
'getGroupId')
76 ->will($this->returnValue(1));
77 $origCustomerDataObjectMock = $this->getMockBuilder(\
Magento\Customer\Api\Data\CustomerInterface::class)
78 ->disableOriginalConstructor()
80 $origCustomerDataObjectMock->expects($this->any())
81 ->method(
'getGroupId')
82 ->will($this->returnValue(1));
83 $this->eventMock->expects($this->any())
84 ->method(
'getCustomerDataObject')
85 ->will($this->returnValue($customerDataObjectMock));
86 $this->eventMock->expects($this->any())
87 ->method(
'getOrigCustomerDataObject')
88 ->will($this->returnValue($origCustomerDataObjectMock));
89 $this->quoteRepositoryMock->expects($this->once())
90 ->method(
'getForCustomer')
91 ->willThrowException(
new \
Magento\Framework\Exception\NoSuchEntityException());
93 $this->customerQuote->execute($this->observerMock);
101 public function testDispatch($isWebsiteScope,
$websites)
103 $this->configMock->expects($this->once())
104 ->method(
'isWebsiteScope')
105 ->will($this->returnValue($isWebsiteScope));
106 $customerDataObjectMock = $this->getMockBuilder(\
Magento\Customer\Api\Data\CustomerInterface::class)
107 ->disableOriginalConstructor()
109 $customerDataObjectMock->expects($this->any())
110 ->method(
'getGroupId')
111 ->will($this->returnValue(1));
112 $customerDataObjectMock->expects($this->any())
113 ->method(
'getWebsiteId')
114 ->will($this->returnValue(2));
115 if ($isWebsiteScope) {
117 $this->storeManagerMock->expects($this->once())
118 ->method(
'getWebsite')
122 $this->storeManagerMock->expects($this->once())
123 ->method(
'getWebsites')
126 $this->eventMock->expects($this->any())
127 ->method(
'getCustomerDataObject')
128 ->will($this->returnValue($customerDataObjectMock));
130 $quoteMock = $this->getMockBuilder(
131 \
Magento\Quote\Model\Quote::class
135 'setCustomerGroupId',
136 'getCustomerGroupId',
140 )->disableOriginalConstructor()->getMock();
142 $this->quoteRepositoryMock->expects($this->once())
143 ->method(
'getForCustomer')
144 ->will($this->returnValue($quoteMock));
145 $quoteMock->expects($this->exactly($websiteCount))
146 ->method(
'setWebsite');
147 $quoteMock->expects($this->exactly($websiteCount))
148 ->method(
'setCustomerGroupId');
149 $quoteMock->expects($this->exactly($websiteCount))
150 ->method(
'collectTotals');
151 $this->quoteRepositoryMock->expects($this->exactly($websiteCount))
154 $quoteMock->expects($this->once())
155 ->method(
'getCustomerGroupId')
157 $this->customerQuote->execute($this->observerMock);
166 [
true, [[
'website1']]],
167 [
true, [[
'website1'], [
'website2']]],
168 [
false, [
'website1']],
169 [
false, [
'website1',
'website2']],
testDispatchNoCustomerGroupChange()