|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Sales\Controller\Guest; |
| 7 | + |
| 8 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 9 | + |
| 10 | +class ViewTest extends \PHPUnit_Framework_TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @var \Magento\Sales\Controller\Guest\View |
| 14 | + */ |
| 15 | + protected $viewController; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \Magento\TestFramework\Helper\ObjectManager |
| 19 | + */ |
| 20 | + protected $objectManagerHelper; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Framework\App\Action\Context |
| 24 | + */ |
| 25 | + protected $context; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + protected $requestMock; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var \Magento\Sales\Helper\Guest|\PHPUnit_Framework_MockObject_MockObject |
| 34 | + */ |
| 35 | + protected $guestHelperMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject |
| 39 | + */ |
| 40 | + protected $resultRedirectMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject |
| 44 | + */ |
| 45 | + protected $resultPageFactoryMock; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject |
| 49 | + */ |
| 50 | + protected $resultPageMock; |
| 51 | + |
| 52 | + /** |
| 53 | + * @return void |
| 54 | + */ |
| 55 | + protected function setUp() |
| 56 | + { |
| 57 | + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') |
| 58 | + ->getMock(); |
| 59 | + $this->guestHelperMock = $this->getMockBuilder('Magento\Sales\Helper\Guest') |
| 60 | + ->disableOriginalConstructor() |
| 61 | + ->getMock(); |
| 62 | + $this->resultRedirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') |
| 63 | + ->disableOriginalConstructor() |
| 64 | + ->getMock(); |
| 65 | + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') |
| 66 | + ->disableOriginalConstructor() |
| 67 | + ->setMethods(['create']) |
| 68 | + ->getMock(); |
| 69 | + $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') |
| 70 | + ->disableOriginalConstructor() |
| 71 | + ->getMock(); |
| 72 | + |
| 73 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 74 | + $this->context = $this->objectManagerHelper->getObject( |
| 75 | + 'Magento\Framework\App\Action\Context', |
| 76 | + [ |
| 77 | + 'request' => $this->requestMock |
| 78 | + ] |
| 79 | + ); |
| 80 | + $this->viewController = $this->objectManagerHelper->getObject( |
| 81 | + 'Magento\Sales\Controller\Guest\View', |
| 82 | + [ |
| 83 | + 'context' => $this->context, |
| 84 | + 'guestHelper' => $this->guestHelperMock, |
| 85 | + 'resultPageFactory' => $this->resultPageFactoryMock |
| 86 | + ] |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return void |
| 92 | + */ |
| 93 | + public function testExecuteOrderLoaded() |
| 94 | + { |
| 95 | + $this->guestHelperMock->expects($this->once()) |
| 96 | + ->method('loadValidOrder') |
| 97 | + ->with($this->requestMock) |
| 98 | + ->willReturn(true); |
| 99 | + $this->resultPageFactoryMock->expects($this->once()) |
| 100 | + ->method('create') |
| 101 | + ->willReturn($this->resultPageMock); |
| 102 | + $this->guestHelperMock->expects($this->once()) |
| 103 | + ->method('getBreadcrumbs') |
| 104 | + ->with($this->resultPageMock); |
| 105 | + |
| 106 | + $this->assertSame($this->resultPageMock, $this->viewController->execute()); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * @return void |
| 111 | + */ |
| 112 | + public function testExecuteOrderNotFound() |
| 113 | + { |
| 114 | + $this->guestHelperMock->expects($this->once()) |
| 115 | + ->method('loadValidOrder') |
| 116 | + ->with($this->requestMock) |
| 117 | + ->willReturn($this->resultRedirectMock); |
| 118 | + |
| 119 | + $this->assertSame($this->resultRedirectMock, $this->viewController->execute()); |
| 120 | + } |
| 121 | +} |
0 commit comments