public function testAfterGenerateXmlNoDepersonalize()
 {
     $this->catalogSessionMock->expects($this->never())->method('clearStorage');
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
     $this->assertEquals($this->resultLayout, $actualResult);
 }
示例#2
0
 public function testExecuteWithItems()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['items', null, '1,2,3'], ['uenc', null, null]]);
     $this->decoderMock->expects($this->never())->method('decode');
     $this->catalogSession->expects($this->never())->method('setBeforeCompareUrl');
     $this->listCompareMock->expects($this->once())->method('addProducts')->with([1, 2, 3]);
     $redirect = $this->getMock('Magento\\Framework\\Controller\\Result\\Redirect', ['setPath'], [], '', false);
     $redirect->expects($this->once())->method('setPath')->with('*/*/*');
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirect);
     $this->index->execute();
 }
示例#3
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithException()
 {
     $productId = 11;
     $categoryId = 5;
     $sender = 'sender';
     $recipients = 'recipients';
     $formData = ['sender' => $sender, 'recipients' => $recipients];
     $redirectUrl = 'redirect_url';
     /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]);
     /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
     $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
     $productMock->expects($this->never())->method('setCategory');
     $this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]);
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]);
     $this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
     $exception = new \Exception(__('Exception.'));
     $this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception);
     $this->sendFriendMock->expects($this->never())->method('send');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf();
     $this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl);
     $this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0);
     $redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->execute());
 }
示例#4
0
 public function testLayoutIsNotCacheable()
 {
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->willReturn(true);
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->requestMock->expects($this->once($this->once()))->method('isAjax')->willReturn(false);
     $this->layoutMock->expects($this->once())->method('isCacheable')->willReturn(false);
     $this->catalogSessionMock->expects($this->never())->method('clearStorage');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
     $this->assertEquals($this->resultLayout, $actualResult);
 }
示例#5
0
 public function testExecuteWithNoticeAndNoData()
 {
     $productId = 11;
     $formData = null;
     $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($productId);
     /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
     $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $this->registryMock->expects($this->once())->method('register')->with('product', $productMock, false);
     $this->sendFriendMock->expects($this->exactly(2))->method('getMaxSendsToFriend')->willReturn(11);
     $this->sendFriendMock->expects($this->once())->method('isExceedLimit')->willReturn(true);
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with(__('You can\'t send messages more than %1 times an hour.', 11))->willReturnSelf();
     /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject $pageMock */
     $pageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE, [])->willReturn($pageMock);
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('sendfriend_product', ['product' => $productMock]);
     $this->catalogSessionMock->expects($this->once())->method('getSendfriendFormData')->willReturn($formData);
     $this->catalogSessionMock->expects($this->never())->method('setSendfriendFormData');
     $pageMock->expects($this->never())->method('getLayout');
     $this->assertEquals($pageMock, $this->model->execute());
 }