/**
  * @param bool $isLoggedIn
  * @param string $userKey
  * @param int $userId
  * @dataProvider catalogProductCompareAddProductDataProvider
  * @return void
  */
 public function testCatalogProductCompareAddProduct($isLoggedIn, $userKey, $userId)
 {
     $productId = 111;
     $customerId = 222;
     $visitorId = 333;
     $viewData = ['product_id' => $productId, $userKey => $userId];
     $observerMock = $this->getObserverMock($productId);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->customerVisitorMock->expects($this->any())->method('getId')->willReturn($visitorId);
     $this->productCompModelMock->expects($this->any())->method('setData')->with($viewData)->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('calculate')->willReturnSelf();
     $this->eventSaverMock->expects($this->once())->method('save');
     $this->observer->execute($observerMock);
 }
 /**
  * @return void
  */
 public function testCustomerLoginLoggedInFalse()
 {
     $observerMock = $this->getObserverMock(111);
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
     $this->customerSessionMock->expects($this->never())->method('getCustomerId');
     $this->customerVisitorMock->expects($this->never())->method('getId');
     $this->productCompModelMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
     $this->productCompModelMock->expects($this->never())->method('calculate')->willReturnSelf();
     $this->productIndexMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
     $this->productIndexMock->expects($this->never())->method('calculate')->willReturnSelf();
     $this->observer->execute($observerMock);
 }
 public function testAfterGenerateXmlNoDepersonalize()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $this->visitorMock->expects($this->never())->method('setSkipRequestLogging');
     $this->visitorMock->expects($this->never())->method('unsetData');
     $this->sessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId');
     $this->customerMock->expects($this->never())->method('setGroupId');
     $this->sessionMock->expects($this->never())->method('setData');
     $this->customerSessionMock->expects($this->never())->method('setCustomer');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
 /**
  * @return void
  */
 public function testCatalogProductViewVisitor()
 {
     $productId = 6;
     $visitorId = 88;
     $storeId = 1;
     $expectedViewedData = ['product_id' => $productId, 'visitor_id' => $visitorId, 'store_id' => $storeId];
     $expectedEventData = ['event_type_id' => \Magento\Reports\Model\Event::EVENT_PRODUCT_VIEW, 'object_id' => $productId, 'subject_id' => $visitorId, 'subtype' => 1, 'store_id' => $storeId];
     $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(false);
     $this->customerVisitorMock->expects($this->any())->method('getId')->willReturn($visitorId);
     $this->eventSaverMock->expects($this->once())->method('save');
     $this->prepareProductIndexMock($expectedViewedData);
     $this->prepareReportEventModel($expectedEventData);
     $eventObserver = $this->getObserverMock($productId);
     $this->observer->execute($eventObserver);
 }