/** * @param \Magento\Catalog\Block\Product\View $subject * @param bool $result * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterCanEmailToFriend(\Magento\Catalog\Block\Product\View $subject, $result) { if (!$result) { $result = $this->_sendfriend->canEmailToFriend(); } return $result; }
public function testGetSentCountWithCheckCookie() { $cookieName = 'testCookieName'; $this->sendfriendDataMock->expects($this->once())->method('getLimitBy')->with()->will($this->returnValue(\Magento\SendFriend\Helper\Data::CHECK_COOKIE)); $this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will($this->returnValue($cookieName)); $this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName); $this->assertEquals(0, $this->model->getSentCount()); }
/** * @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()); }
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()); }
/** * @param bool $isExceedLimit * @param bool $result * * @dataProvider dataProviderCanSend */ public function testCanSend($isExceedLimit, $result) { $this->sendfriendMock->expects($this->once())->method('isExceedLimit')->willReturn($isExceedLimit); $this->assertEquals($result, $this->model->canSend()); }
/** * Check if user is allowed to send * * @return boolean */ public function canSend() { return !$this->sendfriend->isExceedLimit(); }
/** * @dataProvider afterCanEmailToFriendDataSet * @param bool $result * @param string $callSendfriend */ public function testAfterCanEmailToFriend($result, $callSendfriend) { $this->sendfriendModel->expects($this->{$callSendfriend}())->method('canEmailToFriend')->will($this->returnValue(true)); $this->assertTrue($this->view->afterCanEmailToFriend($this->productView, $result)); }