Refactor getManageUrl to instance method
[MAILPOET-2381]
This commit is contained in:
committed by
Jack Kitterhing
parent
21fba11893
commit
4e75f8883e
@ -19,6 +19,7 @@ class Link {
|
|||||||
$content,
|
$content,
|
||||||
$wp_user_preview
|
$wp_user_preview
|
||||||
) {
|
) {
|
||||||
|
$subscription_url_factory = SubscriptionUrl::getInstance();
|
||||||
switch ($shortcode_details['action']) {
|
switch ($shortcode_details['action']) {
|
||||||
case 'subscription_unsubscribe_url':
|
case 'subscription_unsubscribe_url':
|
||||||
return self::processUrl(
|
return self::processUrl(
|
||||||
@ -31,7 +32,7 @@ class Link {
|
|||||||
case 'subscription_manage_url':
|
case 'subscription_manage_url':
|
||||||
return self::processUrl(
|
return self::processUrl(
|
||||||
$shortcode_details['action'],
|
$shortcode_details['action'],
|
||||||
SubscriptionUrl::getManageUrl($wp_user_preview ? null : $subscriber),
|
$subscription_url_factory->getManageUrl($wp_user_preview ? null : $subscriber),
|
||||||
$queue,
|
$queue,
|
||||||
$wp_user_preview
|
$wp_user_preview
|
||||||
);
|
);
|
||||||
@ -73,6 +74,7 @@ class Link {
|
|||||||
static function processShortcodeAction(
|
static function processShortcodeAction(
|
||||||
$shortcode_action, $newsletter, $subscriber, $queue, $wp_user_preview
|
$shortcode_action, $newsletter, $subscriber, $queue, $wp_user_preview
|
||||||
) {
|
) {
|
||||||
|
$subscription_url_factory = SubscriptionUrl::getInstance();
|
||||||
switch ($shortcode_action) {
|
switch ($shortcode_action) {
|
||||||
case 'subscription_unsubscribe_url':
|
case 'subscription_unsubscribe_url':
|
||||||
$settings = new SettingsController();
|
$settings = new SettingsController();
|
||||||
@ -84,7 +86,7 @@ class Link {
|
|||||||
$url = SubscriptionUrl::getUnsubscribeUrl($subscriber);
|
$url = SubscriptionUrl::getUnsubscribeUrl($subscriber);
|
||||||
break;
|
break;
|
||||||
case 'subscription_manage_url':
|
case 'subscription_manage_url':
|
||||||
$url = SubscriptionUrl::getManageUrl($subscriber);
|
$url = $subscription_url_factory->getManageUrl($subscriber);
|
||||||
break;
|
break;
|
||||||
case 'newsletter_view_in_browser_url':
|
case 'newsletter_view_in_browser_url':
|
||||||
$url = NewsletterUrl::getViewInBrowserUrl(
|
$url = NewsletterUrl::getViewInBrowserUrl(
|
||||||
|
@ -48,6 +48,9 @@ class Pages {
|
|||||||
/** @var LinkTokens */
|
/** @var LinkTokens */
|
||||||
private $link_tokens;
|
private $link_tokens;
|
||||||
|
|
||||||
|
/** @var Url */
|
||||||
|
private $subscription_url_factory;
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
NewSubscriberNotificationMailer $new_subscriber_notification_sender,
|
NewSubscriberNotificationMailer $new_subscriber_notification_sender,
|
||||||
WPFunctions $wp,
|
WPFunctions $wp,
|
||||||
@ -55,7 +58,8 @@ class Pages {
|
|||||||
UrlHelper $url_helper,
|
UrlHelper $url_helper,
|
||||||
CaptchaRenderer $captcha_renderer,
|
CaptchaRenderer $captcha_renderer,
|
||||||
WelcomeScheduler $welcome_scheduler,
|
WelcomeScheduler $welcome_scheduler,
|
||||||
LinkTokens $link_tokens
|
LinkTokens $link_tokens,
|
||||||
|
Url $subscription_url_factory
|
||||||
) {
|
) {
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
$this->new_subscriber_notification_sender = $new_subscriber_notification_sender;
|
$this->new_subscriber_notification_sender = $new_subscriber_notification_sender;
|
||||||
@ -64,6 +68,7 @@ class Pages {
|
|||||||
$this->captcha_renderer = $captcha_renderer;
|
$this->captcha_renderer = $captcha_renderer;
|
||||||
$this->welcome_scheduler = $welcome_scheduler;
|
$this->welcome_scheduler = $welcome_scheduler;
|
||||||
$this->link_tokens = $link_tokens;
|
$this->link_tokens = $link_tokens;
|
||||||
|
$this->subscription_url_factory = $subscription_url_factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init($action = false, $data = [], $init_shortcodes = false, $init_page_filters = false) {
|
function init($action = false, $data = [], $init_shortcodes = false, $init_page_filters = false) {
|
||||||
@ -499,7 +504,7 @@ class Pages {
|
|||||||
: $this->wp->__('Manage your subscription', 'mailpoet')
|
: $this->wp->__('Manage your subscription', 'mailpoet')
|
||||||
);
|
);
|
||||||
|
|
||||||
return '<a href="' . Url::getManageUrl(
|
return '<a href="' . $this->subscription_url_factory->getManageUrl(
|
||||||
$this->subscriber ?: null
|
$this->subscriber ?: null
|
||||||
) . '">' . $text . '</a>';
|
) . '">' . $text . '</a>';
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ class Url {
|
|||||||
return self::getSubscriptionUrl($post, 'confirm', $subscriber);
|
return self::getSubscriptionUrl($post, 'confirm', $subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getManageUrl(Subscriber $subscriber = null) {
|
function getManageUrl(Subscriber $subscriber = null) {
|
||||||
$post = self::getPost(self::getSetting('subscription.pages.manage'));
|
$post = self::getPost($this->settings->get('subscription.pages.manage'));
|
||||||
return self::getSubscriptionUrl($post, 'manage', $subscriber);
|
return self::getSubscriptionUrl($post, 'manage', $subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,12 @@ class NewslettersTest extends \MailPoetTest {
|
|||||||
/** @var Newsletters */
|
/** @var Newsletters */
|
||||||
private $endpoint;
|
private $endpoint;
|
||||||
|
|
||||||
|
/** @var SubscriptionUrl */
|
||||||
|
private $subscription_url_factory;
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
|
$this->subscription_url_factory = SubscriptionUrl::getInstance();
|
||||||
$this->endpoint = ContainerWrapper::getInstance()->get(Newsletters::class);
|
$this->endpoint = ContainerWrapper::getInstance()->get(Newsletters::class);
|
||||||
$this->newsletter = Newsletter::createOrUpdate(
|
$this->newsletter = Newsletter::createOrUpdate(
|
||||||
[
|
[
|
||||||
@ -134,7 +138,8 @@ class NewslettersTest extends \MailPoetTest {
|
|||||||
ContainerWrapper::getInstance()->get(NewslettersRepository::class),
|
ContainerWrapper::getInstance()->get(NewslettersRepository::class),
|
||||||
ContainerWrapper::getInstance()->get(NewslettersResponseBuilder::class),
|
ContainerWrapper::getInstance()->get(NewslettersResponseBuilder::class),
|
||||||
ContainerWrapper::getInstance()->get(PostNotificationScheduler::class),
|
ContainerWrapper::getInstance()->get(PostNotificationScheduler::class),
|
||||||
ContainerWrapper::getInstance()->get(MetaInfo::class)
|
ContainerWrapper::getInstance()->get(MetaInfo::class),
|
||||||
|
$this->subscription_url_factory
|
||||||
);
|
);
|
||||||
$response = $this->endpoint->get(['id' => $this->newsletter->id]);
|
$response = $this->endpoint->get(['id' => $this->newsletter->id]);
|
||||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||||
@ -798,9 +803,10 @@ class NewslettersTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItCanSendAPreview() {
|
function testItCanSendAPreview() {
|
||||||
|
|
||||||
$subscriber = 'test@subscriber.com';
|
$subscriber = 'test@subscriber.com';
|
||||||
$unsubscribeLink = SubscriptionUrl::getUnsubscribeUrl(null);
|
$unsubscribeLink = SubscriptionUrl::getUnsubscribeUrl(null);
|
||||||
$manageLink = SubscriptionUrl::getManageUrl(null);
|
$manageLink = $this->subscription_url_factory->getManageUrl(null);
|
||||||
$viewInBrowserLink = Url::getViewInBrowserUrl(null, $this->newsletter, false, false, true);
|
$viewInBrowserLink = Url::getViewInBrowserUrl(null, $this->newsletter, false, false, true);
|
||||||
$mailerMetaInfo = new MetaInfo;
|
$mailerMetaInfo = new MetaInfo;
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -26,6 +26,8 @@ class ShortcodesTest extends \MailPoetTest {
|
|||||||
public $subscriber;
|
public $subscriber;
|
||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $settings;
|
private $settings;
|
||||||
|
/** @var SubscriptionUrl */
|
||||||
|
private $subscription_url_factory;
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
@ -44,6 +46,7 @@ class ShortcodesTest extends \MailPoetTest {
|
|||||||
$this->subscriber
|
$this->subscriber
|
||||||
);
|
);
|
||||||
$this->settings->set('tracking.enabled', false);
|
$this->settings->set('tracking.enabled', false);
|
||||||
|
$this->subscription_url_factory = new SubscriptionUrl(WPFunctions::get(), $this->settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanExtractShortcodes() {
|
function testItCanExtractShortcodes() {
|
||||||
@ -300,7 +303,7 @@ class ShortcodesTest extends \MailPoetTest {
|
|||||||
];
|
];
|
||||||
$links = [
|
$links = [
|
||||||
SubscriptionUrl::getUnsubscribeUrl(null),
|
SubscriptionUrl::getUnsubscribeUrl(null),
|
||||||
SubscriptionUrl::getManageUrl(null),
|
$this->subscription_url_factory->getManageUrl(null),
|
||||||
NewsletterUrl::getViewInBrowserUrl(null, $this->newsletter, false, false, true),
|
NewsletterUrl::getViewInBrowserUrl(null, $this->newsletter, false, false, true),
|
||||||
];
|
];
|
||||||
$result = $shortcodes_object->process($shortcodes);
|
$result = $shortcodes_object->process($shortcodes);
|
||||||
|
@ -81,7 +81,7 @@ class UrlTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItReturnsTheManageSubscriptionUrl() {
|
function testItReturnsTheManageSubscriptionUrl() {
|
||||||
// preview
|
// preview
|
||||||
$url = Url::getManageUrl(null);
|
$url = $this->url->getManageUrl(null);
|
||||||
expect($url)->notNull();
|
expect($url)->notNull();
|
||||||
expect($url)->contains('action=manage');
|
expect($url)->contains('action=manage');
|
||||||
expect($url)->contains('endpoint=subscription');
|
expect($url)->contains('endpoint=subscription');
|
||||||
@ -90,7 +90,7 @@ class UrlTest extends \MailPoetTest {
|
|||||||
$subscriber = Subscriber::createOrUpdate([
|
$subscriber = Subscriber::createOrUpdate([
|
||||||
'email' => 'john@mailpoet.com',
|
'email' => 'john@mailpoet.com',
|
||||||
]);
|
]);
|
||||||
$url = Url::getManageUrl($subscriber);
|
$url = $this->url->getManageUrl($subscriber);
|
||||||
expect($url)->contains('action=manage');
|
expect($url)->contains('action=manage');
|
||||||
expect($url)->contains('endpoint=subscription');
|
expect($url)->contains('endpoint=subscription');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user