|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Wishlist\Controller\Index; |
| 8 | + |
| 9 | +class PluginTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject |
| 13 | + */ |
| 14 | + protected $customerSession; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \Magento\Wishlist\Model\AuthenticationStateInterface|\PHPUnit_Framework_MockObject_MockObject |
| 18 | + */ |
| 19 | + protected $authenticationState; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + protected $config; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + protected $redirector; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + protected $request; |
| 35 | + |
| 36 | + protected function setUp() |
| 37 | + { |
| 38 | + $this->customerSession = $this->getMock('Magento\Customer\Model\Session', [], [], '', false); |
| 39 | + $this->authenticationState = $this->getMock('Magento\Wishlist\Model\AuthenticationState', [], [], '', false); |
| 40 | + $this->config = $this->getMock('Magento\Framework\App\Config', [], [], '', false); |
| 41 | + $this->redirector = $this->getMock('\Magento\Store\App\Response\Redirect', [], [], '', false); |
| 42 | + $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); |
| 43 | + } |
| 44 | + |
| 45 | + protected function tearDown() |
| 46 | + { |
| 47 | + unset( |
| 48 | + $this->customerSession, |
| 49 | + $this->authenticationState, |
| 50 | + $this->config, |
| 51 | + $this->redirector, |
| 52 | + $this->request |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + protected function getPlugin() |
| 57 | + { |
| 58 | + return new \Magento\Wishlist\Controller\Index\Plugin( |
| 59 | + $this->customerSession, |
| 60 | + $this->authenticationState, |
| 61 | + $this->config, |
| 62 | + $this->redirector |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + public function testBeforeDispatch() |
| 67 | + { |
| 68 | + $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); |
| 69 | + |
| 70 | + $actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); |
| 71 | + $indexController = $this->getMock('Magento\Wishlist\Controller\Index\Index', [], [], '', false); |
| 72 | + |
| 73 | + $actionFlag |
| 74 | + ->expects($this->once()) |
| 75 | + ->method('set') |
| 76 | + ->with('', 'no-dispatch', true) |
| 77 | + ->willReturn(true); |
| 78 | + |
| 79 | + $indexController |
| 80 | + ->expects($this->once()) |
| 81 | + ->method('getActionFlag') |
| 82 | + ->willReturn($actionFlag); |
| 83 | + |
| 84 | + $this->authenticationState |
| 85 | + ->expects($this->once()) |
| 86 | + ->method('isEnabled') |
| 87 | + ->willReturn(true); |
| 88 | + |
| 89 | + $this->customerSession |
| 90 | + ->expects($this->once()) |
| 91 | + ->method('authenticate') |
| 92 | + ->with($indexController) |
| 93 | + ->willReturn(false); |
| 94 | + |
| 95 | + $this->redirector |
| 96 | + ->expects($this->once()) |
| 97 | + ->method('getRefererUrl') |
| 98 | + ->willReturn('http://referer-url.com'); |
| 99 | + |
| 100 | + $this->request |
| 101 | + ->expects($this->once()) |
| 102 | + ->method('getParams') |
| 103 | + ->willReturn(['product' => 1]); |
| 104 | + |
| 105 | + $this->customerSession |
| 106 | + ->expects($this->at(1)) |
| 107 | + ->method('__call') |
| 108 | + ->with('getBeforeWishlistUrl', []) |
| 109 | + ->willReturn(false); |
| 110 | + $this->customerSession |
| 111 | + ->expects($this->at(2)) |
| 112 | + ->method('__call') |
| 113 | + ->with('setBeforeWishlistUrl', ['http://referer-url.com']) |
| 114 | + ->willReturn(false); |
| 115 | + $this->customerSession |
| 116 | + ->expects($this->at(3)) |
| 117 | + ->method('__call') |
| 118 | + ->with('setBeforeWishlistRequest', [['product' => 1]]) |
| 119 | + ->willReturn(true); |
| 120 | + |
| 121 | + $this->config |
| 122 | + ->expects($this->once()) |
| 123 | + ->method('isSetFlag') |
| 124 | + ->with('wishlist/general/active') |
| 125 | + ->willReturn(false); |
| 126 | + |
| 127 | + $this->getPlugin()->beforeDispatch($indexController, $this->request); |
| 128 | + } |
| 129 | +} |
0 commit comments