58 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60 $this->customerSessionMock = $this->getMockBuilder(\
Magento\Customer\Model\Session::class)
61 ->disableOriginalConstructor()->getMock();
62 $this->customerVisitorMock = $this->getMockBuilder(\
Magento\Customer\Model\Visitor::class)
63 ->disableOriginalConstructor()->getMock();
65 $this->productIndexFactoryMock = $this->getMockBuilder(
66 \
Magento\Reports\Model\Product\Index\ViewedFactory::class
67 )->setMethods([
'create'])
68 ->disableOriginalConstructor()->getMock();
69 $this->productIndexMock = $this->getMockBuilder(\
Magento\Reports\Model\Product\Index\Viewed::class)
70 ->disableOriginalConstructor()->getMock();
72 $this->productIndexFactoryMock->expects($this->any())
74 ->willReturn($this->productIndexMock);
76 $reportEventFactory = $this->getMockBuilder(\
Magento\Reports\Model\EventFactory::class)
77 ->setMethods([
'create'])->disableOriginalConstructor()->getMock();
78 $this->reportEventMock = $this->getMockBuilder(\
Magento\Reports\Model\Event::class)
79 ->disableOriginalConstructor()->getMock();
81 $reportEventFactory->expects($this->any())
83 ->willReturn($this->reportEventMock);
85 $this->productCompModelMock = $this->getMockBuilder(\
Magento\Reports\Model\Product\Index\Compared::class)
86 ->disableOriginalConstructor()
89 $this->productCompFactoryMock = $this->getMockBuilder(
90 \
Magento\Reports\Model\Product\Index\ComparedFactory::class
91 )->disableOriginalConstructor()
92 ->setMethods([
'create'])
94 $this->productCompFactoryMock->expects($this->any())
96 ->willReturn($this->productCompModelMock);
99 \
Magento\Reports\Observer\CustomerLoginObserver::class,
101 'event' => $reportEventFactory,
102 'productCompFactory' => $this->productCompFactoryMock,
103 'productIndexFactory' => $this->productIndexFactoryMock,
104 'customerSession' => $this->customerSessionMock,
105 'customerVisitor' => $this->customerVisitorMock,
119 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->willReturn(
true);
120 $this->customerSessionMock->expects($this->once())->method(
'getCustomerId')->willReturn(
$customerId);
122 $this->customerVisitorMock->expects($this->once())->method(
'getId')->willReturn($visitorId);
124 $this->reportEventMock->expects($this->once())->method(
'updateCustomerType')->with($visitorId,
$customerId);
126 $this->productCompModelMock->expects($this->once())->method(
'updateCustomerFromVisitor')->willReturnSelf();
127 $this->productCompModelMock->expects($this->once())->method(
'calculate')->willReturnSelf();
129 $this->productIndexMock->expects($this->once())->method(
'updateCustomerFromVisitor')->willReturnSelf();
130 $this->productIndexMock->expects($this->once())->method(
'calculate')->willReturnSelf();
132 $this->observer->execute($observerMock);
142 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->willReturn(
false);
143 $this->customerSessionMock->expects($this->never())->method(
'getCustomerId');
145 $this->customerVisitorMock->expects($this->never())->method(
'getId');
147 $this->productCompModelMock->expects($this->never())->method(
'updateCustomerFromVisitor')->willReturnSelf();
148 $this->productCompModelMock->expects($this->never())->method(
'calculate')->willReturnSelf();
150 $this->productIndexMock->expects($this->never())->method(
'updateCustomerFromVisitor')->willReturnSelf();
151 $this->productIndexMock->expects($this->never())->method(
'calculate')->willReturnSelf();
153 $this->observer->execute($observerMock);
162 $eventObserverMock = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
163 ->disableOriginalConstructor()
165 $eventMock = $this->getMockBuilder(\
Magento\Framework\Event::class)
166 ->disableOriginalConstructor()
167 ->setMethods([
'getProduct'])->getMock();
168 $productMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
169 ->disableOriginalConstructor()
172 $productMock->expects($this->any())->method(
'getId')->willReturn(
$productId);
174 $eventMock->expects($this->any())->method(
'getProduct')->willReturn($productMock);
176 $eventObserverMock->expects($this->any())->method(
'getEvent')->willReturn($eventMock);
178 return $eventObserverMock;
getObserverMock($productId)
testCustomerLoginLoggedInTrue()
testCustomerLoginLoggedInFalse()