|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Framework\App\Test\Unit\Action; |
| 8 | + |
| 9 | +class AbstractActionTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + /** @var \Magento\Framework\App\Action\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */ |
| 12 | + protected $action; |
| 13 | + |
| 14 | + /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 15 | + protected $request; |
| 16 | + |
| 17 | + /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 18 | + protected $response; |
| 19 | + |
| 20 | + /** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 21 | + protected $redirectFactory; |
| 22 | + |
| 23 | + /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ |
| 24 | + protected $redirect; |
| 25 | + |
| 26 | + /** @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */ |
| 27 | + protected $context; |
| 28 | + |
| 29 | + protected $expectedResult = '/index'; |
| 30 | + |
| 31 | + public function setUp() |
| 32 | + { |
| 33 | + $this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface') |
| 34 | + ->disableOriginalConstructor()->getMock(); |
| 35 | + $this->response = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); |
| 36 | + |
| 37 | + $this->redirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') |
| 38 | + ->setMethods(['setRefererOrBaseUrl']) |
| 39 | + ->disableOriginalConstructor() |
| 40 | + ->getMock(); |
| 41 | + $this->redirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') |
| 42 | + ->setMethods(['create']) |
| 43 | + ->disableOriginalConstructor() |
| 44 | + ->getMock(); |
| 45 | + $this->redirectFactory->expects($this->any()) |
| 46 | + ->method('create') |
| 47 | + ->will($this->returnValue($this->redirect)); |
| 48 | + |
| 49 | + $this->context = $this->getMockBuilder('Magento\Framework\App\Action\Context') |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->getMock(); |
| 52 | + $this->context->expects($this->any()) |
| 53 | + ->method('getResultRedirectFactory') |
| 54 | + ->willReturn($this->redirectFactory); |
| 55 | + |
| 56 | + $this->action = $this->getMockForAbstractClass('Magento\Framework\App\Action\AbstractAction', |
| 57 | + [$this->request, $this->response, $this->context] |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetDefaultRedirect() |
| 62 | + { |
| 63 | + $this->redirect->expects($this->once()) |
| 64 | + ->method('setRefererOrBaseUrl') |
| 65 | + ->willReturn('/index'); |
| 66 | + |
| 67 | + $result = $this->action->getDefaultRedirect(); |
| 68 | + $this->assertSame($this->expectedResult, $result); |
| 69 | + } |
| 70 | +} |
0 commit comments