Refactor getCaptchaUrl to instance method
[MAILPOET-2381]
This commit is contained in:
committed by
Jack Kitterhing
parent
3d78d6b550
commit
54632b20c2
@ -65,6 +65,9 @@ class Subscribers extends APIEndpoint {
|
||||
/** @var ConfirmationEmailMailer; */
|
||||
private $confirmation_email_mailer;
|
||||
|
||||
/** @var SubscriptionUrl */
|
||||
private $subscription_url_factory;
|
||||
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action_controller,
|
||||
SubscribersListings $subscribers_listings,
|
||||
@ -75,7 +78,8 @@ class Subscribers extends APIEndpoint {
|
||||
WPFunctions $wp,
|
||||
SettingsController $settings,
|
||||
CaptchaSession $captcha_session,
|
||||
ConfirmationEmailMailer $confirmation_email_mailer
|
||||
ConfirmationEmailMailer $confirmation_email_mailer,
|
||||
SubscriptionUrl $subscription_url_factory
|
||||
) {
|
||||
$this->bulk_action_controller = $bulk_action_controller;
|
||||
$this->subscribers_listings = $subscribers_listings;
|
||||
@ -87,6 +91,7 @@ class Subscribers extends APIEndpoint {
|
||||
$this->settings = $settings;
|
||||
$this->captcha_session = $captcha_session;
|
||||
$this->confirmation_email_mailer = $confirmation_email_mailer;
|
||||
$this->subscription_url_factory = $subscription_url_factory;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
@ -279,7 +284,7 @@ class Subscribers extends APIEndpoint {
|
||||
$is_builtin_captcha_required = $this->subscription_captcha->isRequired(isset($data['email']) ? $data['email'] : '');
|
||||
if ($is_builtin_captcha_required && empty($data['captcha'])) {
|
||||
$meta = [];
|
||||
$meta['redirect_url'] = SubscriptionUrl::getCaptchaUrl();
|
||||
$meta['redirect_url'] = $this->subscription_url_factory->getCaptchaUrl();
|
||||
return $this->badRequest([
|
||||
APIError::BAD_REQUEST => WPFunctions::get()->__('Please fill in the CAPTCHA.', 'mailpoet'),
|
||||
], $meta);
|
||||
|
@ -10,8 +10,19 @@ use MailPoet\Subscribers\LinkTokens;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Url {
|
||||
static function getCaptchaUrl() {
|
||||
$post = self::getPost(self::getSetting('subscription.pages.captcha'));
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
/** @var SettingsController */
|
||||
private $settings;
|
||||
|
||||
public function __construct(WPFunctions $wp, SettingsController $settings) {
|
||||
$this->wp = $wp;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
function getCaptchaUrl() {
|
||||
$post = self::getPost($this->settings->get('subscription.pages.captcha'));
|
||||
return self::getSubscriptionUrl($post, 'captcha', null);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ use MailPoet\Subscribers\Source;
|
||||
use MailPoet\Subscribers\SubscriberActions;
|
||||
use MailPoet\Subscription\Captcha;
|
||||
use MailPoet\Subscription\CaptchaSession;
|
||||
use MailPoet\Subscription\Url;
|
||||
use MailPoet\Util\Cookies;
|
||||
use MailPoet\WP\Functions;
|
||||
|
||||
@ -51,6 +52,8 @@ class SubscribersTest extends \MailPoetTest {
|
||||
->willReturn('abcd');
|
||||
$session = new Session($cookies_mock);
|
||||
$container = ContainerWrapper::getInstance();
|
||||
$settings = $container->get(SettingsController::class);
|
||||
$wp = $container->get(Functions::class);
|
||||
$this->captcha_session = new CaptchaSession($container->get(Functions::class), $session);
|
||||
$this->endpoint = new Subscribers(
|
||||
$container->get(BulkActionController::class),
|
||||
@ -59,10 +62,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$container->get(RequiredCustomFieldValidator::class),
|
||||
$container->get(Handler::class),
|
||||
$container->get(Captcha::class),
|
||||
$container->get(Functions::class),
|
||||
$container->get(SettingsController::class),
|
||||
$wp,
|
||||
$settings,
|
||||
$this->captcha_session,
|
||||
$container->get(ConfirmationEmailMailer::class)
|
||||
$container->get(ConfirmationEmailMailer::class),
|
||||
new Url($wp, $settings)
|
||||
);
|
||||
$obfuscator = new FieldNameObfuscator();
|
||||
$this->obfuscatedEmail = $obfuscator->obfuscate('email');
|
||||
|
@ -15,6 +15,13 @@ use MailPoet\WooCommerce\TransactionalEmails;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class UrlTest extends \MailPoetTest {
|
||||
|
||||
/** @var Url */
|
||||
private $url;
|
||||
|
||||
/** @var SettingsController */
|
||||
private $settings;
|
||||
|
||||
function _before() {
|
||||
parent::_before();
|
||||
$this->settings = new SettingsController;
|
||||
@ -23,12 +30,13 @@ class UrlTest extends \MailPoetTest {
|
||||
$wc_transactional_emails = new TransactionalEmails(WPFunctions::get(), $this->settings);
|
||||
$populator = new Populator($this->settings, WPFunctions::get(), new Captcha, $referral_detector, $features_controller, $wc_transactional_emails);
|
||||
$populator->up();
|
||||
$this->url = new Url(WPFunctions::get(), $this->settings);
|
||||
}
|
||||
|
||||
function testItReturnsTheDefaultPageUrlIfNoPageIsSetInSettings() {
|
||||
$this->settings->delete('subscription');
|
||||
|
||||
$url = Url::getCaptchaUrl();
|
||||
$url = $this->url->getCaptchaUrl();
|
||||
expect($url)->notNull();
|
||||
expect($url)->contains('action=captcha');
|
||||
expect($url)->contains('endpoint=subscription');
|
||||
@ -40,7 +48,7 @@ class UrlTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItReturnsTheCaptchaUrl() {
|
||||
$url = Url::getCaptchaUrl();
|
||||
$url = $this->url->getCaptchaUrl();
|
||||
expect($url)->notNull();
|
||||
expect($url)->contains('action=captcha');
|
||||
expect($url)->contains('endpoint=subscription');
|
||||
|
Reference in New Issue
Block a user