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