Files
piratepoet/mailpoet/tests/integration/Subscription/Captcha/CaptchaSessionTest.php
Jan Jakes 71d7f46718 Make captcha session stateless
[MAILPOET-6038]
2024-08-05 13:28:52 +02:00

37 lines
1.3 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Test\Subscription\Captcha;
use MailPoet\Subscription\Captcha\CaptchaSession;
use MailPoet\WP\Functions as WPFunctions;
class CaptchaSessionTest extends \MailPoetTest {
const SESSION_ID = 'ABCD';
private CaptchaSession $captchaSession;
public function _before() {
$this->captchaSession = new CaptchaSession(new WPFunctions);
}
public function testItCanStoreAndRetrieveFormData() {
$formData = ['email' => 'email@example.com'];
$this->captchaSession->setFormData(self::SESSION_ID, $formData);
verify($this->captchaSession->getFormData(self::SESSION_ID))->equals($formData);
}
public function testItCanStoreAndRetrieveCaptchaHash() {
$hash = '1234';
$this->captchaSession->setCaptchaHash(self::SESSION_ID, $hash);
verify($this->captchaSession->getCaptchaHash(self::SESSION_ID))->equals($hash);
}
public function testItCanResetSessionData() {
$this->captchaSession->setFormData(self::SESSION_ID, ['email' => 'email@example.com']);
$this->captchaSession->setCaptchaHash(self::SESSION_ID, 'hash123');
$this->captchaSession->reset(self::SESSION_ID);
verify($this->captchaSession->getFormData(self::SESSION_ID))->false();
verify($this->captchaSession->getCaptchaHash(self::SESSION_ID))->false();
}
}