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!