Use DI for blocks rendering

[MAILPOET-2899]
This commit is contained in:
Pavel Dohnal
2020-05-26 09:16:05 +02:00
committed by Veljko V
parent 5f73f9ee3e
commit be631bd549
21 changed files with 148 additions and 88 deletions

View File

@@ -270,6 +270,15 @@ class ContainerConfigurator implements IContainerConfigurator {
$container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionsRepository::class)->setPublic(true); $container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionsRepository::class)->setPublic(true);
$container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionFieldsRepository::class)->setPublic(true); $container->autowire(\MailPoet\Newsletter\Options\NewsletterOptionFieldsRepository::class)->setPublic(true);
$container->autowire(\MailPoet\Newsletter\Preview\SendPreviewController::class); $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\Segment\NewsletterSegmentRepository::class);
$container->autowire(\MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository::class); $container->autowire(\MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository::class);
$container->autowire(\MailPoet\Newsletter\Scheduler\WelcomeScheduler::class)->setPublic(true); $container->autowire(\MailPoet\Newsletter\Scheduler\WelcomeScheduler::class)->setPublic(true);

View File

@@ -6,8 +6,8 @@ use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
use MailPoet\Newsletter\Renderer\StylesHelper; use MailPoet\Newsletter\Renderer\StylesHelper;
class Button { class Button {
public static function render($element, $columnBaseWidth) { public function render($element, $columnBaseWidth) {
$element['styles']['block']['width'] = self::calculateWidth($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 = '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); $styles = EHelper::escapeHtmlStyleAttr($styles);
$template = ' $template = '
@@ -43,7 +43,7 @@ class Button {
return $template; return $template;
} }
public static function calculateWidth($element, $columnBaseWidth) { public function calculateWidth($element, $columnBaseWidth) {
$columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2); $columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2);
$borderWidth = (int)$element['styles']['block']['borderWidth']; $borderWidth = (int)$element['styles']['block']['borderWidth'];
$buttonWidth = (int)$element['styles']['block']['width']; $buttonWidth = (int)$element['styles']['block']['width'];

View File

@@ -6,7 +6,7 @@ use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
use MailPoet\Newsletter\Renderer\StylesHelper; use MailPoet\Newsletter\Renderer\StylesHelper;
class Divider { class Divider {
public static function render($element) { public function render($element) {
$backgroundColor = $element['styles']['block']['backgroundColor']; $backgroundColor = $element['styles']['block']['backgroundColor'];
$dividerCellStyle = "border-top-width: {$element['styles']['block']['borderWidth']};"; $dividerCellStyle = "border-top-width: {$element['styles']['block']['borderWidth']};";
$dividerCellStyle .= "border-top-style: {$element['styles']['block']['borderStyle']};"; $dividerCellStyle .= "border-top-style: {$element['styles']['block']['borderStyle']};";

View File

@@ -8,7 +8,7 @@ use MailPoet\Util\pQuery\pQuery;
use MailPoetVendor\CSS; use MailPoetVendor\CSS;
class Footer { class Footer {
public static function render($element) { public function render($element) {
$element['text'] = preg_replace('/\n/', '<br />', $element['text']); $element['text'] = preg_replace('/\n/', '<br />', $element['text']);
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']); $element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
$lineHeight = sprintf( $lineHeight = sprintf(

View File

@@ -8,7 +8,7 @@ use MailPoet\Util\pQuery\pQuery;
use MailPoetVendor\CSS; use MailPoetVendor\CSS;
class Header { class Header {
public static function render($element) { public function render($element) {
$element['text'] = preg_replace('/\n/', '<br />', $element['text']); $element['text'] = preg_replace('/\n/', '<br />', $element['text']);
$element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']); $element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
$lineHeight = sprintf( $lineHeight = sprintf(

View File

@@ -7,7 +7,7 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class Image { class Image {
public static function render($element, $columnBaseWidth) { public function render($element, $columnBaseWidth) {
if (empty($element['src'])) { if (empty($element['src'])) {
return ''; return '';
} }
@@ -22,7 +22,7 @@ class Image {
$element['width'] = (int)$element['width']; $element['width'] = (int)$element['width'];
$element['height'] = (int)$element['height']; $element['height'] = (int)$element['height'];
$originalWidth = $element['width']; $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) // 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; return $template;
} }
public static function adjustImageDimensions($element, $columnBaseWidth) { public function adjustImageDimensions($element, $columnBaseWidth) {
$paddedWidth = StylesHelper::$paddingWidth * 2; $paddedWidth = StylesHelper::$paddingWidth * 2;
// scale image to fit column width // scale image to fit column width
if ($element['width'] > $columnBaseWidth) { if ($element['width'] > $columnBaseWidth) {

View File

@@ -12,9 +12,51 @@ class Renderer {
public $posts; public $posts;
public $ALC; 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->posts = [];
$this->ALC = $ALC; $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) { public function render($newsletter, $data) {
@@ -51,15 +93,28 @@ class Renderer {
public function createElementFromBlockType($newsletter, $block, $columnBaseWidth) { public function createElementFromBlockType($newsletter, $block, $columnBaseWidth) {
if ($block['type'] === 'automatedLatestContent') { if ($block['type'] === 'automatedLatestContent') {
$content = $this->processAutomatedLatestContent($newsletter, $block, $columnBaseWidth); return $this->processAutomatedLatestContent($newsletter, $block, $columnBaseWidth);
return $content;
} }
$block = StylesHelper::applyTextAlignment($block); $block = StylesHelper::applyTextAlignment($block);
$blockClass = __NAMESPACE__ . '\\' . ucfirst($block['type']); switch ($block['type']) {
if (!class_exists($blockClass)) { case 'button':
return ''; 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) { public function automatedLatestContentTransformedPosts($newsletter, $args) {

View File

@@ -5,7 +5,7 @@ namespace MailPoet\Newsletter\Renderer\Blocks;
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper; use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
class Social { class Social {
public static function render($element) { public function render($element) {
$iconsBlock = ''; $iconsBlock = '';
if (is_array($element['icons'])) { if (is_array($element['icons'])) {
foreach ($element['icons'] as $index => $icon) { foreach ($element['icons'] as $index => $icon) {

View File

@@ -5,7 +5,7 @@ namespace MailPoet\Newsletter\Renderer\Blocks;
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper; use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
class Spacer { class Spacer {
public static function render($element) { public function render($element) {
$height = (int)$element['styles']['block']['height']; $height = (int)$element['styles']['block']['height'];
$backgroundColor = EHelper::escapeHtmlAttr($element['styles']['block']['backgroundColor']); $backgroundColor = EHelper::escapeHtmlAttr($element['styles']['block']['backgroundColor']);
$template = ' $template = '

View File

@@ -8,16 +8,16 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
use MailPoet\Util\pQuery\pQuery; use MailPoet\Util\pQuery\pQuery;
class Text { class Text {
public static function render($element) { public function render($element) {
$html = $element['text']; $html = $element['text'];
// replace &nbsp; with spaces // replace &nbsp; with spaces
$html = str_replace('&nbsp;', ' ', $html); $html = str_replace('&nbsp;', ' ', $html);
$html = str_replace('\xc2\xa0', ' ', $html); $html = str_replace('\xc2\xa0', ' ', $html);
$html = self::convertBlockquotesToTables($html); $html = $this->convertBlockquotesToTables($html);
$html = self::convertParagraphsToTables($html); $html = $this->convertParagraphsToTables($html);
$html = self::styleLists($html); $html = $this->styleLists($html);
$html = self::styleHeadings($html); $html = $this->styleHeadings($html);
$html = self::removeLastLineBreak($html); $html = $this->removeLastLineBreak($html);
$template = ' $template = '
<tr> <tr>
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;"> <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; return $template;
} }
public static function convertBlockquotesToTables($html) { public function convertBlockquotesToTables($html) {
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($html); $DOM = $dOMParser->parseStr($html);
$blockquotes = $DOM->query('blockquote'); $blockquotes = $DOM->query('blockquote');
@@ -67,12 +67,12 @@ class Text {
</tr> </tr>
</tbody>' </tbody>'
); );
$blockquote = self::insertLineBreak($blockquote); $blockquote = $this->insertLineBreak($blockquote);
} }
return $DOM->__toString(); return $DOM->__toString();
} }
public static function convertParagraphsToTables($html) { public function convertParagraphsToTables($html) {
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($html); $DOM = $dOMParser->parseStr($html);
$paragraphs = $DOM->query('p'); $paragraphs = $DOM->query('p');
@@ -95,7 +95,7 @@ class Text {
!$previousElement || !$previousElement ||
(preg_match('/h\d+/', $previousElementTag)) (preg_match('/h\d+/', $previousElementTag))
) { ) {
$paragraph = self::insertLineBreak($paragraph); $paragraph = $this->insertLineBreak($paragraph);
} }
$paragraph->remove(); $paragraph->remove();
continue; continue;
@@ -136,7 +136,7 @@ class Text {
return $DOM->__toString(); return $DOM->__toString();
} }
public static function styleLists($html) { public function styleLists($html) {
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($html); $DOM = $dOMParser->parseStr($html);
$lists = $DOM->query('ol, ul, li'); $lists = $DOM->query('ol, ul, li');
@@ -156,7 +156,7 @@ class Text {
return $DOM->__toString(); return $DOM->__toString();
} }
public static function styleHeadings($html) { public function styleHeadings($html) {
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($html); $DOM = $dOMParser->parseStr($html);
$headings = $DOM->query('h1, h2, h3, h4'); $headings = $DOM->query('h1, h2, h3, h4');
@@ -169,11 +169,11 @@ class Text {
return $DOM->__toString(); return $DOM->__toString();
} }
public static function removeLastLineBreak($html) { public function removeLastLineBreak($html) {
return preg_replace('/(^)?(<br[^>]*?\/?>)+$/i', '', $html); return preg_replace('/(^)?(<br[^>]*?\/?>)+$/i', '', $html);
} }
public static function insertLineBreak($element) { public function insertLineBreak($element) {
$element->parent->insertChild( $element->parent->insertChild(
[ [
'tag_name' => 'br', 'tag_name' => 'br',

View File

@@ -5,7 +5,6 @@ namespace MailPoet\Newsletter\Renderer;
use MailPoet\Config\Env; use MailPoet\Config\Env;
use MailPoet\DI\ContainerWrapper; use MailPoet\DI\ContainerWrapper;
use MailPoet\Models\Newsletter; use MailPoet\Models\Newsletter;
use MailPoet\Newsletter\AutomatedLatestContent;
use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper; use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper;
use MailPoet\Services\Bridge; use MailPoet\Services\Bridge;
use MailPoet\Util\License\License; use MailPoet\Util\License\License;
@@ -32,9 +31,7 @@ class Renderer {
public function __construct($newsletter, $preview = false) { public function __construct($newsletter, $preview = false) {
$this->newsletter = ($newsletter instanceof Newsletter) ? $newsletter->asArray() : $newsletter; $this->newsletter = ($newsletter instanceof Newsletter) ? $newsletter->asArray() : $newsletter;
$this->preview = $preview; $this->preview = $preview;
$this->blocksRenderer = new Blocks\Renderer( $this->blocksRenderer = ContainerWrapper::getInstance()->get(Blocks\Renderer::class);
ContainerWrapper::getInstance()->get(AutomatedLatestContent::class)
);
$this->columnsRenderer = new Columns\Renderer(); $this->columnsRenderer = new Columns\Renderer();
$this->preprocessor = new Preprocessor( $this->preprocessor = new Preprocessor(
$this->blocksRenderer, $this->blocksRenderer,

View File

@@ -3,7 +3,6 @@
namespace MailPoet\Test\API\JSON\v1; namespace MailPoet\Test\API\JSON\v1;
use MailPoet\API\JSON\v1\AutomatedLatestContent; use MailPoet\API\JSON\v1\AutomatedLatestContent;
use MailPoet\WP\Functions as WPFunctions;
class AutomatedLatestContentTest extends \MailPoetTest { class AutomatedLatestContentTest extends \MailPoetTest {
public function testItGetsPostTypes() { public function testItGetsPostTypes() {

View File

@@ -229,7 +229,7 @@ class RendererTest extends \MailPoetTest {
public function testItRendersHeader() { public function testItRendersHeader() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][0]; $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 // element should be properly nested, and styles should be applied
expect($DOM('tr > td.mailpoet_header', 0)->html())->notEmpty(); expect($DOM('tr > td.mailpoet_header', 0)->html())->notEmpty();
expect($DOM('tr > td > a', 0)->html())->notEmpty(); expect($DOM('tr > td > a', 0)->html())->notEmpty();
@@ -240,7 +240,7 @@ class RendererTest extends \MailPoetTest {
public function testItRendersImage() { public function testItRendersImage() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1]; $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 // element should be properly nested, it's width set and style applied
expect($DOM('tr > td > img', 0)->attr('width'))->equals(620); 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]; $template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
// default alignment (center) // default alignment (center)
unset($template['styles']['block']['textAlign']); 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'); expect($DOM('tr > td', 0)->attr('align'))->equals('center');
$template['styles']['block']['textAlign'] = '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'); expect($DOM('tr > td', 0)->attr('align'))->equals('center');
$template['styles']['block']['textAlign'] = 'something odd'; $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'); expect($DOM('tr > td', 0)->attr('align'))->equals('center');
// left alignment // left alignment
$template['styles']['block']['textAlign'] = 'left'; $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'); expect($DOM('tr > td', 0)->attr('align'))->equals('left');
// right alignment // right alignment
$template['styles']['block']['textAlign'] = 'right'; $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'); expect($DOM('tr > td', 0)->attr('align'))->equals('right');
} }
@@ -276,7 +276,7 @@ class RendererTest extends \MailPoetTest {
'link' => '', 'link' => '',
'alt' => 'some test alt text', '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(''); expect($renderedImage)->equals('');
} }
@@ -289,7 +289,7 @@ class RendererTest extends \MailPoetTest {
'fullWidth' => false, 'fullWidth' => false,
'alt' => 'some test alt text', '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'); $siteUrl = get_option('siteurl');
expect($renderedImage)->contains('src="' . $siteUrl . '/relative-path"'); expect($renderedImage)->contains('src="' . $siteUrl . '/relative-path"');
@@ -301,7 +301,7 @@ class RendererTest extends \MailPoetTest {
'fullWidth' => false, 'fullWidth' => false,
'alt' => 'some test alt text', '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"'); expect($renderedImage)->contains('src="//path-without-protocol"');
} }
@@ -309,7 +309,7 @@ class RendererTest extends \MailPoetTest {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1]; $template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
$template['link'] = 'http://example.com'; $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 // element should be wrapped in <a> tag
expect($DOM('tr > td > a', 0)->html())->contains('<img'); expect($DOM('tr > td > a', 0)->html())->contains('<img');
expect($DOM('tr > td > a', 0)->attr('href'))->equals($template['link']); expect($DOM('tr > td > a', 0)->attr('href'))->equals($template['link']);
@@ -322,25 +322,25 @@ class RendererTest extends \MailPoetTest {
'height' => 600, 'height' => 600,
'fullWidth' => true, '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['width'])->equals(660);
expect($newImageDimensions['height'])->equals(495); expect($newImageDimensions['height'])->equals(495);
// nothing happens when image width = column width // nothing happens when image width = column width
$image['width'] = 661; $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); expect($newImageDimensions['width'])->equals(660);
// nothing happens when image width < column width // nothing happens when image width < column width
$image['width'] = 659; $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); expect($newImageDimensions['width'])->equals(659);
// image is reduced by 40px when it's width > padded column width // image is reduced by 40px when it's width > padded column width
$image['width'] = 621; $image['width'] = 621;
$image['fullWidth'] = false; $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); expect($newImageDimensions['width'])->equals(620);
// nothing happens when image with < padded column width // nothing happens when image with < padded column width
$image['width'] = 619; $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); expect($newImageDimensions['width'])->equals(619);
} }
@@ -353,7 +353,7 @@ class RendererTest extends \MailPoetTest {
'fullWidth' => false, 'fullWidth' => false,
'alt' => 'some test alt text', '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"'); expect($renderedImage)->contains('width="auto"');
} }
@@ -366,7 +366,7 @@ class RendererTest extends \MailPoetTest {
'fullWidth' => false, 'fullWidth' => false,
'alt' => 'some test alt text', '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"'); expect($renderedImage)->contains('width="620"');
} }
@@ -379,14 +379,14 @@ class RendererTest extends \MailPoetTest {
'fullWidth' => false, 'fullWidth' => false,
'alt' => 'some test alt text', '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"'); expect($renderedImage)->contains('width="620"');
} }
public function testItRendersText() { public function testItRendersText() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][2]; $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 // blockquotes and paragraphs should be converted to spans and placed inside a table
expect( expect(
$DOM('tr > td > table > tr > td.mailpoet_paragraph', 0)->html() $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 // trailing line breaks should be cut off, but not inside an element
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][8]; $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))) expect(count($DOM('tr > td > br', 0)))
->equals(0); ->equals(0);
expect($DOM('tr > td > h3', 0)->html()) expect($DOM('tr > td > h3', 0)->html())
@@ -426,7 +426,7 @@ class RendererTest extends \MailPoetTest {
public function testItRendersDivider() { public function testItRendersDivider() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][3]; $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 // element should be properly nested and its border-top-width set
expect( expect(
preg_match( preg_match(
@@ -438,7 +438,7 @@ class RendererTest extends \MailPoetTest {
public function testItRendersSpacer() { public function testItRendersSpacer() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][4]; $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 // element should be properly nested and its height set
expect($DOM('tr > td.mailpoet_spacer', 0)->attr('height'))->equals(50); expect($DOM('tr > td.mailpoet_spacer', 0)->attr('height'))->equals(50);
} }
@@ -446,10 +446,10 @@ class RendererTest extends \MailPoetTest {
public function testItSetsSpacerBackground() { public function testItSetsSpacerBackground() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][4]; $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(); expect($DOM('tr > td.mailpoet_spacer', 0)->attr('bgcolor'))->null();
$template['styles']['block']['backgroundColor'] = '#ffff'; $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')) expect($DOM('tr > td.mailpoet_spacer', 0)->attr('bgcolor'))
->equals('#ffff'); ->equals('#ffff');
} }
@@ -458,14 +458,14 @@ class RendererTest extends \MailPoetTest {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5]; $template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
$template['styles']['block']['width'] = '700px'; $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) expect($buttonWidth)->equals('618px'); //(width - (2 * border width)
} }
public function testItRendersButton() { public function testItRendersButton() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5]; $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 // element should be properly nested with arcsize/styles/fillcolor set
expect( expect(
$DOM('tr > td > div > table > tr > td > a.mailpoet_button', 0)->html() $DOM('tr > td > div > table > tr > td > a.mailpoet_button', 0)->html()
@@ -501,7 +501,7 @@ class RendererTest extends \MailPoetTest {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5]; $template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
$template['styles']['block']['fontFamily'] = 'Lucida'; $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( expect(
preg_match( preg_match(
'/font-family: \'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif/', '/font-family: \'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif/',
@@ -512,7 +512,7 @@ class RendererTest extends \MailPoetTest {
public function testItRendersSocialIcons() { public function testItRendersSocialIcons() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][6]; $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 // element should be properly nested, contain social icons and
// image source/link href/alt should be properly set // image source/link href/alt should be properly set
expect($DOM('tr > td', 0)->html())->notEmpty(); expect($DOM('tr > td', 0)->html())->notEmpty();
@@ -533,14 +533,14 @@ class RendererTest extends \MailPoetTest {
'iconType' => 'custom', 'iconType' => 'custom',
], ],
]; ];
$renderedBlock = Social::render($block); $renderedBlock = (new Social)->render($block);
expect($renderedBlock)->equals(''); expect($renderedBlock)->equals('');
} }
public function testItRendersFooter() { public function testItRendersFooter() {
$newsletter = $this->newsletter['body']; $newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][3]['blocks'][0]['blocks'][0]; $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 // element should be properly nested, and styles should be applied
expect($DOM('tr > td.mailpoet_footer', 0)->html())->notEmpty(); expect($DOM('tr > td.mailpoet_footer', 0)->html())->notEmpty();
expect($DOM('tr > td > a', 0)->html())->notEmpty(); expect($DOM('tr > td > a', 0)->html())->notEmpty();

View File

@@ -27,7 +27,7 @@ class ButtonTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Button::render($this->block, 200); $output = (new Button)->render($this->block, 200);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_padded_vertical mailpoet_padded_side" valign="top"> <td class="mailpoet_padded_vertical mailpoet_padded_side" valign="top">

View File

@@ -18,7 +18,7 @@ class DividerTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Divider::render($this->block); $output = (new Divider)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_divider" valign="top" style="padding: 13px 20px 13px 20px;"> <td class="mailpoet_divider" valign="top" style="padding: 13px 20px 13px 20px;">

View File

@@ -25,7 +25,7 @@ class FooterTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Footer::render($this->block); $output = (new Footer)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <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;"> <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() { public function testItRendersWithBackgroundColor() {
$this->block['styles']['block']['backgroundColor'] = '#f0f0f0'; $this->block['styles']['block']['backgroundColor'] = '#f0f0f0';
$output = Footer::render($this->block); $output = (new Footer)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <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;"> <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() { public function testItPrefersInlinedCssForLinks() {
$this->block['text'] = '<p>Footer text. <a href="http://example.com" style="color:#aaaaaa;">link</a></p>'; $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>'); expect($output)->contains('<a href="http://example.com" style="color:#aaaaaa;text-decoration:none">link</a>');
} }
} }

View File

@@ -25,7 +25,7 @@ class HeaderTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Header::render($this->block); $output = (new Header)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <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;"> <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() { public function testItRendersBackgroundColorCorrectly() {
$this->block['styles']['block']['backgroundColor'] = '#f0f0f0'; $this->block['styles']['block']['backgroundColor'] = '#f0f0f0';
$output = Header::render($this->block); $output = (new Header)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <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;"> <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() { public function testItPrefersInlinedCssForLinks() {
$this->block['text'] = '<p>Header text. <a href="http://example.com" style="color:#aaaaaa;">link</a></p>'; $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>'); expect($output)->contains('<a href="http://example.com" style="color:#aaaaaa;text-decoration:underline">link</a>');
} }
} }

View File

@@ -20,7 +20,7 @@ class ImageTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Image::render($this->block, 200); $output = (new Image)->render($this->block, 200);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top"> <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() { public function testItRendersWithoutLink() {
$this->block['link'] = null; $this->block['link'] = null;
$output = Image::render($this->block, 200); $output = (new Image)->render($this->block, 200);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top"> <td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top">

View File

@@ -35,7 +35,7 @@ class SocialTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Social::render($this->block); $output = (new Social)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_padded_side mailpoet_padded_vertical" valign="top" align="center"> <td class="mailpoet_padded_side mailpoet_padded_vertical" valign="top" align="center">

View File

@@ -15,7 +15,7 @@ class SpacerTest extends \MailPoetUnitTest {
]; ];
public function testItRendersCorrectly() { public function testItRendersCorrectly() {
$output = Spacer::render($this->block); $output = (new Spacer)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_spacer" height="13" valign="top"></td> <td class="mailpoet_spacer" height="13" valign="top"></td>
@@ -25,7 +25,7 @@ class SpacerTest extends \MailPoetUnitTest {
public function testsItRendersWithBackground() { public function testsItRendersWithBackground() {
$this->block['styles']['block']['backgroundColor'] = "#ffffff"; $this->block['styles']['block']['backgroundColor'] = "#ffffff";
$output = Spacer::render($this->block); $output = (new Spacer)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_spacer" bgcolor="#ffffff" height="13" valign="top"></td> <td class="mailpoet_spacer" bgcolor="#ffffff" height="13" valign="top"></td>

View File

@@ -20,7 +20,7 @@ class TextTest extends \MailPoetUnitTest {
} }
public function testItRendersPlainText() { public function testItRendersPlainText() {
$output = Text::render($this->block); $output = (new Text)->render($this->block);
$expectedResult = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;"> <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() { public function testItRendersParagraph() {
$this->block['text'] = '<p>Text</p>'; $this->block['text'] = '<p>Text</p>';
$output = Text::render($this->block); $output = (new Text)->render($this->block);
$table = $this->parser->parseStr($output)->query('table'); $table = $this->parser->parseStr($output)->query('table');
assert($table instanceof \pQuery); assert($table instanceof \pQuery);
$paragraphTable = $table[0]->toString(); $paragraphTable = $table[0]->toString();
@@ -47,7 +47,7 @@ class TextTest extends \MailPoetUnitTest {
public function testItRendersList() { public function testItRendersList() {
$this->block['text'] = '<ul><li>Item 1</li><li>Item 2</li></ul>'; $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'); $ul = $this->parser->parseStr($output)->query('ul');
assert($ul instanceof \pQuery); assert($ul instanceof \pQuery);
$list = $ul[0]->toString(); $list = $ul[0]->toString();
@@ -57,7 +57,7 @@ class TextTest extends \MailPoetUnitTest {
public function testItRendersBlockquotes() { public function testItRendersBlockquotes() {
$this->block['text'] = '<blockquote><p>Quote</p></blockquote>'; $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'); $table = $this->parser->parseStr($output)->query('table');
assert($table instanceof \pQuery); assert($table instanceof \pQuery);
$blockquoteTable = $table[0]->toString(); $blockquoteTable = $table[0]->toString();
@@ -82,7 +82,7 @@ class TextTest extends \MailPoetUnitTest {
public function testItShouldRemoveEmptyParagraphs() { public function testItShouldRemoveEmptyParagraphs() {
$this->block['text'] = '<p></p><p>Text</p><p></p><p>Text2</p><p></p><p></p>'; $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 = ' $expectedResult = '
<tr> <tr>
<td class="mailpoet_text mailpoet_padded_vertical mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;"> <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() { public function testItStylesHeadings() {
$this->block['text'] = '<h1>Heading</h1><h2>Heading 2</h2>'; $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('<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>'); expect($output)->contains('<h2 style="text-align:left;padding:0;font-style:normal;font-weight:normal;">Heading 2</h2>');
} }
public function testItRemovesLastLineBreak() { public function testItRemovesLastLineBreak() {
$this->block['text'] = 'hello<br />'; $this->block['text'] = 'hello<br />';
$output = Text::render($this->block); $output = (new Text)->render($this->block);
expect($output)->notContains('<br />'); expect($output)->notContains('<br />');
} }
} }