diff --git a/lib/Newsletter/Editor/PostTransformerContentsExtractor.php b/lib/Newsletter/Editor/PostTransformerContentsExtractor.php index e19535714f..7921442c2f 100644 --- a/lib/Newsletter/Editor/PostTransformerContentsExtractor.php +++ b/lib/Newsletter/Editor/PostTransformerContentsExtractor.php @@ -133,7 +133,7 @@ class PostTransformerContentsExtractor { } public function getTitle($post) { - $title = $this->sanitizeTitle($post->post_title); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $title = $post->post_title; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps if (filter_var($this->args['titleIsLink'], FILTER_VALIDATE_BOOLEAN)) { $title = '' . $title . ''; diff --git a/tests/integration/Newsletter/RendererTest.php b/tests/integration/Newsletter/RendererTest.php index 5c3373d11c..ef8245ff72 100644 --- a/tests/integration/Newsletter/RendererTest.php +++ b/tests/integration/Newsletter/RendererTest.php @@ -638,4 +638,63 @@ class RendererTest extends \MailPoetTest { // non mso condition for button is rendered correctly expect(preg_match('/<\!--\[if \!mso\]><\!-- -->\s+\s+<\!--<\!\[endif\]-->/s', $template['html']))->equals(1); } + + // Test case for MAILPOET-3660 + public function testItRendersPostContentWhenMultipleQuotesInPostTitle() { + $postTitle = 'This \"is \'a\" test'; + $postContent = '\n

This is the post content

\n'; + $postId = wp_insert_post( + [ + 'post_title' => $postTitle, + 'post_content' => $postContent, + 'post_status' => 'publish', + ] + ); + $filename = 'tests/_data/600x400.jpg'; + $contents = file_get_contents($filename); + + $upload = wp_upload_bits(basename($filename), null, $contents); + $attachmentId = $this->makeAttachment($upload); + set_post_thumbnail($postId, $attachmentId); + + $this->newsletter->setBody(json_decode( + (string)file_get_contents(dirname(__FILE__) . '/RendererTestALCdata.json'), true + )); + + $template = $this->renderer->render($this->newsletter); + expect($template['html'])->stringContainsString('This is the post content'); + + wp_delete_attachment($attachmentId, true); + wp_delete_post($postId, true); + } + + public function makeAttachment($upload, $parentPostId = 0) { + if ( ! function_exists( 'wp_crop_image' ) ) { + include( ABSPATH . 'wp-admin/includes/image.php' ); + } + + $type = ''; + if (!empty($upload['type'])) { + $type = $upload['type']; + } else { + $mime = wp_check_filetype($upload['file']); + if ($mime) + $type = $mime['type']; + } + + $attachment = [ + 'post_title' => basename($upload['file']), + 'post_content' => '', + 'post_type' => 'attachment', + 'post_parent' => $parentPostId, + 'post_mime_type' => $type, + 'guid' => $upload['url'], + ]; + + $id = wp_insert_attachment($attachment, $upload['file'], $parentPostId); + $metadata = wp_generate_attachment_metadata($id, $upload['file']); + wp_update_attachment_metadata($id, $metadata); + + return $id; + } } diff --git a/tests/integration/Newsletter/RendererTestALCdata.json b/tests/integration/Newsletter/RendererTestALCdata.json new file mode 100644 index 0000000000..34dfbeba4c --- /dev/null +++ b/tests/integration/Newsletter/RendererTestALCdata.json @@ -0,0 +1,403 @@ +{ + "content": { + "type": "container", + "orientation": "vertical", + "styles": { + "block": { + "backgroundColor": "transparent" + } + }, + "blocks": [ + { + "orientation": "horizontal", + "type": "container", + "styles": { + "block": { + "backgroundColor": "#999999" + } + }, + "blocks": [ + { + "orientation": "vertical", + "type": "container", + "styles": { + "block": { + "backgroundColor": "#999999" + } + }, + "blocks": [ + { + "type": "automatedLatestContent", + "withLayout": true, + "amount": "3", + "contentType": "post", + "terms": [], + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h3", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "titlePosition": "abovePost", + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "type": "button", + "text": "Read the post", + "url": "[postLink]", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "160px", + "lineHeight": "30px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "16px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "type": "divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + } + ] + } + ] + } + ] + }, + "globalStyles": { + "text": { + "fontColor": "#000000", + "fontFamily": "Arial", + "fontSize": "16px" + }, + "h1": { + "fontColor": "#111111", + "fontFamily": "Trebuchet MS", + "fontSize": "30px" + }, + "h2": { + "fontColor": "#222222", + "fontFamily": "Trebuchet MS", + "fontSize": "24px" + }, + "h3": { + "fontColor": "#333333", + "fontFamily": "Trebuchet MS", + "fontSize": "22px" + }, + "link": { + "fontColor": "#21759B", + "textDecoration": "underline" + }, + "wrapper": { + "backgroundColor": "#ffffff" + }, + "body": { + "backgroundColor": "#eeeeee" + } + }, + "blockDefaults": { + "automatedLatestContent": { + "amount": "5", + "withLayout": false, + "contentType": "post", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "titlePosition": "abovePost", + "featuredImagePosition": "belowTitle", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "automatedLatestContent.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "automatedLatestContent.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "automatedLatestContentLayout": { + "amount": "5", + "withLayout": true, + "contentType": "post", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "titlePosition": "abovePost", + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "button", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "automatedLatestContentLayout.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "automatedLatestContentLayout.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "button": { + "text": "Read the post", + "url": "[postLink]", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + }, + "type": "button" + }, + "container": { + "styles": { + "block": { + "backgroundColor": "transparent" + } + } + }, + "divider": { + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + }, + "type": "divider" + }, + "footer": { + "text": "

Unsubscribe | Manage subscription
Add your postal address here!

", + "styles": { + "block": { + "backgroundColor": "transparent" + }, + "text": { + "fontColor": "#222222", + "fontFamily": "Arial", + "fontSize": "12px", + "textAlign": "center" + }, + "link": { + "fontColor": "#6cb7d4", + "textDecoration": "none" + } + } + }, + "posts": { + "amount": "10", + "withLayout": true, + "contentType": "post", + "postStatus": "publish", + "inclusionType": "include", + "displayType": "excerpt", + "titleFormat": "h1", + "titleAlignment": "left", + "titleIsLink": false, + "imageFullWidth": false, + "titlePosition": "abovePost", + "featuredImagePosition": "alternate", + "showAuthor": "no", + "authorPrecededBy": "Author:", + "showCategories": "no", + "categoriesPrecededBy": "Categories:", + "readMoreType": "link", + "readMoreText": "Read more", + "readMoreButton": { + "text": "Read more", + "url": "[postLink]", + "context": "posts.readMoreButton", + "styles": { + "block": { + "backgroundColor": "#2ea1cd", + "borderColor": "#0074a2", + "borderWidth": "1px", + "borderRadius": "5px", + "borderStyle": "solid", + "width": "180px", + "lineHeight": "40px", + "fontColor": "#ffffff", + "fontFamily": "Verdana", + "fontSize": "18px", + "fontWeight": "normal", + "textAlign": "center" + } + } + }, + "sortBy": "newest", + "showDivider": true, + "divider": { + "context": "posts.divider", + "styles": { + "block": { + "backgroundColor": "transparent", + "padding": "13px", + "borderStyle": "solid", + "borderWidth": "3px", + "borderColor": "#aaaaaa" + } + } + }, + "backgroundColor": "#ffffff", + "backgroundColorAlternate": "#eeeeee" + }, + "social": { + "iconSet": "default", + "icons": [ + { + "type": "socialIcon", + "iconType": "facebook", + "link": "http://www.facebook.com", + "image": "http://localhost/wp-content/plugins/mailpoet/assets/img/newsletter_editor/social-icons/01-social/Facebook.png?mailpoet_version=3.7.8", + "height": "32px", + "width": "32px", + "text": "Facebook" + }, + { + "type": "socialIcon", + "iconType": "twitter", + "link": "http://www.twitter.com", + "image": "http://localhost/wp-content/plugins/mailpoet/assets/img/newsletter_editor/social-icons/01-social/Twitter.png?mailpoet_version=3.7.8", + "height": "32px", + "width": "32px", + "text": "Twitter" + } + ] + }, + "spacer": { + "styles": { + "block": { + "backgroundColor": "transparent", + "height": "40px" + } + } + }, + "header": { + "text": "View this in your browser.", + "styles": { + "block": { + "backgroundColor": "transparent" + }, + "text": { + "fontColor": "#222222", + "fontFamily": "Arial", + "fontSize": "12px", + "textAlign": "center" + }, + "link": { + "fontColor": "#6cb7d4", + "textDecoration": "underline" + } + } + } + } +}