Use DI for blocks rendering
[MAILPOET-2899]
This commit is contained in:
@ -270,6 +270,15 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionsRepository::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionFieldsRepository::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Preview\SendPreviewController::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Button::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Divider::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Footer::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Header::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Image::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Renderer::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Social::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Spacer::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Renderer\Blocks\Text::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Segment\NewsletterSegmentRepository::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository::class);
|
||||
$container->autowire(\MailPoet\Newsletter\Scheduler\WelcomeScheduler::class)->setPublic(true);
|
||||
|
@ -6,8 +6,8 @@ use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
|
||||
use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
|
||||
class Button {
|
||||
public static function render($element, $columnBaseWidth) {
|
||||
$element['styles']['block']['width'] = self::calculateWidth($element, $columnBaseWidth);
|
||||
public function render($element, $columnBaseWidth) {
|
||||
$element['styles']['block']['width'] = $this->calculateWidth($element, $columnBaseWidth);
|
||||
$styles = 'display:inline-block;-webkit-text-size-adjust:none;mso-hide:all;text-decoration:none !important;text-align:center;' . StylesHelper::getBlockStyles($element, $exclude = ['textAlign']);
|
||||
$styles = EHelper::escapeHtmlStyleAttr($styles);
|
||||
$template = '
|
||||
@ -43,7 +43,7 @@ class Button {
|
||||
return $template;
|
||||
}
|
||||
|
||||
public static function calculateWidth($element, $columnBaseWidth) {
|
||||
public function calculateWidth($element, $columnBaseWidth) {
|
||||
$columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2);
|
||||
$borderWidth = (int)$element['styles']['block']['borderWidth'];
|
||||
$buttonWidth = (int)$element['styles']['block']['width'];
|
||||
|
@ -6,7 +6,7 @@ use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
|
||||
use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
|
||||
class Divider {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$backgroundColor = $element['styles']['block']['backgroundColor'];
|
||||
$dividerCellStyle = "border-top-width: {$element['styles']['block']['borderWidth']};";
|
||||
$dividerCellStyle .= "border-top-style: {$element['styles']['block']['borderStyle']};";
|
||||
|
@ -8,7 +8,7 @@ use MailPoet\Util\pQuery\pQuery;
|
||||
use MailPoetVendor\CSS;
|
||||
|
||||
class Footer {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$element['text'] = preg_replace('/\n/', '<br />', $element['text']);
|
||||
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
|
||||
$lineHeight = sprintf(
|
||||
|
@ -8,7 +8,7 @@ use MailPoet\Util\pQuery\pQuery;
|
||||
use MailPoetVendor\CSS;
|
||||
|
||||
class Header {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$element['text'] = preg_replace('/\n/', '<br />', $element['text']);
|
||||
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
|
||||
$lineHeight = sprintf(
|
||||
|
@ -7,7 +7,7 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Image {
|
||||
public static function render($element, $columnBaseWidth) {
|
||||
public function render($element, $columnBaseWidth) {
|
||||
if (empty($element['src'])) {
|
||||
return '';
|
||||
}
|
||||
@ -22,7 +22,7 @@ class Image {
|
||||
$element['width'] = (int)$element['width'];
|
||||
$element['height'] = (int)$element['height'];
|
||||
$originalWidth = $element['width'];
|
||||
$element = self::adjustImageDimensions($element, $columnBaseWidth);
|
||||
$element = $this->adjustImageDimensions($element, $columnBaseWidth);
|
||||
}
|
||||
|
||||
// If image was downsized because of column width set width to aways fill full column (e.g. on mobile)
|
||||
@ -51,7 +51,7 @@ class Image {
|
||||
return $template;
|
||||
}
|
||||
|
||||
public static function adjustImageDimensions($element, $columnBaseWidth) {
|
||||
public function adjustImageDimensions($element, $columnBaseWidth) {
|
||||
$paddedWidth = StylesHelper::$paddingWidth * 2;
|
||||
// scale image to fit column width
|
||||
if ($element['width'] > $columnBaseWidth) {
|
||||
|
@ -12,9 +12,51 @@ class Renderer {
|
||||
public $posts;
|
||||
public $ALC;
|
||||
|
||||
public function __construct(AutomatedLatestContent $ALC) {
|
||||
/** @var Button */
|
||||
private $button;
|
||||
|
||||
/** @var Divider */
|
||||
private $divider;
|
||||
|
||||
/** @var Footer */
|
||||
private $footer;
|
||||
|
||||
/** @var Header */
|
||||
private $header;
|
||||
|
||||
/** @var Image */
|
||||
private $image;
|
||||
|
||||
/** @var Social */
|
||||
private $social;
|
||||
|
||||
/** @var Spacer */
|
||||
private $spacer;
|
||||
|
||||
/** @var Text */
|
||||
private $text;
|
||||
|
||||
public function __construct(
|
||||
AutomatedLatestContent $ALC,
|
||||
Button $button,
|
||||
Divider $divider,
|
||||
Footer $footer,
|
||||
Header $header,
|
||||
Image $image,
|
||||
Social $social,
|
||||
Spacer $spacer,
|
||||
Text $text
|
||||
) {
|
||||
$this->posts = [];
|
||||
$this->ALC = $ALC;
|
||||
$this->button = $button;
|
||||
$this->divider = $divider;
|
||||
$this->footer = $footer;
|
||||
$this->header = $header;
|
||||
$this->image = $image;
|
||||
$this->social = $social;
|
||||
$this->spacer = $spacer;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function render($newsletter, $data) {
|
||||
@ -51,15 +93,28 @@ class Renderer {
|
||||
|
||||
public function createElementFromBlockType($newsletter, $block, $columnBaseWidth) {
|
||||
if ($block['type'] === 'automatedLatestContent') {
|
||||
$content = $this->processAutomatedLatestContent($newsletter, $block, $columnBaseWidth);
|
||||
return $content;
|
||||
return $this->processAutomatedLatestContent($newsletter, $block, $columnBaseWidth);
|
||||
}
|
||||
$block = StylesHelper::applyTextAlignment($block);
|
||||
$blockClass = __NAMESPACE__ . '\\' . ucfirst($block['type']);
|
||||
if (!class_exists($blockClass)) {
|
||||
return '';
|
||||
switch ($block['type']) {
|
||||
case 'button':
|
||||
return $this->button->render($block, $columnBaseWidth);
|
||||
case 'divider':
|
||||
return $this->divider->render($block);
|
||||
case 'footer':
|
||||
return $this->footer->render($block);
|
||||
case 'header':
|
||||
return $this->header->render($block);
|
||||
case 'image':
|
||||
return $this->image->render($block, $columnBaseWidth);
|
||||
case 'social':
|
||||
return $this->social->render($block);
|
||||
case 'spacer':
|
||||
return $this->spacer->render($block);
|
||||
case 'text':
|
||||
return $this->text->render($block);
|
||||
}
|
||||
return $blockClass::render($block, $columnBaseWidth);
|
||||
return '';
|
||||
}
|
||||
|
||||
public function automatedLatestContentTransformedPosts($newsletter, $args) {
|
||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Newsletter\Renderer\Blocks;
|
||||
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
|
||||
|
||||
class Social {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$iconsBlock = '';
|
||||
if (is_array($element['icons'])) {
|
||||
foreach ($element['icons'] as $index => $icon) {
|
||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Newsletter\Renderer\Blocks;
|
||||
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
|
||||
|
||||
class Spacer {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$height = (int)$element['styles']['block']['height'];
|
||||
$backgroundColor = EHelper::escapeHtmlAttr($element['styles']['block']['backgroundColor']);
|
||||
$template = '
|
||||
|
@ -8,16 +8,16 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
|
||||
class Text {
|
||||
public static function render($element) {
|
||||
public function render($element) {
|
||||
$html = $element['text'];
|
||||
// replace with spaces
|
||||
$html = str_replace(' ', ' ', $html);
|
||||
$html = str_replace('\xc2\xa0', ' ', $html);
|
||||
$html = self::convertBlockquotesToTables($html);
|
||||
$html = self::convertParagraphsToTables($html);
|
||||
$html = self::styleLists($html);
|
||||
$html = self::styleHeadings($html);
|
||||
$html = self::removeLastLineBreak($html);
|
||||
$html = $this->convertBlockquotesToTables($html);
|
||||
$html = $this->convertParagraphsToTables($html);
|
||||
$html = $this->styleLists($html);
|
||||
$html = $this->styleHeadings($html);
|
||||
$html = $this->removeLastLineBreak($html);
|
||||
$template = '
|
||||
<tr>
|
||||
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;">
|
||||
@ -27,7 +27,7 @@ class Text {
|
||||
return $template;
|
||||
}
|
||||
|
||||
public static function convertBlockquotesToTables($html) {
|
||||
public function convertBlockquotesToTables($html) {
|
||||
$dOMParser = new pQuery();
|
||||
$DOM = $dOMParser->parseStr($html);
|
||||
$blockquotes = $DOM->query('blockquote');
|
||||
@ -67,12 +67,12 @@ class Text {
|
||||
</tr>
|
||||
</tbody>'
|
||||
);
|
||||
$blockquote = self::insertLineBreak($blockquote);
|
||||
$blockquote = $this->insertLineBreak($blockquote);
|
||||
}
|
||||
return $DOM->__toString();
|
||||
}
|
||||
|
||||
public static function convertParagraphsToTables($html) {
|
||||
public function convertParagraphsToTables($html) {
|
||||
$dOMParser = new pQuery();
|
||||
$DOM = $dOMParser->parseStr($html);
|
||||
$paragraphs = $DOM->query('p');
|
||||
@ -95,7 +95,7 @@ class Text {
|
||||
!$previousElement ||
|
||||
(preg_match('/h\d+/', $previousElementTag))
|
||||
) {
|
||||
$paragraph = self::insertLineBreak($paragraph);
|
||||
$paragraph = $this->insertLineBreak($paragraph);
|
||||
}
|
||||
$paragraph->remove();
|
||||
continue;
|
||||
@ -136,7 +136,7 @@ class Text {
|
||||
return $DOM->__toString();
|
||||
}
|
||||
|
||||
public static function styleLists($html) {
|
||||
public function styleLists($html) {
|
||||
$dOMParser = new pQuery();
|
||||
$DOM = $dOMParser->parseStr($html);
|
||||
$lists = $DOM->query('ol, ul, li');
|
||||
@ -156,7 +156,7 @@ class Text {
|
||||
return $DOM->__toString();
|
||||
}
|
||||
|
||||
public static function styleHeadings($html) {
|
||||
public function styleHeadings($html) {
|
||||
$dOMParser = new pQuery();
|
||||
$DOM = $dOMParser->parseStr($html);
|
||||
$headings = $DOM->query('h1, h2, h3, h4');
|
||||
@ -169,11 +169,11 @@ class Text {
|
||||
return $DOM->__toString();
|
||||
}
|
||||
|
||||
public static function removeLastLineBreak($html) {
|
||||
public function removeLastLineBreak($html) {
|
||||
return preg_replace('/(^)?(<br[^>]*?\/?>)+$/i', '', $html);
|
||||
}
|
||||
|
||||
public static function insertLineBreak($element) {
|
||||
public function insertLineBreak($element) {
|
||||
$element->parent->insertChild(
|
||||
[
|
||||
'tag_name' => 'br',
|
||||
|
@ -5,7 +5,6 @@ namespace MailPoet\Newsletter\Renderer;
|
||||
use MailPoet\Config\Env;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Newsletter\AutomatedLatestContent;
|
||||
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Util\License\License;
|
||||
@ -32,9 +31,7 @@ class Renderer {
|
||||
public function __construct($newsletter, $preview = false) {
|
||||
$this->newsletter = ($newsletter instanceof Newsletter) ? $newsletter->asArray() : $newsletter;
|
||||
$this->preview = $preview;
|
||||
$this->blocksRenderer = new Blocks\Renderer(
|
||||
ContainerWrapper::getInstance()->get(AutomatedLatestContent::class)
|
||||
);
|
||||
$this->blocksRenderer = ContainerWrapper::getInstance()->get(Blocks\Renderer::class);
|
||||
$this->columnsRenderer = new Columns\Renderer();
|
||||
$this->preprocessor = new Preprocessor(
|
||||
$this->blocksRenderer,
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace MailPoet\Test\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\v1\AutomatedLatestContent;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class AutomatedLatestContentTest extends \MailPoetTest {
|
||||
public function testItGetsPostTypes() {
|
||||
|
@ -229,7 +229,7 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItRendersHeader() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][0];
|
||||
$DOM = $this->dOMParser->parseStr(Header::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Header)->render($template));
|
||||
// element should be properly nested, and styles should be applied
|
||||
expect($DOM('tr > td.mailpoet_header', 0)->html())->notEmpty();
|
||||
expect($DOM('tr > td > a', 0)->html())->notEmpty();
|
||||
@ -240,7 +240,7 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItRendersImage() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, self::COLUMN_BASE_WIDTH));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, self::COLUMN_BASE_WIDTH));
|
||||
// element should be properly nested, it's width set and style applied
|
||||
expect($DOM('tr > td > img', 0)->attr('width'))->equals(620);
|
||||
}
|
||||
@ -250,21 +250,21 @@ class RendererTest extends \MailPoetTest {
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||
// default alignment (center)
|
||||
unset($template['styles']['block']['textAlign']);
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, $columnCount = 1));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, $columnCount = 1));
|
||||
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
|
||||
$template['styles']['block']['textAlign'] = 'center';
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, $columnCount = 1));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, $columnCount = 1));
|
||||
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
|
||||
$template['styles']['block']['textAlign'] = 'something odd';
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, $columnCount = 1));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, $columnCount = 1));
|
||||
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
|
||||
// left alignment
|
||||
$template['styles']['block']['textAlign'] = 'left';
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, $columnCount = 1));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, $columnCount = 1));
|
||||
expect($DOM('tr > td', 0)->attr('align'))->equals('left');
|
||||
// right alignment
|
||||
$template['styles']['block']['textAlign'] = 'right';
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, $columnCount = 1));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, $columnCount = 1));
|
||||
expect($DOM('tr > td', 0)->attr('align'))->equals('right');
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ class RendererTest extends \MailPoetTest {
|
||||
'link' => '',
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($renderedImage)->equals('');
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ class RendererTest extends \MailPoetTest {
|
||||
'fullWidth' => false,
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
$siteUrl = get_option('siteurl');
|
||||
expect($renderedImage)->contains('src="' . $siteUrl . '/relative-path"');
|
||||
|
||||
@ -301,7 +301,7 @@ class RendererTest extends \MailPoetTest {
|
||||
'fullWidth' => false,
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($renderedImage)->contains('src="//path-without-protocol"');
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ class RendererTest extends \MailPoetTest {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||
$template['link'] = 'http://example.com';
|
||||
$DOM = $this->dOMParser->parseStr(Image::render($template, self::COLUMN_BASE_WIDTH));
|
||||
$DOM = $this->dOMParser->parseStr((new Image)->render($template, self::COLUMN_BASE_WIDTH));
|
||||
// element should be wrapped in <a> tag
|
||||
expect($DOM('tr > td > a', 0)->html())->contains('<img');
|
||||
expect($DOM('tr > td > a', 0)->attr('href'))->equals($template['link']);
|
||||
@ -322,25 +322,25 @@ class RendererTest extends \MailPoetTest {
|
||||
'height' => 600,
|
||||
'fullWidth' => true,
|
||||
];
|
||||
$newImageDimensions = Image::adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
$newImageDimensions = (new Image)->adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($newImageDimensions['width'])->equals(660);
|
||||
expect($newImageDimensions['height'])->equals(495);
|
||||
// nothing happens when image width = column width
|
||||
$image['width'] = 661;
|
||||
$newImageDimensions = Image::adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
$newImageDimensions = (new Image)->adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($newImageDimensions['width'])->equals(660);
|
||||
// nothing happens when image width < column width
|
||||
$image['width'] = 659;
|
||||
$newImageDimensions = Image::adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
$newImageDimensions = (new Image)->adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($newImageDimensions['width'])->equals(659);
|
||||
// image is reduced by 40px when it's width > padded column width
|
||||
$image['width'] = 621;
|
||||
$image['fullWidth'] = false;
|
||||
$newImageDimensions = Image::adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
$newImageDimensions = (new Image)->adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($newImageDimensions['width'])->equals(620);
|
||||
// nothing happens when image with < padded column width
|
||||
$image['width'] = 619;
|
||||
$newImageDimensions = Image::adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
$newImageDimensions = (new Image)->adjustImageDimensions($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($newImageDimensions['width'])->equals(619);
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ class RendererTest extends \MailPoetTest {
|
||||
'fullWidth' => false,
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($renderedImage)->contains('width="auto"');
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ class RendererTest extends \MailPoetTest {
|
||||
'fullWidth' => false,
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($renderedImage)->contains('width="620"');
|
||||
}
|
||||
|
||||
@ -379,14 +379,14 @@ class RendererTest extends \MailPoetTest {
|
||||
'fullWidth' => false,
|
||||
'alt' => 'some test alt text',
|
||||
];
|
||||
$renderedImage = Image::render($image, self::COLUMN_BASE_WIDTH);
|
||||
$renderedImage = (new Image)->render($image, self::COLUMN_BASE_WIDTH);
|
||||
expect($renderedImage)->contains('width="620"');
|
||||
}
|
||||
|
||||
public function testItRendersText() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][2];
|
||||
$DOM = $this->dOMParser->parseStr(Text::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Text)->render($template));
|
||||
// blockquotes and paragraphs should be converted to spans and placed inside a table
|
||||
expect(
|
||||
$DOM('tr > td > table > tr > td.mailpoet_paragraph', 0)->html()
|
||||
@ -416,7 +416,7 @@ class RendererTest extends \MailPoetTest {
|
||||
|
||||
// trailing line breaks should be cut off, but not inside an element
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][8];
|
||||
$DOM = $this->dOMParser->parseStr(Text::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Text)->render($template));
|
||||
expect(count($DOM('tr > td > br', 0)))
|
||||
->equals(0);
|
||||
expect($DOM('tr > td > h3', 0)->html())
|
||||
@ -426,7 +426,7 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItRendersDivider() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][3];
|
||||
$DOM = $this->dOMParser->parseStr(Divider::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Divider)->render($template));
|
||||
// element should be properly nested and its border-top-width set
|
||||
expect(
|
||||
preg_match(
|
||||
@ -438,7 +438,7 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItRendersSpacer() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][4];
|
||||
$DOM = $this->dOMParser->parseStr(Spacer::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Spacer)->render($template));
|
||||
// element should be properly nested and its height set
|
||||
expect($DOM('tr > td.mailpoet_spacer', 0)->attr('height'))->equals(50);
|
||||
}
|
||||
@ -446,10 +446,10 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItSetsSpacerBackground() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][4];
|
||||
$DOM = $this->dOMParser->parseStr(Spacer::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Spacer)->render($template));
|
||||
expect($DOM('tr > td.mailpoet_spacer', 0)->attr('bgcolor'))->null();
|
||||
$template['styles']['block']['backgroundColor'] = '#ffff';
|
||||
$DOM = $this->dOMParser->parseStr(Spacer::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Spacer)->render($template));
|
||||
expect($DOM('tr > td.mailpoet_spacer', 0)->attr('bgcolor'))
|
||||
->equals('#ffff');
|
||||
}
|
||||
@ -458,14 +458,14 @@ class RendererTest extends \MailPoetTest {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
|
||||
$template['styles']['block']['width'] = '700px';
|
||||
$buttonWidth = Button::calculateWidth($template, self::COLUMN_BASE_WIDTH);
|
||||
$buttonWidth = (new Button)->calculateWidth($template, self::COLUMN_BASE_WIDTH);
|
||||
expect($buttonWidth)->equals('618px'); //(width - (2 * border width)
|
||||
}
|
||||
|
||||
public function testItRendersButton() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
|
||||
$DOM = $this->dOMParser->parseStr(Button::render($template, self::COLUMN_BASE_WIDTH));
|
||||
$DOM = $this->dOMParser->parseStr((new Button)->render($template, self::COLUMN_BASE_WIDTH));
|
||||
// element should be properly nested with arcsize/styles/fillcolor set
|
||||
expect(
|
||||
$DOM('tr > td > div > table > tr > td > a.mailpoet_button', 0)->html()
|
||||
@ -501,7 +501,7 @@ class RendererTest extends \MailPoetTest {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
|
||||
$template['styles']['block']['fontFamily'] = 'Lucida';
|
||||
$DOM = $this->dOMParser->parseStr(Button::render($template, self::COLUMN_BASE_WIDTH));
|
||||
$DOM = $this->dOMParser->parseStr((new Button)->render($template, self::COLUMN_BASE_WIDTH));
|
||||
expect(
|
||||
preg_match(
|
||||
'/font-family: \'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif/',
|
||||
@ -512,7 +512,7 @@ class RendererTest extends \MailPoetTest {
|
||||
public function testItRendersSocialIcons() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][6];
|
||||
$DOM = $this->dOMParser->parseStr(Social::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Social)->render($template));
|
||||
// element should be properly nested, contain social icons and
|
||||
// image source/link href/alt should be properly set
|
||||
expect($DOM('tr > td', 0)->html())->notEmpty();
|
||||
@ -533,14 +533,14 @@ class RendererTest extends \MailPoetTest {
|
||||
'iconType' => 'custom',
|
||||
],
|
||||
];
|
||||
$renderedBlock = Social::render($block);
|
||||
$renderedBlock = (new Social)->render($block);
|
||||
expect($renderedBlock)->equals('');
|
||||
}
|
||||
|
||||
public function testItRendersFooter() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][3]['blocks'][0]['blocks'][0];
|
||||
$DOM = $this->dOMParser->parseStr(Footer::render($template));
|
||||
$DOM = $this->dOMParser->parseStr((new Footer)->render($template));
|
||||
// element should be properly nested, and styles should be applied
|
||||
expect($DOM('tr > td.mailpoet_footer', 0)->html())->notEmpty();
|
||||
expect($DOM('tr > td > a', 0)->html())->notEmpty();
|
||||
|
@ -27,7 +27,7 @@ class ButtonTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Button::render($this->block, 200);
|
||||
$output = (new Button)->render($this->block, 200);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_padded_vertical mailpoet_padded_side" valign="top">
|
||||
|
@ -18,7 +18,7 @@ class DividerTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Divider::render($this->block);
|
||||
$output = (new Divider)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_divider" valign="top" style="padding: 13px 20px 13px 20px;">
|
||||
|
@ -25,7 +25,7 @@ class FooterTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Footer::render($this->block);
|
||||
$output = (new Footer)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_header_footer_padded mailpoet_footer" style="line-height: 19.2px;color: #222222;font-family: roboto, \'helvetica neue\', helvetica, arial, sans-serif;font-size: 12px;text-align: center;">
|
||||
@ -37,7 +37,7 @@ class FooterTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersWithBackgroundColor() {
|
||||
$this->block['styles']['block']['backgroundColor'] = '#f0f0f0';
|
||||
$output = Footer::render($this->block);
|
||||
$output = (new Footer)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_header_footer_padded mailpoet_footer" bgcolor="#f0f0f0" style="line-height: 19.2px;background-color: #f0f0f0;color: #222222;font-family: roboto, \'helvetica neue\', helvetica, arial, sans-serif;font-size: 12px;text-align: center;">
|
||||
@ -49,7 +49,7 @@ class FooterTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItPrefersInlinedCssForLinks() {
|
||||
$this->block['text'] = '<p>Footer text. <a href="http://example.com" style="color:#aaaaaa;">link</a></p>';
|
||||
$output = Footer::render($this->block);
|
||||
$output = (new Footer)->render($this->block);
|
||||
expect($output)->contains('<a href="http://example.com" style="color:#aaaaaa;text-decoration:none">link</a>');
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class HeaderTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Header::render($this->block);
|
||||
$output = (new Header)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_header_footer_padded mailpoet_header" style="line-height: 19.2px;color: #222222;font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif;font-size: 12px;text-align: left;">
|
||||
@ -37,7 +37,7 @@ class HeaderTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersBackgroundColorCorrectly() {
|
||||
$this->block['styles']['block']['backgroundColor'] = '#f0f0f0';
|
||||
$output = Header::render($this->block);
|
||||
$output = (new Header)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_header_footer_padded mailpoet_header" bgcolor="#f0f0f0" style="line-height: 19.2px;background-color: #f0f0f0;color: #222222;font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif;font-size: 12px;text-align: left;">
|
||||
@ -49,7 +49,7 @@ class HeaderTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItPrefersInlinedCssForLinks() {
|
||||
$this->block['text'] = '<p>Header text. <a href="http://example.com" style="color:#aaaaaa;">link</a></p>';
|
||||
$output = Footer::render($this->block);
|
||||
$output = (new Footer)->render($this->block);
|
||||
expect($output)->contains('<a href="http://example.com" style="color:#aaaaaa;text-decoration:underline">link</a>');
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class ImageTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Image::render($this->block, 200);
|
||||
$output = (new Image)->render($this->block, 200);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top">
|
||||
@ -32,7 +32,7 @@ class ImageTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersWithoutLink() {
|
||||
$this->block['link'] = null;
|
||||
$output = Image::render($this->block, 200);
|
||||
$output = (new Image)->render($this->block, 200);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top">
|
||||
|
@ -35,7 +35,7 @@ class SocialTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Social::render($this->block);
|
||||
$output = (new Social)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_padded_side mailpoet_padded_vertical" valign="top" align="center">
|
||||
|
@ -15,7 +15,7 @@ class SpacerTest extends \MailPoetUnitTest {
|
||||
];
|
||||
|
||||
public function testItRendersCorrectly() {
|
||||
$output = Spacer::render($this->block);
|
||||
$output = (new Spacer)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_spacer" height="13" valign="top"></td>
|
||||
@ -25,7 +25,7 @@ class SpacerTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testsItRendersWithBackground() {
|
||||
$this->block['styles']['block']['backgroundColor'] = "#ffffff";
|
||||
$output = Spacer::render($this->block);
|
||||
$output = (new Spacer)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_spacer" bgcolor="#ffffff" height="13" valign="top"></td>
|
||||
|
@ -20,7 +20,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
}
|
||||
|
||||
public function testItRendersPlainText() {
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;">
|
||||
@ -32,7 +32,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersParagraph() {
|
||||
$this->block['text'] = '<p>Text</p>';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
$paragraphTable = $table[0]->toString();
|
||||
@ -47,7 +47,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersList() {
|
||||
$this->block['text'] = '<ul><li>Item 1</li><li>Item 2</li></ul>';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
$ul = $this->parser->parseStr($output)->query('ul');
|
||||
assert($ul instanceof \pQuery);
|
||||
$list = $ul[0]->toString();
|
||||
@ -57,7 +57,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItRendersBlockquotes() {
|
||||
$this->block['text'] = '<blockquote><p>Quote</p></blockquote>';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
$table = $this->parser->parseStr($output)->query('table');
|
||||
assert($table instanceof \pQuery);
|
||||
$blockquoteTable = $table[0]->toString();
|
||||
@ -82,7 +82,7 @@ class TextTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItShouldRemoveEmptyParagraphs() {
|
||||
$this->block['text'] = '<p></p><p>Text</p><p></p><p>Text2</p><p></p><p></p>';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
$expectedResult = '
|
||||
<tr>
|
||||
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;">
|
||||
@ -104,14 +104,14 @@ class TextTest extends \MailPoetUnitTest {
|
||||
|
||||
public function testItStylesHeadings() {
|
||||
$this->block['text'] = '<h1>Heading</h1><h2>Heading 2</h2>';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
expect($output)->contains('<h1 style="text-align:left;padding:0;font-style:normal;font-weight:normal;">Heading</h1>');
|
||||
expect($output)->contains('<h2 style="text-align:left;padding:0;font-style:normal;font-weight:normal;">Heading 2</h2>');
|
||||
}
|
||||
|
||||
public function testItRemovesLastLineBreak() {
|
||||
$this->block['text'] = 'hello<br />';
|
||||
$output = Text::render($this->block);
|
||||
$output = (new Text)->render($this->block);
|
||||
expect($output)->notContains('<br />');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user