Fix namespace in unit tests
[MAILPOET-6216]
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Postprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\HighlightingPostprocessor;
|
||||
|
||||
class HighlightingPostprocessorTest extends \MailPoetUnitTest {
|
||||
/** @var HighlightingPostprocessor */
|
||||
private $postprocessor;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->postprocessor = new HighlightingPostprocessor();
|
||||
}
|
||||
|
||||
public function testItReplacesHtmlElements(): void {
|
||||
$html = '
|
||||
<mark>Some text</mark>
|
||||
<p>Some <mark style="color:red;">paragraph</mark></p>
|
||||
<a href="http://example.com">Some <mark style="font-weight:bold;">link</mark></a>
|
||||
';
|
||||
$result = $this->postprocessor->postprocess($html);
|
||||
$this->assertEquals( '
|
||||
<span>Some text</span>
|
||||
<p>Some <span style="color:red;">paragraph</span></p>
|
||||
<a href="http://example.com">Some <span style="font-weight:bold;">link</span></a>
|
||||
', $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Postprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\VariablesPostprocessor;
|
||||
use MailPoet\EmailEditor\Engine\ThemeController;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class VariablesPostprocessorTest extends \MailPoetUnitTest {
|
||||
private VariablesPostprocessor $postprocessor;
|
||||
|
||||
/** @var ThemeController & MockObject */
|
||||
private $themeControllerMock;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->themeControllerMock = $this->createMock(ThemeController::class);
|
||||
$this->postprocessor = new VariablesPostprocessor($this->themeControllerMock);
|
||||
}
|
||||
|
||||
public function testItReplacesVariablesInStyleAttributes(): void {
|
||||
$variablesMap = [
|
||||
'--wp--preset--spacing--10' => '10px',
|
||||
'--wp--preset--spacing--20' => '20px',
|
||||
'--wp--preset--spacing--30' => '30px',
|
||||
];
|
||||
$this->themeControllerMock->method('getVariablesValuesMap')->willReturn($variablesMap);
|
||||
$html = '<div style="padding:var(--wp--preset--spacing--10);margin:var(--wp--preset--spacing--20)"><p style="color:white;padding-left:var(--wp--preset--spacing--10);">Helloo I have padding var(--wp--preset--spacing--10); </p></div>';
|
||||
$result = $this->postprocessor->postprocess($html);
|
||||
$this->assertEquals('<div style="padding:10px;margin:20px"><p style="color:white;padding-left:10px;">Helloo I have padding var(--wp--preset--spacing--10); </p></div>', $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,463 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\BlocksWidthPreprocessor;
|
||||
|
||||
class BlocksWidthPreprocessorTest extends \MailPoetUnitTest {
|
||||
|
||||
/** @var BlocksWidthPreprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new BlocksWidthPreprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
|
||||
public function testItCalculatesWidthWithoutPadding(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '50%',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '25%',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '100px',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$styles = $this->styles;
|
||||
$styles['spacing']['padding'] = ['left' => '0px', 'right' => '0px', 'top' => '0px', 'bottom' => '0px'];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $styles);
|
||||
$result = $result[0];
|
||||
$this->assertEquals('660px', $result['email_attrs']['width']);
|
||||
$this->assertCount(3, $result['innerBlocks']);
|
||||
$this->assertEquals('330px', $result['innerBlocks'][0]['email_attrs']['width']); // 660 * 0.5
|
||||
$this->assertEquals('165px', $result['innerBlocks'][1]['email_attrs']['width']); // 660 * 0.25
|
||||
$this->assertEquals('100px', $result['innerBlocks'][2]['email_attrs']['width']);
|
||||
}
|
||||
|
||||
public function testItCalculatesWidthWithLayoutPadding(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '33%',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '100px',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '20%',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$result = $result[0];
|
||||
$this->assertCount(3, $result['innerBlocks']);
|
||||
$this->assertEquals('211px', $result['innerBlocks'][0]['email_attrs']['width']); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals('100px', $result['innerBlocks'][1]['email_attrs']['width']);
|
||||
$this->assertEquals('128px', $result['innerBlocks'][2]['email_attrs']['width']); // (660 - 10 - 10) * 0.2
|
||||
}
|
||||
|
||||
public function testItCalculatesWidthOfBlockInColumn(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '40%',
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '60%',
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
|
||||
$this->assertCount(2, $innerBlocks);
|
||||
$this->assertEquals('256px', $innerBlocks[0]['email_attrs']['width']); // (660 - 10 - 10) * 0.4
|
||||
$this->assertEquals('236px', $innerBlocks[0]['innerBlocks'][0]['email_attrs']['width']); // 256 - 10 - 10
|
||||
$this->assertEquals('384px', $innerBlocks[1]['email_attrs']['width']); // (660 - 10 - 10) * 0.6
|
||||
$this->assertEquals('344px', $innerBlocks[1]['innerBlocks'][0]['email_attrs']['width']); // 384 - 25 - 15
|
||||
}
|
||||
|
||||
public function testItAddsMissingColumnWidth(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$result = $this->preprocessor->preprocess($blocks, ['contentSize' => '620px'], $this->styles);
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
|
||||
$this->assertCount(3, $innerBlocks);
|
||||
$this->assertEquals('200px', $innerBlocks[0]['email_attrs']['width']); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals('200px', $innerBlocks[0]['innerBlocks'][0]['email_attrs']['width']);
|
||||
$this->assertEquals('200px', $innerBlocks[1]['email_attrs']['width']); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals('200px', $innerBlocks[1]['innerBlocks'][0]['email_attrs']['width']);
|
||||
$this->assertEquals('200px', $innerBlocks[2]['email_attrs']['width']); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals('200px', $innerBlocks[2]['innerBlocks'][0]['email_attrs']['width']);
|
||||
}
|
||||
|
||||
public function testItCalculatesMissingColumnWidth(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '33.33%',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '200px',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
|
||||
$this->assertCount(3, $innerBlocks);
|
||||
$this->assertEquals('200px', $innerBlocks[0]['email_attrs']['width']); // (620 - 10 - 10) * 0.3333
|
||||
$this->assertEquals('200px', $innerBlocks[1]['email_attrs']['width']); // already defined
|
||||
$this->assertEquals('200px', $innerBlocks[2]['email_attrs']['width']); // 600 -200 - 200
|
||||
}
|
||||
|
||||
public function testItDoesNotSubtractPaddingForFullWidthBlocks(): void {
|
||||
$blocks = [
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'align' => 'full',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals('660px', $result[0]['email_attrs']['width']); // full width
|
||||
$this->assertEquals('640px', $result[1]['email_attrs']['width']); // 660 - 10 - 10
|
||||
}
|
||||
|
||||
public function testItCalculatesWidthForColumnWithoutDefinition(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '140px',
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '20px',
|
||||
'right' => '20px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(3, $result[0]['innerBlocks']);
|
||||
$this->assertEquals('140px', $result[0]['innerBlocks'][0]['email_attrs']['width']);
|
||||
$this->assertEquals('220px', $result[0]['innerBlocks'][1]['email_attrs']['width']);
|
||||
$this->assertEquals('240px', $result[0]['innerBlocks'][2]['email_attrs']['width']);
|
||||
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '140px',
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(2, $result[0]['innerBlocks']);
|
||||
$this->assertEquals('140px', $result[0]['innerBlocks'][0]['email_attrs']['width']);
|
||||
$this->assertEquals('500px', $result[0]['innerBlocks'][1]['email_attrs']['width']);
|
||||
}
|
||||
|
||||
public function testItCalculatesWidthForColumnWithBorder(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'border' => [
|
||||
'width' => '10px',
|
||||
],
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'width' => '140px',
|
||||
'style' => [
|
||||
'border' => [
|
||||
'left' => [
|
||||
'width' => '5px',
|
||||
],
|
||||
'right' => [
|
||||
'width' => '5px',
|
||||
],
|
||||
],
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'border' => [
|
||||
'width' => '15px',
|
||||
],
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '20px',
|
||||
'right' => '20px',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(3, $result[0]['innerBlocks']);
|
||||
$this->assertEquals('140px', $result[0]['innerBlocks'][0]['email_attrs']['width']);
|
||||
$this->assertEquals('185px', $result[0]['innerBlocks'][1]['email_attrs']['width']);
|
||||
$this->assertEquals('255px', $result[0]['innerBlocks'][2]['email_attrs']['width']);
|
||||
$imageBlock = $result[0]['innerBlocks'][1]['innerBlocks'][0];
|
||||
$this->assertEquals('185px', $imageBlock['email_attrs']['width']);
|
||||
$imageBlock = $result[0]['innerBlocks'][2]['innerBlocks'][0];
|
||||
$this->assertEquals('215px', $imageBlock['email_attrs']['width']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\CleanupPreprocessor;
|
||||
|
||||
class CleanupPreprocessorTest extends \MailPoetUnitTest {
|
||||
|
||||
private const PARAGRAPH_BLOCK = [
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerHTML' => 'Paragraph content',
|
||||
];
|
||||
|
||||
private const COLUMNS_BLOCK = [
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
]],
|
||||
];
|
||||
|
||||
/** @var CleanupPreprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new CleanupPreprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
|
||||
public function testItRemovesUnwantedBlocks(): void {
|
||||
$blocks = [
|
||||
self::COLUMNS_BLOCK,
|
||||
['blockName' => null, 'attrs' => [], 'innerHTML' => "\r\n"],
|
||||
self::PARAGRAPH_BLOCK,
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals(self::COLUMNS_BLOCK, $result[0]);
|
||||
$this->assertEquals(self::PARAGRAPH_BLOCK, $result[1]);
|
||||
}
|
||||
|
||||
public function testItPreservesAllRelevantBlocks(): void {
|
||||
$blocks = [
|
||||
self::COLUMNS_BLOCK,
|
||||
self::PARAGRAPH_BLOCK,
|
||||
self::COLUMNS_BLOCK,
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertEquals(self::COLUMNS_BLOCK, $result[0]);
|
||||
$this->assertEquals(self::PARAGRAPH_BLOCK, $result[1]);
|
||||
$this->assertEquals(self::COLUMNS_BLOCK, $result[2]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\SpacingPreprocessor;
|
||||
|
||||
class SpacingPreprocessorTest extends \MailPoetUnitTest {
|
||||
|
||||
/** @var SpacingPreprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new SpacingPreprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
|
||||
public function testItAddsDefaultVerticalSpacing(): void {
|
||||
$blocks = [
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/list',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/img',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/heading',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$expectedEmailAttrs = ['margin-top' => '10px'];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(2, $result);
|
||||
$firstColumns = $result[0];
|
||||
$secondColumns = $result[1];
|
||||
|
||||
// First elements should not have margin-top, but others should.
|
||||
$this->assertArrayNotHasKey('margin-top', $firstColumns['email_attrs']);
|
||||
$this->arrayHasKey('margin-top', $secondColumns['email_attrs']);
|
||||
$this->assertEquals('10px', $secondColumns['email_attrs']['margin-top']);
|
||||
|
||||
// First element children should have margin-top unless first child.
|
||||
$this->assertArrayNotHasKey('margin-top', $firstColumns['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertArrayHasKey('margin-top', $firstColumns['innerBlocks'][1]['email_attrs']);
|
||||
$this->assertEquals('10px', $firstColumns['innerBlocks'][1]['email_attrs']['margin-top']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,276 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\TypographyPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\SettingsController;
|
||||
|
||||
class TypographyPreprocessorTest extends \MailPoetUnitTest {
|
||||
|
||||
/** @var TypographyPreprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$settingsMock = $this->createMock(SettingsController::class);
|
||||
$themeMock = $this->createMock(\WP_Theme_JSON::class);
|
||||
$themeMock->method('get_data')->willReturn([
|
||||
'styles' => [
|
||||
'color' => [
|
||||
'text' => '#000000',
|
||||
],
|
||||
'typography' => [
|
||||
'fontSize' => '13px',
|
||||
'fontFamily' => 'Arial',
|
||||
],
|
||||
],
|
||||
'settings' => [
|
||||
'typography' => [
|
||||
'fontFamilies' => [
|
||||
[
|
||||
'slug' => 'arial-slug',
|
||||
'name' => 'Arial Name',
|
||||
'fontFamily' => 'Arial',
|
||||
],
|
||||
[
|
||||
'slug' => 'georgia-slug',
|
||||
'name' => 'Georgia Name',
|
||||
'fontFamily' => 'Georgia',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$settingsMock->method('getTheme')->willReturn($themeMock);
|
||||
// This slug translate mock expect slugs in format slug-10px and will return 10px
|
||||
$settingsMock->method('translateSlugToFontSize')->willReturnCallback(function($slug) {
|
||||
return str_replace('slug-', '', $slug);
|
||||
});
|
||||
$this->preprocessor = new TypographyPreprocessor($settingsMock);
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
|
||||
public function testItCopiesColumnsTypography(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'fontFamily' => 'arial-slug',
|
||||
'style' => [
|
||||
'color' => [
|
||||
'text' => '#aa00dd',
|
||||
],
|
||||
'typography' => [
|
||||
'fontSize' => '12px',
|
||||
'textDecoration' => 'underline',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$expectedEmailAttrs = [
|
||||
'color' => '#aa00dd',
|
||||
'font-size' => '12px',
|
||||
'text-decoration' => 'underline',
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$result = $result[0];
|
||||
$this->assertCount(2, $result['innerBlocks']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][1]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs']);
|
||||
}
|
||||
|
||||
public function testItReplacesFontSizeSlugsWithValues(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'fontSize' => 'slug-20px',
|
||||
'style' => [],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$expectedEmailAttrs = [
|
||||
'color' => '#000000',
|
||||
'font-size' => '20px',
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$result = $result[0];
|
||||
$this->assertCount(2, $result['innerBlocks']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][1]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs']);
|
||||
}
|
||||
|
||||
public function testItDoesNotCopyColumnsWidth(): void {
|
||||
$blocks = [[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'email_attrs' => [
|
||||
'width' => '640px',
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$result = $result[0];
|
||||
$this->assertCount(2, $result['innerBlocks']);
|
||||
$this->assertEquals(['width' => '640px', 'color' => '#000000', 'font-size' => '13px'], $result['email_attrs']);
|
||||
$defaultFontStyles = ['color' => '#000000', 'font-size' => '13px'];
|
||||
$this->assertEquals($defaultFontStyles, $result['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($defaultFontStyles, $result['innerBlocks'][1]['email_attrs']);
|
||||
$this->assertEquals($defaultFontStyles, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs']);
|
||||
}
|
||||
|
||||
public function testItOverridesColumnsTypography(): void {
|
||||
$blocks = [
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [
|
||||
'fontFamily' => 'arial-slug',
|
||||
'style' => [
|
||||
'color' => [
|
||||
'text' => '#aa00dd',
|
||||
],
|
||||
'typography' => [
|
||||
'fontSize' => '12px',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'fontFamily' => 'georgia-slug',
|
||||
'style' => [
|
||||
'color' => [
|
||||
'text' => '#cc22aa',
|
||||
],
|
||||
'typography' => [
|
||||
'fontSize' => '18px',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [
|
||||
'fontFamily' => 'georgia-slug',
|
||||
'style' => [
|
||||
'color' => [
|
||||
'text' => '#cc22aa',
|
||||
],
|
||||
'typography' => [
|
||||
'fontSize' => '18px',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$expectedEmailAttrs1 = [
|
||||
'color' => '#aa00dd',
|
||||
'font-size' => '12px',
|
||||
];
|
||||
$expectedEmailAttrs2 = [
|
||||
'color' => '#cc22aa',
|
||||
'font-size' => '18px',
|
||||
];
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$child1 = $result[0];
|
||||
$child2 = $result[1];
|
||||
$this->assertCount(2, $child1['innerBlocks']);
|
||||
$this->assertEquals($expectedEmailAttrs1, $child1['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs2, $child1['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs2, $child1['innerBlocks'][0]['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs1, $child1['innerBlocks'][1]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs1, $child1['innerBlocks'][1]['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertCount(1, $child2['innerBlocks']);
|
||||
$this->assertEquals(['color' => '#000000', 'font-size' => '13px'], $child2['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs2, $child2['innerBlocks'][0]['email_attrs']);
|
||||
$this->assertEquals($expectedEmailAttrs2, $child2['innerBlocks'][0]['innerBlocks'][0]['email_attrs']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\HighlightingPostprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\VariablesPostprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\BlocksWidthPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\CleanupPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\SpacingPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\TypographyPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\ProcessManager;
|
||||
|
||||
class ProcessManagerTest extends \MailPoetUnitTest {
|
||||
public function testItCallsPreprocessorsProperly(): void {
|
||||
$layout = [
|
||||
'contentSize' => '600px',
|
||||
];
|
||||
$styles = [
|
||||
'spacing' => [
|
||||
'blockGap' => '0px',
|
||||
'padding' => [
|
||||
'bottom' => '0px',
|
||||
'left' => '0px',
|
||||
'right' => '0px',
|
||||
'top' => '0px',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$cleanup = $this->createMock(CleanupPreprocessor::class);
|
||||
$cleanup->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
|
||||
$blocksWidth = $this->createMock(BlocksWidthPreprocessor::class);
|
||||
$blocksWidth->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
|
||||
$typography = $this->createMock(TypographyPreprocessor::class);
|
||||
$typography->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
|
||||
$spacing = $this->createMock(SpacingPreprocessor::class);
|
||||
$spacing->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
|
||||
$highlighting = $this->createMock(HighlightingPostprocessor::class);
|
||||
$highlighting->expects($this->once())->method('postprocess')->willReturn('');
|
||||
|
||||
$variables = $this->createMock(VariablesPostprocessor::class);
|
||||
$variables->expects($this->once())->method('postprocess')->willReturn('');
|
||||
|
||||
$processManager = new ProcessManager($cleanup, $blocksWidth, $typography, $spacing, $highlighting, $variables);
|
||||
$this->assertEquals([], $processManager->preprocess([], $layout, $styles));
|
||||
$this->assertEmpty($processManager->postprocess(''));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user