|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Checkout\Test\Unit\Controller\Cart; |
| 7 | + |
| 8 | +use Magento\Checkout\Controller\Cart\Index; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class IndexTest |
| 12 | + */ |
| 13 | +class IndexTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var Index |
| 17 | + */ |
| 18 | + protected $controller; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \Magento\Checkout\Model\Session | \PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + protected $checkoutSession; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\Framework\App\Request\Http | \PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + protected $request; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + protected $response; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var \Magento\Quote\Model\Quote | \PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + protected $quote; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject |
| 42 | + */ |
| 43 | + protected $eventManager; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject |
| 47 | + */ |
| 48 | + protected $objectManagerMock; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 52 | + */ |
| 53 | + protected $cart; |
| 54 | + |
| 55 | + /** |
| 56 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 57 | + */ |
| 58 | + protected $scopeConfig; |
| 59 | + |
| 60 | + /** |
| 61 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 62 | + */ |
| 63 | + protected $messageManager; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 67 | + */ |
| 68 | + protected $resultPageFactory; |
| 69 | + |
| 70 | + /** |
| 71 | + * @return void |
| 72 | + */ |
| 73 | + public function setUp() |
| 74 | + { |
| 75 | + $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); |
| 76 | + $this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); |
| 77 | + $this->quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); |
| 78 | + $this->eventManager = $this->getMock('Magento\Framework\Event\Manager', [], [], '', false); |
| 79 | + $this->checkoutSession = $this->getMock('Magento\Checkout\Model\Session', [], [], '', false); |
| 80 | + |
| 81 | + $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); |
| 82 | + |
| 83 | + $this->messageManager = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface') |
| 84 | + ->disableOriginalConstructor() |
| 85 | + ->getMock(); |
| 86 | + |
| 87 | + $context = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); |
| 88 | + $context->expects($this->once()) |
| 89 | + ->method('getObjectManager') |
| 90 | + ->willReturn($this->objectManagerMock); |
| 91 | + $context->expects($this->once()) |
| 92 | + ->method('getRequest') |
| 93 | + ->willReturn($this->request); |
| 94 | + $context->expects($this->once()) |
| 95 | + ->method('getResponse') |
| 96 | + ->willReturn($this->response); |
| 97 | + $context->expects($this->once()) |
| 98 | + ->method('getEventManager') |
| 99 | + ->willReturn($this->eventManager); |
| 100 | + $context->expects($this->once()) |
| 101 | + ->method('getMessageManager') |
| 102 | + ->willReturn($this->messageManager); |
| 103 | + |
| 104 | + $this->cart = $this->getMockBuilder('Magento\Checkout\Model\Cart') |
| 105 | + ->disableOriginalConstructor() |
| 106 | + ->getMock(); |
| 107 | + $this->scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') |
| 108 | + ->disableOriginalConstructor() |
| 109 | + ->getMock(); |
| 110 | + $this->resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') |
| 111 | + ->disableOriginalConstructor() |
| 112 | + ->setMethods(['create']) |
| 113 | + ->getMock(); |
| 114 | + |
| 115 | + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 116 | + |
| 117 | + $this->controller = $objectManagerHelper->getObject( |
| 118 | + 'Magento\Checkout\Controller\Cart\Index', |
| 119 | + [ |
| 120 | + 'context' => $context, |
| 121 | + 'checkoutSession' => $this->checkoutSession, |
| 122 | + 'cart' => $this->cart, |
| 123 | + 'scopeConfig' => $this->scopeConfig, |
| 124 | + 'resultPageFactory' => $this->resultPageFactory |
| 125 | + ] |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @return void |
| 131 | + */ |
| 132 | + public function testExecuteWithMessages() |
| 133 | + { |
| 134 | + $layout = $this->getMockBuilder('Magento\Framework\View\Layout') |
| 135 | + ->disableOriginalConstructor() |
| 136 | + ->getMock(); |
| 137 | + $layout->expects($this->once()) |
| 138 | + ->method('initMessages'); |
| 139 | + |
| 140 | + $title = $this->getMockBuilder('Magento\Framework\View\Page\Title') |
| 141 | + ->disableOriginalConstructor() |
| 142 | + ->getMock(); |
| 143 | + $title->expects($this->once()) |
| 144 | + ->method('set') |
| 145 | + ->with('Shopping Cart'); |
| 146 | + |
| 147 | + $config = $this->getMockBuilder('Magento\Framework\View\Page\Config') |
| 148 | + ->disableOriginalConstructor() |
| 149 | + ->getMock(); |
| 150 | + $config->expects($this->once()) |
| 151 | + ->method('getTitle') |
| 152 | + ->willReturn($title); |
| 153 | + |
| 154 | + $page = $this->getMockBuilder('Magento\Framework\View\Result\Page') |
| 155 | + ->disableOriginalConstructor() |
| 156 | + ->getMock(); |
| 157 | + $page->expects($this->once()) |
| 158 | + ->method('getLayout') |
| 159 | + ->willReturn($layout); |
| 160 | + $page->expects($this->once()) |
| 161 | + ->method('getConfig') |
| 162 | + ->willReturn($config); |
| 163 | + |
| 164 | + $this->resultPageFactory->expects($this->once()) |
| 165 | + ->method('create') |
| 166 | + ->willReturn($page); |
| 167 | + $result = $this->controller->execute(); |
| 168 | + $this->assertInstanceOf('Magento\Framework\View\Result\Page', $result); |
| 169 | + } |
| 170 | +} |
0 commit comments