- Fixes incorrect shortcode name

- Updates unit test
This commit is contained in:
Vlad
2016-06-08 11:08:32 -04:00
parent d182638971
commit d6cbe5aac8
2 changed files with 30 additions and 17 deletions

View File

@@ -58,7 +58,7 @@ class Link {
break; break;
case 'newsletter_view_in_browser': 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 = esc_attr(NewsletterUrl::getViewInBrowserUrl($newsletter, $subscriber, $queue));
$url = self::processUrl($action, $url, $queue); $url = self::processUrl($action, $url, $queue);
return sprintf( return sprintf(

View File

@@ -165,25 +165,25 @@ class ShortcodesTest extends MailPoetTest {
$shortcodes_object = $this->shortcodes_object; $shortcodes_object = $this->shortcodes_object;
$result = $result =
$shortcodes_object->process(array('[link:subscription_unsubscribe]')); $shortcodes_object->process(array('[link:subscription_unsubscribe]'));
expect(preg_match('/^<a.*?\/a>$/', $result['0']))->equals(1); expect($result['0'])->regExp('/^<a.*?\/a>$/');
expect(preg_match('/action=unsubscribe/', $result['0']))->equals(1); expect($result['0'])->regExp('/action=unsubscribe/');
$result = $result =
$shortcodes_object->process(array('[link:subscription_unsubscribe_url]')); $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 = $result =
$shortcodes_object->process(array('[link:subscription_manage]')); $shortcodes_object->process(array('[link:subscription_manage]'));
expect(preg_match('/^<a.*?\/a>$/', $result['0']))->equals(1); expect($result['0'])->regExp('/^<a.*?\/a>$/');
expect(preg_match('/action=manage/', $result['0']))->equals(1); expect($result['0'])->regExp('/action=manage/');
$result = $result =
$shortcodes_object->process(array('[link:subscription_manage_url]')); $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 = $result =
$shortcodes_object->process(array('[link:newsletter_view_in_browser]')); $shortcodes_object->process(array('[link:newsletter_view_in_browser]'));
expect(preg_match('/^<a.*?\/a>$/', $result['0']))->equals(1); expect($result['0'])->regExp('/^<a.*?\/a>$/');
expect(preg_match('/endpoint=view_in_browser/', $result['0']))->equals(1); expect($result['0'])->regExp('/endpoint=view_in_browser/');
$result = $result =
$shortcodes_object->process(array('[link:newsletter_view_in_browser_url]')); $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() { function testItReturnsShortcodeWhenTrackingEnabled() {
@@ -191,9 +191,9 @@ class ShortcodesTest extends MailPoetTest {
$shortcode = '[link:subscription_unsubscribe_url]'; $shortcode = '[link:subscription_unsubscribe_url]';
$result = $result =
$shortcodes_object->process(array($shortcode)); $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); Setting::setValue('tracking.enabled', true);
$shortcodes = array( $initial_shortcodes = array(
'[link:subscription_unsubscribe]', '[link:subscription_unsubscribe]',
'[link:subscription_unsubscribe_url]', '[link:subscription_unsubscribe_url]',
'[link:subscription_manage]', '[link:subscription_manage]',
@@ -201,13 +201,26 @@ class ShortcodesTest extends MailPoetTest {
'[link:newsletter_view_in_browser]', '[link:newsletter_view_in_browser]',
'[link:newsletter_view_in_browser_url]' '[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 // tracking function only works during sending, so queue object must not be false
$shortcodes_object->queue = true; $shortcodes_object->queue = true;
$result = $result = $shortcodes_object->process($initial_shortcodes);
$shortcodes_object->process($shortcodes); foreach($result as $index => $transformed_shortcode) {
// all returned shortcodes must end with url // 1. result must not contain a link
$result = join(',', $result); expect($transformed_shortcode)->regExp('/^((?!href="http).)*$/');
expect(substr_count($result, '_url'))->equals(count($shortcodes)); // 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() { function testItCanProcessCustomLinkShortcodes() {