Use Cookies service within Session and add unit test

[MAILPOET-2248]
This commit is contained in:
Rostislav Wolny
2019-08-05 15:03:19 +02:00
committed by Jack Kitterhing
parent 881d068f8b
commit 13724898d1
6 changed files with 148 additions and 21 deletions

View File

@@ -8,13 +8,25 @@ use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberIP;
use MailPoet\Subscription\Captcha;
use MailPoet\Subscription\CaptchaSession;
use MailPoet\Util\Cookies;
use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WP\Functions;
class CaptchaTest extends \MailPoetTest {
/** @var Captcha */
private $captcha;
/** @var CaptchaSession */
private $captcha_session;
function _before() {
$this->captcha = new Captcha(new WPFunctions);
$cookies_mock = $this->createMock(Cookies::class);
$cookies_mock->method('get')->willReturn('abcd');
$this->captcha_session = new CaptchaSession(new Functions(), new Session($cookies_mock));
$this->captcha = new Captcha(new WPFunctions, $this->captcha_session);
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$this->captcha_session->reset();
}
function testItDoesNotRequireCaptchaForTheFirstSubscription() {
@@ -42,13 +54,11 @@ class CaptchaTest extends \MailPoetTest {
expect($result)->equals(true);
}
function testItRendersImage() {
$_COOKIE[Session::COOKIE_NAME] = 'abcd';
$captcha_session = new CaptchaSession(new Functions(), new Session());
expect($captcha_session->getCaptchaHash())->false();
function testItRendersImageAndStoresHashToSession() {
expect($this->captcha_session->getCaptchaHash())->false();
$image = $this->captcha->renderImage(null, null, true);
expect($image)->notEmpty();
expect($captcha_session->getCaptchaHash())->notEmpty();
expect($this->captcha_session->getCaptchaHash())->notEmpty();
}
function _after() {