Skip to content

Commit 8593165

Browse files
author
Dmytro Poperechnyy
committed
MAGETWO-34989: Implement getDefaultRedirect() method
- Unit tests for getDefaultRedirect and setRefererOrBaseUrl methods added;
1 parent 65ba9e2 commit 8593165

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Model\View\Result;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
10+
class RedirectTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/** @var \Magento\Backend\Model\View\Result\Redirect */
13+
protected $action;
14+
15+
/** @var ObjectManagerHelper */
16+
protected $objectManagerHelper;
17+
18+
/** @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
19+
protected $session;
20+
21+
/** @var \Magento\Framework\App\ActionFlag|\PHPUnit_Framework_MockObject_MockObject */
22+
protected $actionFlag;
23+
24+
/** @var \Magento\Backend\Model\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
25+
protected $urlBuilder;
26+
27+
/** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */
28+
protected $redirect;
29+
30+
protected $url = 'adminhtml/index';
31+
32+
protected function setUp()
33+
{
34+
$this->session = $this->getMock('Magento\Backend\Model\Session', [], [], '', false);
35+
$this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false);
36+
$this->urlBuilder = $this->getMock('Magento\Backend\Model\UrlInterface', [], [], '', false);
37+
$this->redirect = $this->getMock(
38+
'Magento\Framework\App\Response\RedirectInterface',
39+
[],
40+
[],
41+
'',
42+
false
43+
);
44+
$this->objectManagerHelper = new ObjectManagerHelper($this);
45+
$this->action = $this->objectManagerHelper->getObject(
46+
'Magento\Backend\Model\View\Result\Redirect',
47+
[
48+
'session' => $this->session,
49+
'actionFlag' => $this->actionFlag,
50+
'redirect' => $this->redirect,
51+
'urlBuilder' =>$this->urlBuilder,
52+
]
53+
);
54+
}
55+
56+
public function testSetRefererOrBaseUrl()
57+
{
58+
$this->urlBuilder->expects($this->once())->method('getUrl')->willReturn($this->url);
59+
$this->redirect->expects($this->once())->method('getRedirectUrl')->with($this->url)->willReturn('test string');
60+
$this->action->setRefererOrBaseUrl();
61+
}
62+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)