Move email editor unit tests

[MAILPOET-6216]
This commit is contained in:
Jan Lysý
2024-09-10 19:44:38 +02:00
committed by Jan Lysý
parent 09a8d7445b
commit 0860f7c45f
9 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
<?php declare(strict_types = 1);
namespace 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);
verify($result)->equals('
<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>
');
}
}

View File

@@ -0,0 +1,32 @@
<?php declare(strict_types = 1);
namespace 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);
verify($result)->equals('<div style="padding:10px;margin:20px"><p style="color:white;padding-left:10px;">Helloo I have padding var(--wp--preset--spacing--10); </p></div>');
}
}

View File

@@ -0,0 +1,463 @@
<?php declare(strict_types = 1);
namespace 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];
verify($result['email_attrs']['width'])->equals('660px');
verify($result['innerBlocks'])->arrayCount(3);
verify($result['innerBlocks'][0]['email_attrs']['width'])->equals('330px'); // 660 * 0.5
verify($result['innerBlocks'][1]['email_attrs']['width'])->equals('165px'); // 660 * 0.25
verify($result['innerBlocks'][2]['email_attrs']['width'])->equals('100px');
}
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];
verify($result['innerBlocks'])->arrayCount(3);
verify($result['innerBlocks'][0]['email_attrs']['width'])->equals('211px'); // (660 - 10 - 10) * 0.33
verify($result['innerBlocks'][1]['email_attrs']['width'])->equals('100px');
verify($result['innerBlocks'][2]['email_attrs']['width'])->equals('128px'); // (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'];
verify($innerBlocks)->arrayCount(2);
verify($innerBlocks[0]['email_attrs']['width'])->equals('256px'); // (660 - 10 - 10) * 0.4
verify($innerBlocks[0]['innerBlocks'][0]['email_attrs']['width'])->equals('236px'); // 256 - 10 - 10
verify($innerBlocks[1]['email_attrs']['width'])->equals('384px'); // (660 - 10 - 10) * 0.6
verify($innerBlocks[1]['innerBlocks'][0]['email_attrs']['width'])->equals('344px'); // 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'];
verify($innerBlocks)->arrayCount(3);
verify($innerBlocks[0]['email_attrs']['width'])->equals('200px'); // (660 - 10 - 10) * 0.33
verify($innerBlocks[0]['innerBlocks'][0]['email_attrs']['width'])->equals('200px');
verify($innerBlocks[1]['email_attrs']['width'])->equals('200px'); // (660 - 10 - 10) * 0.33
verify($innerBlocks[1]['innerBlocks'][0]['email_attrs']['width'])->equals('200px');
verify($innerBlocks[2]['email_attrs']['width'])->equals('200px'); // (660 - 10 - 10) * 0.33
verify($innerBlocks[2]['innerBlocks'][0]['email_attrs']['width'])->equals('200px');
}
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'];
verify($innerBlocks)->arrayCount(3);
verify($innerBlocks[0]['email_attrs']['width'])->equals('200px'); // (620 - 10 - 10) * 0.3333
verify($innerBlocks[1]['email_attrs']['width'])->equals('200px'); // already defined
verify($innerBlocks[2]['email_attrs']['width'])->equals('200px'); // 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);
verify($result)->arrayCount(2);
verify($result[0]['email_attrs']['width'])->equals('660px'); // full width
verify($result[1]['email_attrs']['width'])->equals('640px'); // 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);
verify($result[0]['innerBlocks'])->arrayCount(3);
verify($result[0]['innerBlocks'][0]['email_attrs']['width'])->equals('140px');
verify($result[0]['innerBlocks'][1]['email_attrs']['width'])->equals('220px');
verify($result[0]['innerBlocks'][2]['email_attrs']['width'])->equals('240px');
$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);
verify($result[0]['innerBlocks'])->arrayCount(2);
verify($result[0]['innerBlocks'][0]['email_attrs']['width'])->equals('140px');
verify($result[0]['innerBlocks'][1]['email_attrs']['width'])->equals('500px');
}
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);
verify($result[0]['innerBlocks'])->arrayCount(3);
verify($result[0]['innerBlocks'][0]['email_attrs']['width'])->equals('140px');
verify($result[0]['innerBlocks'][1]['email_attrs']['width'])->equals('185px');
verify($result[0]['innerBlocks'][2]['email_attrs']['width'])->equals('255px');
$imageBlock = $result[0]['innerBlocks'][1]['innerBlocks'][0];
verify($imageBlock['email_attrs']['width'])->equals('185px');
$imageBlock = $result[0]['innerBlocks'][2]['innerBlocks'][0];
verify($imageBlock['email_attrs']['width'])->equals('215px');
}
}

