File tree Expand file tree Collapse file tree 5 files changed +64
-14
lines changed
Test/Unit/Controller/Index
dev/tests/integration/testsuite/Magento/Contact/Controller
lib/internal/Magento/Framework/App Expand file tree Collapse file tree 5 files changed +64
-14
lines changed Original file line number Diff line number Diff line change 12
12
use Magento \Framework \App \Request \DataPersistorInterface ;
13
13
use Magento \Framework \Controller \Result \Redirect ;
14
14
use Magento \Framework \Exception \LocalizedException ;
15
- use Magento \Framework \HTTP \PhpEnvironment \Request ;
16
15
use Psr \Log \LoggerInterface ;
17
16
use Magento \Framework \App \ObjectManager ;
18
17
use Magento \Framework \DataObject ;
@@ -67,7 +66,7 @@ public function __construct(
67
66
*/
68
67
public function execute ()
69
68
{
70
- if (!$ this ->isPostRequest ()) {
69
+ if (!$ this ->getRequest ()-> isPost ()) {
71
70
return $ this ->resultRedirectFactory ->create ()->setPath ('*/*/ ' );
72
71
}
73
72
try {
@@ -101,16 +100,6 @@ private function sendEmail($post)
101
100
);
102
101
}
103
102
104
- /**
105
- * @return bool
106
- */
107
- private function isPostRequest ()
108
- {
109
- /** @var Request $request */
110
- $ request = $ this ->getRequest ();
111
- return !empty ($ request ->getPostValue ());
112
- }
113
-
114
103
/**
115
104
* @return array
116
105
* @throws \Exception
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ protected function setUp()
78
78
$ this ->createMock (\Magento \Framework \Message \ManagerInterface::class);
79
79
$ this ->requestStub = $ this ->createPartialMock (
80
80
\Magento \Framework \App \Request \Http::class,
81
- ['getPostValue ' , 'getParams ' , 'getParam ' ]
81
+ ['getPostValue ' , 'getParams ' , 'getParam ' , ' isPost ' ]
82
82
);
83
83
$ this ->redirectResultMock = $ this ->createMock (\Magento \Framework \Controller \Result \Redirect::class);
84
84
$ this ->redirectResultMock ->method ('setPath ' )->willReturnSelf ();
@@ -174,6 +174,10 @@ public function testExecuteValidPost()
174
174
*/
175
175
private function stubRequestPostData ($ post )
176
176
{
177
+ $ this ->requestStub
178
+ ->expects ($ this ->once ())
179
+ ->method ('isPost ' )
180
+ ->willReturn (!empty ($ post ));
177
181
$ this ->requestStub ->method ('getPostValue ' )->willReturn ($ post );
178
182
$ this ->requestStub ->method ('getParams ' )->willReturn ($ post );
179
183
$ this ->requestStub ->method ('getParam ' )->willReturnCallback (
Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \Contact \Controller ;
7
7
8
+ use Zend \Http \Request ;
9
+
8
10
/**
9
11
* Contact index controller test
10
12
*/
@@ -19,6 +21,7 @@ public function testPostAction()
19
21
'hideit ' => '' ,
20
22
];
21
23
$ this ->getRequest ()->setPostValue ($ params );
24
+ $ this ->getRequest ()->setMethod (Request::METHOD_POST );
22
25
23
26
$ this ->dispatch ('contact/index/post ' );
24
27
$ this ->assertRedirect ($ this ->stringContains ('contact/index ' ));
@@ -38,6 +41,7 @@ public function testPostAction()
38
41
public function testInvalidPostAction ($ params , $ expectedMessage )
39
42
{
40
43
$ this ->getRequest ()->setPostValue ($ params );
44
+ $ this ->getRequest ()->setMethod (Request::METHOD_POST );
41
45
42
46
$ this ->dispatch ('contact/index/post ' );
43
47
$ this ->assertRedirect ($ this ->stringContains ('contact/index ' ));
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Framework \App ;
8
+
9
+ interface HttpRequestInterface
10
+ {
11
+ /**
12
+ * Returned true if POST request
13
+ *
14
+ * @return boolean
15
+ */
16
+ public function isPost ();
17
+
18
+ /**
19
+ * Returned true if GET request
20
+ *
21
+ * @return boolean
22
+ */
23
+ public function isGet ();
24
+
25
+ /**
26
+ * Returned true if PATCH request
27
+ *
28
+ * @return boolean
29
+ */
30
+ public function isPatch ();
31
+
32
+ /**
33
+ * Returned true if DELETE request
34
+ *
35
+ * @return boolean
36
+ */
37
+ public function isDelete ();
38
+
39
+ /**
40
+ * Returned true if PUT request
41
+ *
42
+ * @return boolean
43
+ */
44
+ public function isPut ();
45
+
46
+ /**
47
+ * Returned true if Ajax request
48
+ *
49
+ * @return boolean
50
+ */
51
+ public function isAjax ();
52
+ }
Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \Framework \App \Request ;
7
7
8
+ use Magento \Framework \App \HttpRequestInterface ;
8
9
use Magento \Framework \App \RequestContentInterface ;
9
10
use Magento \Framework \App \RequestSafetyInterface ;
10
11
use Magento \Framework \App \Route \ConfigInterface \Proxy as ConfigInterface ;
16
17
/**
17
18
* Http request
18
19
*/
19
- class Http extends Request implements RequestContentInterface, RequestSafetyInterface
20
+ class Http extends Request implements RequestContentInterface, RequestSafetyInterface, HttpRequestInterface
20
21
{
21
22
/**#@+
22
23
* HTTP Ports
You can’t perform that action at this time.
0 commit comments