Change coding style in email editor tests to WordPress
This commit contains automated changes made with phpcbf command from CodeSniffer package. [MAILPOET-6240]
This commit is contained in:
@@ -5,25 +5,28 @@ namespace MailPoet\EmailEditor\Engine\Renderer\Postprocessors;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Highlighting_Postprocessor;
|
||||
|
||||
class Highlighting_Postprocessor_Test extends \MailPoetUnitTest {
|
||||
/** @var Highlighting_Postprocessor */
|
||||
private $postprocessor;
|
||||
/** @var Highlighting_Postprocessor */
|
||||
private $postprocessor;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->postprocessor = new Highlighting_Postprocessor();
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->postprocessor = new Highlighting_Postprocessor();
|
||||
}
|
||||
|
||||
public function testItReplacesHtmlElements(): void {
|
||||
$html = '
|
||||
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( '
|
||||
$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);
|
||||
}
|
||||
',
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -7,26 +7,26 @@ use MailPoet\EmailEditor\Engine\Theme_Controller;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class Variables_Postprocessor_Test extends \MailPoetUnitTest {
|
||||
private Variables_Postprocessor $postprocessor;
|
||||
private Variables_Postprocessor $postprocessor;
|
||||
|
||||
/** @var Theme_Controller & MockObject */
|
||||
private $themeControllerMock;
|
||||
/** @var Theme_Controller & MockObject */
|
||||
private $themeControllerMock;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->themeControllerMock = $this->createMock(Theme_Controller::class);
|
||||
$this->postprocessor = new Variables_Postprocessor($this->themeControllerMock);
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->themeControllerMock = $this->createMock( Theme_Controller::class );
|
||||
$this->postprocessor = new Variables_Postprocessor( $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('get_variables_values_map')->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);
|
||||
}
|
||||
public function testItReplacesVariablesInStyleAttributes(): void {
|
||||
$variablesMap = array(
|
||||
'--wp--preset--spacing--10' => '10px',
|
||||
'--wp--preset--spacing--20' => '20px',
|
||||
'--wp--preset--spacing--30' => '30px',
|
||||
);
|
||||
$this->themeControllerMock->method( 'get_variables_values_map' )->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 );
|
||||
}
|
||||
}
|
||||
|
@@ -6,458 +6,489 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Blocks_Wi
|
||||
|
||||
class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Blocks_Width_Preprocessor */
|
||||
private $preprocessor;
|
||||
/** @var Blocks_Width_Preprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
/** @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;
|
||||
/** @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 Blocks_Width_Preprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new Blocks_Width_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
$this->styles = array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'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 testItCalculatesWidthWithoutPadding(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '50%',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '25%',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '100px',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$styles = $this->styles;
|
||||
$styles['spacing']['padding'] = array(
|
||||
'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 testItCalculatesWidthWithLayoutPadding(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '33%',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '100px',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '20%',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$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'];
|
||||
public function testItCalculatesWidthOfBlockInColumn(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '40%',
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '60%',
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$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
|
||||
}
|
||||
$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'];
|
||||
public function testItAddsMissingColumnWidth(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, array( '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']);
|
||||
}
|
||||
$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'];
|
||||
public function testItCalculatesMissingColumnWidth(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '33.33%',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '200px',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$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
|
||||
}
|
||||
$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);
|
||||
public function testItDoesNotSubtractPaddingForFullWidthBlocks(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'align' => 'full',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
);
|
||||
$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
|
||||
}
|
||||
$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' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
public function testItCalculatesWidthForColumnWithoutDefinition(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '140px',
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '20px',
|
||||
'right' => '20px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$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']);
|
||||
$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' => [],
|
||||
],
|
||||
],
|
||||
]];
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '140px',
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$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']);
|
||||
}
|
||||
$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' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]];
|
||||
public function testItCalculatesWidthForColumnWithBorder(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'border' => array(
|
||||
'width' => '10px',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'width' => '140px',
|
||||
'style' => array(
|
||||
'border' => array(
|
||||
'left' => array(
|
||||
'width' => '5px',
|
||||
),
|
||||
'right' => array(
|
||||
'width' => '5px',
|
||||
),
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '25px',
|
||||
'right' => '15px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'border' => array(
|
||||
'width' => '15px',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '20px',
|
||||
'right' => '20px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$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']);
|
||||
}
|
||||
$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'] );
|
||||
}
|
||||
}
|
||||
|
@@ -6,60 +6,76 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Cleanup_P
|
||||
|
||||
class Cleanup_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
private const PARAGRAPH_BLOCK = [
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerHTML' => 'Paragraph content',
|
||||
];
|
||||
private const PARAGRAPH_BLOCK = array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerHTML' => 'Paragraph content',
|
||||
);
|
||||
|
||||
private const COLUMNS_BLOCK = [
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
]],
|
||||
];
|
||||
private const COLUMNS_BLOCK = array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Cleanup_Preprocessor */
|
||||
private $preprocessor;
|
||||
/** @var Cleanup_Preprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
/** @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;
|
||||
/** @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 Cleanup_Preprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new Cleanup_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
$this->styles = array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'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 testItRemovesUnwantedBlocks(): void {
|
||||
$blocks = array(
|
||||
self::COLUMNS_BLOCK,
|
||||
array(
|
||||
'blockName' => null,
|
||||
'attrs' => array(),
|
||||
'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]);
|
||||
}
|
||||
public function testItPreservesAllRelevantBlocks(): void {
|
||||
$blocks = array(
|
||||
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] );
|
||||
}
|
||||
}
|
||||
|
@@ -6,73 +6,83 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Spacing_P
|
||||
|
||||
class Spacing_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Spacing_Preprocessor */
|
||||
private $preprocessor;
|
||||
/** @var Spacing_Preprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
/** @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;
|
||||
/** @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 Spacing_Preprocessor();
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->preprocessor = new Spacing_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
$this->styles = array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'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/columns',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
public function testItAddsDefaultVerticalSpacing(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/list',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/img',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$result = $this->preprocessor->preprocess($blocks, $this->layout, $this->styles);
|
||||
$this->assertCount(2, $result);
|
||||
$firstColumns = $result[0];
|
||||
$secondColumns = $result[1];
|
||||
$nestedColumn = $firstColumns['innerBlocks'][0];
|
||||
$nestedColumnFirstItem = $nestedColumn['innerBlocks'][0];
|
||||
$nestedColumnSecondItem = $nestedColumn['innerBlocks'][1];
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$this->assertCount( 2, $result );
|
||||
$firstColumns = $result[0];
|
||||
$secondColumns = $result[1];
|
||||
$nestedColumn = $firstColumns['innerBlocks'][0];
|
||||
$nestedColumnFirstItem = $nestedColumn['innerBlocks'][0];
|
||||
$nestedColumnSecondItem = $nestedColumn['innerBlocks'][1];
|
||||
|
||||
// First elements should not have margin-top, but others should.
|
||||
$this->assertArrayNotHasKey('margin-top', $firstColumns['email_attrs']);
|
||||
$this->assertArrayNotHasKey('margin-top', $secondColumns['email_attrs']);
|
||||
$this->assertArrayNotHasKey('margin-top', $nestedColumn['email_attrs']);
|
||||
$this->assertArrayNotHasKey('margin-top', $nestedColumnFirstItem['email_attrs']);
|
||||
$this->assertArrayHasKey('margin-top', $nestedColumnSecondItem['email_attrs']);
|
||||
$this->assertEquals('10px', $nestedColumnSecondItem['email_attrs']['margin-top']);
|
||||
}
|
||||
// First elements should not have margin-top, but others should.
|
||||
$this->assertArrayNotHasKey( 'margin-top', $firstColumns['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $secondColumns['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $nestedColumn['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $nestedColumnFirstItem['email_attrs'] );
|
||||
$this->assertArrayHasKey( 'margin-top', $nestedColumnSecondItem['email_attrs'] );
|
||||
$this->assertEquals( '10px', $nestedColumnSecondItem['email_attrs']['margin-top'] );
|
||||
}
|
||||
}
|
||||
|
@@ -7,270 +7,306 @@ use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Typography_Preprocessor */
|
||||
private $preprocessor;
|
||||
/** @var Typography_Preprocessor */
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
private array $layout;
|
||||
/** @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;
|
||||
/** @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(Settings_Controller::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('get_theme')->willReturn($themeMock);
|
||||
// This slug translate mock expect slugs in format slug-10px and will return 10px
|
||||
$settingsMock->method('translate_slug_to_font_size')->willReturnCallback(function($slug) {
|
||||
return str_replace('slug-', '', $slug);
|
||||
});
|
||||
$this->preprocessor = new Typography_Preprocessor($settingsMock);
|
||||
$this->layout = ['contentSize' => '660px'];
|
||||
$this->styles = ['spacing' => ['padding' => ['left' => '10px', 'right' => '10px', 'top' => '10px', 'bottom' => '10px'], 'blockGap' => '10px']];
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$settingsMock = $this->createMock( Settings_Controller::class );
|
||||
$themeMock = $this->createMock( \WP_Theme_JSON::class );
|
||||
$themeMock->method( 'get_data' )->willReturn(
|
||||
array(
|
||||
'styles' => array(
|
||||
'color' => array(
|
||||
'text' => '#000000',
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSize' => '13px',
|
||||
'fontFamily' => 'Arial',
|
||||
),
|
||||
),
|
||||
'settings' => array(
|
||||
'typography' => array(
|
||||
'fontFamilies' => array(
|
||||
array(
|
||||
'slug' => 'arial-slug',
|
||||
'name' => 'Arial Name',
|
||||
'fontFamily' => 'Arial',
|
||||
),
|
||||
array(
|
||||
'slug' => 'georgia-slug',
|
||||
'name' => 'Georgia Name',
|
||||
'fontFamily' => 'Georgia',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$settingsMock->method( 'get_theme' )->willReturn( $themeMock );
|
||||
// This slug translate mock expect slugs in format slug-10px and will return 10px
|
||||
$settingsMock->method( 'translate_slug_to_font_size' )->willReturnCallback(
|
||||
function ( $slug ) {
|
||||
return str_replace( 'slug-', '', $slug );
|
||||
}
|
||||
);
|
||||
$this->preprocessor = new Typography_Preprocessor( $settingsMock );
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
$this->styles = array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'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 testItCopiesColumnsTypography(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'fontFamily' => 'arial-slug',
|
||||
'style' => array(
|
||||
'color' => array(
|
||||
'text' => '#aa00dd',
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSize' => '12px',
|
||||
'textDecoration' => 'underline',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs = array(
|
||||
'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 testItReplacesFontSizeSlugsWithValues(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'fontSize' => 'slug-20px',
|
||||
'style' => array(),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs = array(
|
||||
'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 testItDoesNotCopyColumnsWidth(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'email_attrs' => array(
|
||||
'width' => '640px',
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$result = $result[0];
|
||||
$this->assertCount( 2, $result['innerBlocks'] );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'width' => '640px',
|
||||
'color' => '#000000',
|
||||
'font-size' => '13px',
|
||||
),
|
||||
$result['email_attrs']
|
||||
);
|
||||
$defaultFontStyles = array(
|
||||
'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']);
|
||||
}
|
||||
public function testItOverridesColumnsTypography(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
'fontFamily' => 'arial-slug',
|
||||
'style' => array(
|
||||
'color' => array(
|
||||
'text' => '#aa00dd',
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSize' => '12px',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'fontFamily' => 'georgia-slug',
|
||||
'style' => array(
|
||||
'color' => array(
|
||||
'text' => '#cc22aa',
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSize' => '18px',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(
|
||||
'fontFamily' => 'georgia-slug',
|
||||
'style' => array(
|
||||
'color' => array(
|
||||
'text' => '#cc22aa',
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSize' => '18px',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs1 = array(
|
||||
'color' => '#aa00dd',
|
||||
'font-size' => '12px',
|
||||
);
|
||||
$expectedEmailAttrs2 = array(
|
||||
'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(
|
||||
array(
|
||||
'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'] );
|
||||
}
|
||||
}
|
||||
|
@@ -11,42 +11,42 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Typograph
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Process_Manager;
|
||||
|
||||
class Process_Manager_Test extends \MailPoetUnitTest {
|
||||
public function testItCallsPreprocessorsProperly(): void {
|
||||
$layout = [
|
||||
'contentSize' => '600px',
|
||||
];
|
||||
$styles = [
|
||||
'spacing' => [
|
||||
'blockGap' => '0px',
|
||||
'padding' => [
|
||||
'bottom' => '0px',
|
||||
'left' => '0px',
|
||||
'right' => '0px',
|
||||
'top' => '0px',
|
||||
],
|
||||
],
|
||||
];
|
||||
public function testItCallsPreprocessorsProperly(): void {
|
||||
$layout = array(
|
||||
'contentSize' => '600px',
|
||||
);
|
||||
$styles = array(
|
||||
'spacing' => array(
|
||||
'blockGap' => '0px',
|
||||
'padding' => array(
|
||||
'bottom' => '0px',
|
||||
'left' => '0px',
|
||||
'right' => '0px',
|
||||
'top' => '0px',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$cleanup = $this->createMock(Cleanup_Preprocessor::class);
|
||||
$cleanup->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
$cleanup = $this->createMock( Cleanup_Preprocessor::class );
|
||||
$cleanup->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
|
||||
$blocksWidth = $this->createMock(Blocks_Width_Preprocessor::class);
|
||||
$blocksWidth->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
$blocksWidth = $this->createMock( Blocks_Width_Preprocessor::class );
|
||||
$blocksWidth->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
|
||||
$typography = $this->createMock(Typography_Preprocessor::class);
|
||||
$typography->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
$typography = $this->createMock( Typography_Preprocessor::class );
|
||||
$typography->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
|
||||
$spacing = $this->createMock(Spacing_Preprocessor::class);
|
||||
$spacing->expects($this->once())->method('preprocess')->willReturn([]);
|
||||
$spacing = $this->createMock( Spacing_Preprocessor::class );
|
||||
$spacing->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
|
||||
$highlighting = $this->createMock(Highlighting_Postprocessor::class);
|
||||
$highlighting->expects($this->once())->method('postprocess')->willReturn('');
|
||||
$highlighting = $this->createMock( Highlighting_Postprocessor::class );
|
||||
$highlighting->expects( $this->once() )->method( 'postprocess' )->willReturn( '' );
|
||||
|
||||
$variables = $this->createMock(Variables_Postprocessor::class);
|
||||
$variables->expects($this->once())->method('postprocess')->willReturn('');
|
||||
$variables = $this->createMock( Variables_Postprocessor::class );
|
||||
$variables->expects( $this->once() )->method( 'postprocess' )->willReturn( '' );
|
||||
|
||||
$processManager = new Process_Manager($cleanup, $blocksWidth, $typography, $spacing, $highlighting, $variables);
|
||||
$this->assertEquals([], $processManager->preprocess([], $layout, $styles));
|
||||
$this->assertEmpty($processManager->postprocess(''));
|
||||
}
|
||||
$processManager = new Process_Manager( $cleanup, $blocksWidth, $typography, $spacing, $highlighting, $variables );
|
||||
$this->assertEquals( array(), $processManager->preprocess( array(), $layout, $styles ) );
|
||||
$this->assertEmpty( $processManager->postprocess( '' ) );
|
||||
}
|
||||
}
|
||||
|
@@ -3,28 +3,32 @@
|
||||
namespace MailPoet\EmailEditor\Engine;
|
||||
|
||||
class Settings_Controller_Test 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(Theme_Controller::class);
|
||||
$themeController->method('get_theme')->willReturn($themeJsonMock);
|
||||
$themeController->method('get_layout_settings')->willReturn([
|
||||
"contentSize" => "660px",
|
||||
"wideSize" => null,
|
||||
]);
|
||||
$settingsController = new Settings_Controller($themeController);
|
||||
$layoutWidth = $settingsController->get_layout_width_without_padding();
|
||||
// default width is 660px and if we subtract padding from left and right we must get the correct value
|
||||
$expectedWidth = 660 - 10 * 2;
|
||||
$this->assertEquals($expectedWidth . 'px', $layoutWidth);
|
||||
}
|
||||
public function testItGetsCorrectLayoutWidthWithoutPadding(): void {
|
||||
$themeJsonMock = $this->createMock( \WP_Theme_JSON::class );
|
||||
$themeJsonMock->method( 'get_data' )->willReturn(
|
||||
array(
|
||||
'styles' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$themeController = $this->createMock( Theme_Controller::class );
|
||||
$themeController->method( 'get_theme' )->willReturn( $themeJsonMock );
|
||||
$themeController->method( 'get_layout_settings' )->willReturn(
|
||||
array(
|
||||
'contentSize' => '660px',
|
||||
'wideSize' => null,
|
||||
)
|
||||
);
|
||||
$settingsController = new Settings_Controller( $themeController );
|
||||
$layoutWidth = $settingsController->get_layout_width_without_padding();
|
||||
// default width is 660px and if we subtract padding from left and right we must get the correct value
|
||||
$expectedWidth = 660 - 10 * 2;
|
||||
$this->assertEquals( $expectedWidth . 'px', $layoutWidth );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user