Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions app/code/Magento/Contact/Controller/Index/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\HTTP\PhpEnvironment\Request;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
Expand Down Expand Up @@ -68,7 +67,7 @@ public function __construct(
*/
public function execute()
{
if (!$this->isPostRequest()) {
if (!$this->getRequest()->isPost()) {
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
try {
Expand Down Expand Up @@ -102,16 +101,6 @@ private function sendEmail($post)
);
}

/**
* @return bool
*/
private function isPostRequest()
{
/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());
}

/**
* @return array
* @throws \Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function setUp()
$this->createMock(\Magento\Framework\Message\ManagerInterface::class);
$this->requestStub = $this->createPartialMock(
\Magento\Framework\App\Request\Http::class,
['getPostValue', 'getParams', 'getParam']
['getPostValue', 'getParams', 'getParam', 'isPost']
);
$this->redirectResultMock = $this->createMock(\Magento\Framework\Controller\Result\Redirect::class);
$this->redirectResultMock->method('setPath')->willReturnSelf();
Expand Down Expand Up @@ -177,6 +177,10 @@ public function testExecuteValidPost()
*/
private function stubRequestPostData($post)
{
$this->requestStub
->expects($this->once())
->method('isPost')
->willReturn(!empty($post));
$this->requestStub->method('getPostValue')->willReturn($post);
$this->requestStub->method('getParams')->willReturn($post);
$this->requestStub->method('getParam')->willReturnCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Contact\Controller;

use Zend\Http\Request;

/**
* Contact index controller test
*/
Expand All @@ -20,6 +22,7 @@ public function testPostAction()
'hideit' => '',
];
$this->getRequest()->setPostValue($params);
$this->getRequest()->setMethod(Request::METHOD_POST);

$this->dispatch('contact/index/post');
$this->assertRedirect($this->stringContains('contact/index'));
Expand All @@ -39,6 +42,7 @@ public function testPostAction()
public function testInvalidPostAction($params, $expectedMessage)
{
$this->getRequest()->setPostValue($params);
$this->getRequest()->setMethod(Request::METHOD_POST);

$this->dispatch('contact/index/post');
$this->assertRedirect($this->stringContains('contact/index'));
Expand Down
53 changes: 53 additions & 0 deletions lib/internal/Magento/Framework/App/HttpRequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\App;

interface HttpRequestInterface
{
/**
* Returned true if POST request
*
* @return boolean
*/
public function isPost();

/**
* Returned true if GET request
*
* @return boolean
*/
public function isGet();

/**
* Returned true if PATCH request
*
* @return boolean
*/
public function isPatch();

/**
* Returned true if DELETE request
*
* @return boolean
*/
public function isDelete();

/**
* Returned true if PUT request
*
* @return boolean
*/
public function isPut();

/**
* Returned true if Ajax request
*
* @return boolean
*/
public function isAjax();
}
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/App/Request/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Framework\App\Request;

use Magento\Framework\App\HttpRequestInterface;
use Magento\Framework\App\RequestContentInterface;
use Magento\Framework\App\RequestSafetyInterface;
use Magento\Framework\App\Route\ConfigInterface\Proxy as ConfigInterface;
Expand All @@ -16,7 +17,7 @@
/**
* Http request
*/
class Http extends Request implements RequestContentInterface, RequestSafetyInterface
class Http extends Request implements RequestContentInterface, RequestSafetyInterface, HttpRequestInterface
{
/**#@+
* HTTP Ports
Expand Down