6
6
7
7
namespace Magento \Framework \Controller \Test \Unit \Result ;
8
8
9
- use Magento \Framework \App \Response \HttpInterface as HttpResponseInterface ;
9
+ use \PHPUnit \Framework \TestCase ;
10
+ use \Magento \Framework \App \Response \HttpInterface as HttpResponseInterface ;
11
+ use \Magento \Framework \App \Response \RedirectInterface ;
10
12
use \Magento \Framework \Controller \Result \Redirect ;
13
+ use \Magento \Framework \UrlInterface ;
11
14
12
- class RedirectTest extends \ PHPUnit \ Framework \ TestCase
15
+ class RedirectTest extends TestCase
13
16
{
14
17
/** @var \Magento\Framework\Controller\Result\Redirect */
15
18
protected $ redirect ;
@@ -28,9 +31,9 @@ class RedirectTest extends \PHPUnit\Framework\TestCase
28
31
29
32
protected function setUp ()
30
33
{
31
- $ this ->redirectInterface = $ this ->createMock (\ Magento \ Framework \ App \ Response \ RedirectInterface::class);
32
- $ this ->urlBuilder = $ this ->createMock (\ Magento \ Framework \ UrlInterface::class);
33
- $ this ->urlInterface = $ this ->createMock (\ Magento \ Framework \ UrlInterface::class);
34
+ $ this ->redirectInterface = $ this ->createMock (RedirectInterface::class);
35
+ $ this ->urlBuilder = $ this ->createMock (UrlInterface::class);
36
+ $ this ->urlInterface = $ this ->createMock (UrlInterface::class);
34
37
$ this ->response = $ this ->createMock (HttpResponseInterface::class);
35
38
$ this ->redirect = new Redirect ($ this ->redirectInterface , $ this ->urlInterface );
36
39
}
@@ -39,7 +42,7 @@ public function testSetRefererUrl()
39
42
{
40
43
$ this ->redirectInterface ->expects ($ this ->once ())->method ('getRefererUrl ' );
41
44
$ this ->assertInstanceOf (
42
- \ Magento \ Framework \ Controller \ Result \ Redirect::class,
45
+ Redirect::class,
43
46
$ this ->redirect ->setRefererUrl ()
44
47
);
45
48
}
@@ -48,15 +51,15 @@ public function testSetRefererOrBaseUrl()
48
51
{
49
52
$ this ->redirectInterface ->expects ($ this ->once ())->method ('getRedirectUrl ' );
50
53
$ this ->assertInstanceOf (
51
- \ Magento \ Framework \ Controller \ Result \ Redirect::class,
54
+ Redirect::class,
52
55
$ this ->redirect ->setRefererOrBaseUrl ()
53
56
);
54
57
}
55
58
56
59
public function testSetUrl ()
57
60
{
58
61
$ url = 'http://test.com ' ;
59
- $ this ->assertInstanceOf (\ Magento \ Framework \ Controller \ Result \ Redirect::class, $ this ->redirect ->setUrl ($ url ));
62
+ $ this ->assertInstanceOf (Redirect::class, $ this ->redirect ->setUrl ($ url ));
60
63
}
61
64
62
65
public function testSetPath ()
@@ -67,17 +70,36 @@ public function testSetPath()
67
70
$ this ->returnValue ($ params )
68
71
);
69
72
$ this ->assertInstanceOf (
70
- \ Magento \ Framework \ Controller \ Result \ Redirect::class,
73
+ Redirect::class,
71
74
$ this ->redirect ->setPath ($ path , $ params )
72
75
);
73
76
}
74
77
75
- public function testRender ()
78
+ public function httpRedirectResponseStatusCodes ()
76
79
{
77
- $ this ->response ->expects ($ this ->once ())->method ('setRedirect ' );
78
- $ this ->assertInstanceOf (
79
- \Magento \Framework \Controller \Result \Redirect::class,
80
- $ this ->redirect ->renderResult ($ this ->response )
81
- );
80
+ return [
81
+ [302 , null ],
82
+ [302 , 302 ],
83
+ [303 , 303 ]
84
+ ];
85
+ }
86
+
87
+ /**
88
+ * @param int $expectedStatusCode
89
+ * @param int|null $actualStatusCode
90
+ * @dataProvider httpRedirectResponseStatusCodes
91
+ */
92
+ public function testRender ($ expectedStatusCode , $ actualStatusCode )
93
+ {
94
+ $ url = 'http://test.com ' ;
95
+ $ this ->redirect ->setUrl ($ url );
96
+ $ this ->redirect ->setHttpResponseCode ($ actualStatusCode );
97
+
98
+ $ this ->response
99
+ ->expects ($ this ->once ())
100
+ ->method ('setRedirect ' )
101
+ ->with ($ url , $ expectedStatusCode );
102
+
103
+ $ this ->redirect ->renderResult ($ this ->response );
82
104
}
83
105
}
0 commit comments