Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegisterFormKeyFromCookieTest.php
Go to the documentation of this file.
1 <?php
8 declare(strict_types=1);
9 
11 
14 use PHPUnit\Framework\TestCase;
15 use Magento\Framework\App\Request\Http as HttpRequest;
16 use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
18 
19 class RegisterFormKeyFromCookieTest extends TestCase
20 {
24  private $request;
25 
29  private $frontController;
30 
34  private $formKeyValidator;
35 
39  protected function setUp()
40  {
42  $this->request = $objectManager->get(RequestInterface::class);
43  $this->frontController = $objectManager->get(
44  FrontController::class
45  );
46  $this->formKeyValidator = $objectManager->get(FormKeyValidator::class);
47  }
48 
52  public function testTakenFromCookie()
53  {
55  $this->markTestSkipped(
56  'Can\'t test dispatch process without sending headers'
57  );
58  }
59  $_SERVER['HTTP_HOST'] = 'localhost';
60  $formKey = 'customFormKey';
61  $_COOKIE['form_key'] = $formKey;
62  $this->request->setMethod(HttpRequest::METHOD_POST);
63  $this->request->setParam('form_key', $formKey);
64  $this->request->setRequestUri('core/index/index');
65  $this->frontController->dispatch($this->request);
66  $this->assertTrue($this->formKeyValidator->validate($this->request));
67  }
68 }
$objectManager
Definition: bootstrap.php:17