From d6cbe5aac8d91d86c285f694d78b49b7d2a21946 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 8 Jun 2016 11:08:32 -0400 Subject: [PATCH] - Fixes incorrect shortcode name - Updates unit test --- lib/Newsletter/Shortcodes/Categories/Link.php | 2 +- tests/unit/Newsletter/ShortcodesTest.php | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/Newsletter/Shortcodes/Categories/Link.php b/lib/Newsletter/Shortcodes/Categories/Link.php index 8d83a12249..9e97d91812 100644 --- a/lib/Newsletter/Shortcodes/Categories/Link.php +++ b/lib/Newsletter/Shortcodes/Categories/Link.php @@ -58,7 +58,7 @@ class Link { break; case 'newsletter_view_in_browser': - $action = 'view_in_browser_url'; + $action = 'newsletter_view_in_browser_url'; $url = esc_attr(NewsletterUrl::getViewInBrowserUrl($newsletter, $subscriber, $queue)); $url = self::processUrl($action, $url, $queue); return sprintf( diff --git a/tests/unit/Newsletter/ShortcodesTest.php b/tests/unit/Newsletter/ShortcodesTest.php index 50c394a1d4..690e4961d9 100644 --- a/tests/unit/Newsletter/ShortcodesTest.php +++ b/tests/unit/Newsletter/ShortcodesTest.php @@ -165,25 +165,25 @@ class ShortcodesTest extends MailPoetTest { $shortcodes_object = $this->shortcodes_object; $result = $shortcodes_object->process(array('[link:subscription_unsubscribe]')); - expect(preg_match('/^$/', $result['0']))->equals(1); - expect(preg_match('/action=unsubscribe/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^$/'); + expect($result['0'])->regExp('/action=unsubscribe/'); $result = $shortcodes_object->process(array('[link:subscription_unsubscribe_url]')); - expect(preg_match('/^http.*?action=unsubscribe/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^http.*?action=unsubscribe/'); $result = $shortcodes_object->process(array('[link:subscription_manage]')); - expect(preg_match('/^$/', $result['0']))->equals(1); - expect(preg_match('/action=manage/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^$/'); + expect($result['0'])->regExp('/action=manage/'); $result = $shortcodes_object->process(array('[link:subscription_manage_url]')); - expect(preg_match('/^http.*?action=manage/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^http.*?action=manage/'); $result = $shortcodes_object->process(array('[link:newsletter_view_in_browser]')); - expect(preg_match('/^$/', $result['0']))->equals(1); - expect(preg_match('/endpoint=view_in_browser/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^$/'); + expect($result['0'])->regExp('/endpoint=view_in_browser/'); $result = $shortcodes_object->process(array('[link:newsletter_view_in_browser_url]')); - expect(preg_match('/^http.*?endpoint=view_in_browser/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^http.*?endpoint=view_in_browser/'); } function testItReturnsShortcodeWhenTrackingEnabled() { @@ -191,9 +191,9 @@ class ShortcodesTest extends MailPoetTest { $shortcode = '[link:subscription_unsubscribe_url]'; $result = $shortcodes_object->process(array($shortcode)); - expect(preg_match('/^http.*?action=unsubscribe/', $result['0']))->equals(1); + expect($result['0'])->regExp('/^http.*?action=unsubscribe/'); Setting::setValue('tracking.enabled', true); - $shortcodes = array( + $initial_shortcodes = array( '[link:subscription_unsubscribe]', '[link:subscription_unsubscribe_url]', '[link:subscription_manage]', @@ -201,13 +201,26 @@ class ShortcodesTest extends MailPoetTest { '[link:newsletter_view_in_browser]', '[link:newsletter_view_in_browser_url]' ); + $expected_transformed_shortcodes = array( + '[link:subscription_unsubscribe_url]', + '[link:subscription_unsubscribe_url]', + '[link:subscription_manage_url]', + '[link:subscription_manage_url]', + '[link:newsletter_view_in_browser_url]', + '[link:newsletter_view_in_browser_url]' + ); // tracking function only works during sending, so queue object must not be false $shortcodes_object->queue = true; - $result = - $shortcodes_object->process($shortcodes); - // all returned shortcodes must end with url - $result = join(',', $result); - expect(substr_count($result, '_url'))->equals(count($shortcodes)); + $result = $shortcodes_object->process($initial_shortcodes); + foreach($result as $index => $transformed_shortcode) { + // 1. result must not contain a link + expect($transformed_shortcode)->regExp('/^((?!href="http).)*$/'); + // 2. result must include a URL shortcode. for example: + // [link:subscription_unsubscribe] should become + // [link:subscription_unsubscribe_url] + expect($transformed_shortcode) + ->regExp('/' . preg_quote($expected_transformed_shortcodes[$index]) . '/'); + } } function testItCanProcessCustomLinkShortcodes() {