Refactor getCaptchaImageUrl to instance method

[MAILPOET-2381]
This commit is contained in:
Rostislav Wolny
2019-09-23 14:31:15 +02:00
committed by Jack Kitterhing
parent 54632b20c2
commit 14cf67d556
3 changed files with 9 additions and 5 deletions

View File

@@ -17,10 +17,14 @@ class CaptchaRenderer {
/** @var CaptchaSession */
private $captcha_session;
function __construct(UrlHelper $url_helper, WPFunctions $wp, CaptchaSession $captcha_session) {
/** @var Url */
private $subscription_url_factory;
function __construct(UrlHelper $url_helper, WPFunctions $wp, CaptchaSession $captcha_session, Url $subscription_url_factory) {
$this->url_helper = $url_helper;
$this->wp = $wp;
$this->captcha_session = $captcha_session;
$this->subscription_url_factory = $subscription_url_factory;
}
public function getCaptchaPageTitle() {
@@ -91,7 +95,7 @@ class CaptchaRenderer {
$width = 220;
$height = 60;
$captcha_url = Url::getCaptchaImageUrl($width, $height);
$captcha_url = $this->subscription_url_factory->getCaptchaImageUrl($width, $height);
$form_html .= '<div class="mailpoet_form_hide_on_success">';
$form_html .= '<p class="mailpoet_paragraph">';

View File

@@ -26,8 +26,8 @@ class Url {
return self::getSubscriptionUrl($post, 'captcha', null);
}
static function getCaptchaImageUrl($width, $height) {
$post = self::getPost(self::getSetting('subscription.pages.captcha'));
function getCaptchaImageUrl($width, $height) {
$post = self::getPost($this->settings->get('subscription.pages.captcha'));
return self::getSubscriptionUrl($post, 'captchaImage', null, ['width' => $width, 'height' => $height]);
}

View File

@@ -55,7 +55,7 @@ class UrlTest extends \MailPoetTest {
}
function testItReturnsTheCaptchaImageUrl() {
$url = Url::getCaptchaImageUrl(250, 100);
$url = $this->url->getCaptchaImageUrl(250, 100);
expect($url)->notNull();
expect($url)->contains('action=captchaImage');
expect($url)->contains('endpoint=subscription');