Refactor captcha session to use internal session id
[MAILPOET-2343]
This commit is contained in:
committed by
Jack Kitterhing
parent
5a33946ea8
commit
704117d37d
@@ -1,61 +1,33 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Subscription;
|
||||
|
||||
use MailPoet\Config\Session;
|
||||
use MailPoet\Subscription\CaptchaSession;
|
||||
use MailPoet\Util\Cookies;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||
|
||||
class CaptchaSessionTest extends \MailPoetTest {
|
||||
const SESSION_ID = 'ABCD';
|
||||
|
||||
/** @var CaptchaSession */
|
||||
private $captcha_session;
|
||||
|
||||
/** @var MockObject */
|
||||
private $cookies_mock;
|
||||
|
||||
function _before() {
|
||||
$this->cookies_mock = $this->createMock(Cookies::class);
|
||||
$this->captcha_session = new CaptchaSession(new WPFunctions, new Session($this->cookies_mock));
|
||||
}
|
||||
|
||||
function testIsAvailableWhenCookieExists() {
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturn('abcd');
|
||||
expect($this->captcha_session->isAvailable())->true();
|
||||
}
|
||||
|
||||
function testIsNotAvailableWhenCookieDoesntExits() {
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
expect($this->captcha_session->isAvailable())->false();
|
||||
$this->captcha_session = new CaptchaSession(new WPFunctions);
|
||||
$this->captcha_session->init(self::SESSION_ID);
|
||||
}
|
||||
|
||||
function testItCanStoreAndRetrieveFormData() {
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturn('abcd');
|
||||
$form_data = ['email' => 'email@example.com'];
|
||||
$this->captcha_session->setFormData($form_data);
|
||||
expect($this->captcha_session->getFormData())->equals($form_data);
|
||||
}
|
||||
|
||||
function testItCanStoreAndRetrieveCaptchaHash() {
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturn('abcd');
|
||||
$hash = '1234';
|
||||
$this->captcha_session->setCaptchaHash($hash);
|
||||
expect($this->captcha_session->getCaptchaHash())->equals($hash);
|
||||
}
|
||||
|
||||
function testItCanResetSessionData() {
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturn('abcd');
|
||||
$this->captcha_session->setFormData(['email' => 'email@example.com']);
|
||||
$this->captcha_session->setCaptchaHash('hash123');
|
||||
$this->captcha_session->reset();
|
||||
@@ -64,15 +36,12 @@ class CaptchaSessionTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItAssociatesDataWithSession() {
|
||||
$session1 = 'abcd';
|
||||
$session2 = 'efgh';
|
||||
$this->cookies_mock
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls($session1, $session1, $session2, $session1);
|
||||
$hash = '1234';
|
||||
$this->captcha_session->setCaptchaHash($hash);
|
||||
expect($this->captcha_session->getCaptchaHash())->equals($hash);
|
||||
$this->captcha_session->init();
|
||||
expect($this->captcha_session->getCaptchaHash())->false();
|
||||
$this->captcha_session->init(self::SESSION_ID);
|
||||
expect($this->captcha_session->getCaptchaHash())->equals($hash);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user