7 declare(strict_types=1);
19 use PHPUnit\Framework\TestCase;
22 use Zend\Stdlib\Parameters;
24 use Magento\Framework\App\Response\HttpFactory as HttpResponseFactory;
31 private const AWARE_URL =
'test/1';
33 private const AWARE_VALIDATION_PARAM =
'test_param';
35 private const AWARE_MESSAGE =
'custom validation failed';
40 private $mockUnawareAction;
45 private $mockAwareAction;
65 private $httpResponseFactory;
76 public function execute()
89 $m = self::AWARE_MESSAGE;
90 $p = self::AWARE_VALIDATION_PARAM;
113 public function __construct(
120 $this->param = $param;
126 public function execute()
134 public function createCsrfValidationException(
139 ->get(RedirectFactory::class);
140 $redirect = $redirectFactory->create();
141 $redirect->setUrl($this->url);
145 [
new Phrase($this->message)]
154 return (
bool)
$request->getParam($this->param);
167 $this->mockUnawareAction = $this->createUnawareAction();
168 $this->mockAwareAction = $this->createAwareAction();
171 HttpResponseFactory::class
180 $this->request->setMethod(HttpRequest::METHOD_POST);
181 $this->validator->validate(
183 $this->mockUnawareAction
192 $this->request->setPost(
193 new Parameters([
'form_key' => $this->formKey->getFormKey()])
195 $this->request->setMethod(HttpRequest::METHOD_POST);
197 $this->validator->validate(
199 $this->mockUnawareAction
209 $this->request->setPost(
210 new Parameters([
'form_key' => $this->formKey->getFormKey() .
'1'])
212 $this->request->setMethod(HttpRequest::METHOD_POST);
214 $this->validator->validate(
216 $this->mockUnawareAction
223 public function testValidateInvalidWithAwareAction()
225 $this->request->setMethod(HttpRequest::METHOD_POST);
230 $this->validator->validate(
232 $this->mockAwareAction
235 $caught = $exception;
238 $this->assertNotNull($caught);
239 $this->assertInstanceOf(Redirect::class, $caught->getReplaceResult());
241 $response = $this->httpResponseFactory->create();
242 $caught->getReplaceResult()->renderResult(
$response);
243 $this->assertContains(
247 $this->assertCount(1, $caught->getMessages());
250 $caught->getMessages()[0]->getText()
259 $this->request->setMethod(HttpRequest::METHOD_POST);
260 $this->request->setPost(
261 new Parameters([self::AWARE_VALIDATION_PARAM =>
'1'])
264 $this->validator->validate(
266 $this->mockAwareAction
testValidateWithValidKey()
testValidateWithInvalidKey()
testValidateValidWithAwareAction()
testValidateInWrongArea()
static getObjectManager()