View File

@@ -0,0 +1,65 @@
<?php declare(strict_types = 1);
namespace 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);
verify($result)->arrayCount(2);
verify($result[0])->equals(self::COLUMNS_BLOCK);
verify($result[1])->equals(self::PARAGRAPH_BLOCK);
}
public function testItPreservesAllRelevantBlocks(): void {
$blocks = [
self::COLUMNS_BLOCK,
self::PARAGRAPH_BLOCK,
self::COLUMNS_BLOCK,
];
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
verify($result)->arrayCount(3);
verify($result[0])->equals(self::COLUMNS_BLOCK);
verify($result[1])->equals(self::PARAGRAPH_BLOCK);
verify($result[2])->equals(self::COLUMNS_BLOCK);
}
}

View File

@@ -0,0 +1,94 @@
<?php declare(strict_types = 1);
namespace 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);
verify($result)->arrayCount(2);
$firstColumns = $result[0];
$secondColumns = $result[1];
// First elements should not have margin-top, but others should.
verify($firstColumns['email_attrs'])->arrayHasNotKey('margin-top');
verify($secondColumns['email_attrs'])->arrayHasKey('margin-top');
verify($secondColumns['email_attrs']['margin-top'])->equals('10px');
// First element children should have margin-top unless first child.
verify($firstColumns['innerBlocks'][0]['email_attrs'])->arrayHasNotKey('margin-top');
verify($firstColumns['innerBlocks'][1]['email_attrs'])->arrayHasKey('margin-top');
verify($firstColumns['innerBlocks'][1]['email_attrs']['margin-top'])->equals('10px');
}
}

View File

@@ -0,0 +1,276 @@
<?php declare(strict_types = 1);
namespace 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];
verify($result['innerBlocks'])->arrayCount(2);
verify($result['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][1]['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs);
}
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];
verify($result['innerBlocks'])->arrayCount(2);
verify($result['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][1]['email_attrs'])->equals($expectedEmailAttrs);
verify($result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs);
}
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];
verify($result['innerBlocks'])->arrayCount(2);
verify($result['email_attrs'])->equals(['width' => '640px', 'color' => '#000000', 'font-size' => '13px']);
$defaultFontStyles = ['color' => '#000000', 'font-size' => '13px'];
verify($result['innerBlocks'][0]['email_attrs'])->equals($defaultFontStyles);
verify($result['innerBlocks'][1]['email_attrs'])->equals($defaultFontStyles);
verify($result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($defaultFontStyles);
}
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];
verify($child1['innerBlocks'])->arrayCount(2);
verify($child1['email_attrs'])->equals($expectedEmailAttrs1);
verify($child1['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2);
verify($child1['innerBlocks'][0]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2);
verify($child1['innerBlocks'][1]['email_attrs'])->equals($expectedEmailAttrs1);
verify($child1['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs1);
verify($child2['innerBlocks'])->arrayCount(1);
verify($child2['email_attrs'])->equals(['color' => '#000000', 'font-size' => '13px']);
verify($child2['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2);
verify($child2['innerBlocks'][0]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2);
}
}

View File

@@ -0,0 +1,52 @@
<?php declare(strict_types = 1);
namespace 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);
verify($processManager->preprocess([], $layout, $styles))->equals([]);
verify($processManager->postprocess(''))->equals('');
}
}

View File

@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);
namespace EmailEditor\Engine;
use MailPoet\EmailEditor\Engine\SettingsController;
use MailPoet\EmailEditor\Engine\ThemeController;
class SettingsControllerTest extends \MailPoetUnitTest {
public function testItGetsCorrectLayoutWidthWithoutPadding(): void {
$themeJsonMock = $this->createMock(\WP_Theme_JSON::class);
$themeJsonMock->method('get_data')->willReturn([
'styles' => [
'spacing' => [
'padding' => [
'left' => '10px',
'right' => '10px',
],
],
],
]);
$themeController = $this->createMock(ThemeController::class);
$themeController->method('getTheme')->willReturn($themeJsonMock);
$themeController->method('getSettings')->willReturn([
"layout" => [
"contentSize" => "660px",
"wideSize" => "660px",
],
]);
$settingsController = new SettingsController($themeController);
$layoutWidth = $settingsController->getLayoutWidthWithoutPadding();
// default width is 660px and if we subtract padding from left and right we must get the correct value
$expectedWidth = (int)SettingsController::EMAIL_WIDTH - 10 * 2;
verify($layoutWidth)->equals($expectedWidth . 'px');
}
}