Migrate tests/unit/Engine folder to WordPress Coding Standard
[MAILPOET-6240]
This commit is contained in:
@@ -1,18 +1,37 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Postprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Highlighting_Postprocessor;
|
||||
|
||||
/**
|
||||
* Unit test class for Highlighting_Postprocessor.
|
||||
*/
|
||||
class Highlighting_Postprocessor_Test extends \MailPoetUnitTest {
|
||||
/** @var Highlighting_Postprocessor */
|
||||
/**
|
||||
* Instance of Highlighting_Postprocessor.
|
||||
*
|
||||
* @var Highlighting_Postprocessor
|
||||
*/
|
||||
private $postprocessor;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test.
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$this->postprocessor = new Highlighting_Postprocessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it replaces HTML elements.
|
||||
*/
|
||||
public function testItReplacesHtmlElements(): void {
|
||||
$html = '
|
||||
<mark>Some text</mark>
|
||||
|
@@ -1,30 +1,54 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Postprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Variables_Postprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Theme_Controller;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
* Unit test for Variables_Postprocessor
|
||||
*/
|
||||
class Variables_Postprocessor_Test extends \MailPoetUnitTest {
|
||||
/**
|
||||
* Instance of Variables_Postprocessor
|
||||
*
|
||||
* @var Variables_Postprocessor
|
||||
*/
|
||||
private Variables_Postprocessor $postprocessor;
|
||||
|
||||
/** @var Theme_Controller & MockObject */
|
||||
private $themeControllerMock;
|
||||
/**
|
||||
* Theme_Controller mock
|
||||
*
|
||||
* @var Theme_Controller & MockObject
|
||||
*/
|
||||
private $theme_controller_mock;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$this->themeControllerMock = $this->createMock( Theme_Controller::class );
|
||||
$this->postprocessor = new Variables_Postprocessor( $this->themeControllerMock );
|
||||
$this->theme_controller_mock = $this->createMock( Theme_Controller::class );
|
||||
$this->postprocessor = new Variables_Postprocessor( $this->theme_controller_mock );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it replaces variables in the content
|
||||
*/
|
||||
public function testItReplacesVariablesInStyleAttributes(): void {
|
||||
$variablesMap = array(
|
||||
$variables_map = 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 );
|
||||
$this->theme_controller_mock->method( 'get_variables_values_map' )->willReturn( $variables_map );
|
||||
$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 );
|
||||
|
@@ -1,21 +1,45 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Blocks_Width_Preprocessor;
|
||||
|
||||
/**
|
||||
* Unit test for Blocks_Width_Preprocessor
|
||||
*/
|
||||
class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Blocks_Width_Preprocessor */
|
||||
/**
|
||||
* Instance of Blocks_Width_Preprocessor
|
||||
*
|
||||
* @var Blocks_Width_Preprocessor
|
||||
*/
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
/**
|
||||
* Layout configuration
|
||||
*
|
||||
* @var array{contentSize: string}
|
||||
*/
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
/**
|
||||
* Styles configuration
|
||||
*
|
||||
* @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles
|
||||
*/
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$this->preprocessor = new Blocks_Width_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
@@ -32,6 +56,9 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width without padding
|
||||
*/
|
||||
public function testItCalculatesWidthWithoutPadding(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -78,6 +105,9 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$this->assertEquals( '100px', $result['innerBlocks'][2]['email_attrs']['width'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with layout padding
|
||||
*/
|
||||
public function testItCalculatesWidthWithLayoutPadding(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -116,8 +146,11 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$this->assertEquals( '128px', $result['innerBlocks'][2]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.2
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width of block in column
|
||||
*/
|
||||
public function testItCalculatesWidthOfBlockInColumn(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
@@ -167,18 +200,21 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$inner_blocks = $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, $inner_blocks );
|
||||
$this->assertEquals( '256px', $inner_blocks[0]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.4
|
||||
$this->assertEquals( '236px', $inner_blocks[0]['innerBlocks'][0]['email_attrs']['width'] ); // 256 - 10 - 10
|
||||
$this->assertEquals( '384px', $inner_blocks[1]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.6
|
||||
$this->assertEquals( '344px', $inner_blocks[1]['innerBlocks'][0]['email_attrs']['width'] ); // 384 - 25 - 15
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with padding
|
||||
*/
|
||||
public function testItAddsMissingColumnWidth(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
@@ -219,20 +255,23 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, array( 'contentSize' => '620px' ), $this->styles );
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
$result = $this->preprocessor->preprocess( $blocks, array( 'contentSize' => '620px' ), $this->styles );
|
||||
$inner_blocks = $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, $inner_blocks );
|
||||
$this->assertEquals( '200px', $inner_blocks[0]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals( '200px', $inner_blocks[0]['innerBlocks'][0]['email_attrs']['width'] );
|
||||
$this->assertEquals( '200px', $inner_blocks[1]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals( '200px', $inner_blocks[1]['innerBlocks'][0]['email_attrs']['width'] );
|
||||
$this->assertEquals( '200px', $inner_blocks[2]['email_attrs']['width'] ); // (660 - 10 - 10) * 0.33
|
||||
$this->assertEquals( '200px', $inner_blocks[2]['innerBlocks'][0]['email_attrs']['width'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with padding
|
||||
*/
|
||||
public function testItCalculatesMissingColumnWidth(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
@@ -268,15 +307,18 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$innerBlocks = $result[0]['innerBlocks'];
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$inner_blocks = $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, $inner_blocks );
|
||||
$this->assertEquals( '200px', $inner_blocks[0]['email_attrs']['width'] ); // (620 - 10 - 10) * 0.3333
|
||||
$this->assertEquals( '200px', $inner_blocks[1]['email_attrs']['width'] ); // already defined.
|
||||
$this->assertEquals( '200px', $inner_blocks[2]['email_attrs']['width'] ); // 600 -200 - 200
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with padding
|
||||
*/
|
||||
public function testItDoesNotSubtractPaddingForFullWidthBlocks(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -295,10 +337,13 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$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( '660px', $result[0]['email_attrs']['width'] ); // full width.
|
||||
$this->assertEquals( '640px', $result[1]['email_attrs']['width'] ); // 660 - 10 - 10
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with padding
|
||||
*/
|
||||
public function testItCalculatesWidthForColumnWithoutDefinition(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -402,6 +447,9 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$this->assertEquals( '500px', $result[0]['innerBlocks'][1]['email_attrs']['width'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it calculates width for column with border
|
||||
*/
|
||||
public function testItCalculatesWidthForColumnWithBorder(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -486,9 +534,9 @@ class Blocks_Width_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$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'] );
|
||||
$image_block = $result[0]['innerBlocks'][1]['innerBlocks'][0];
|
||||
$this->assertEquals( '185px', $image_block['email_attrs']['width'] );
|
||||
$image_block = $result[0]['innerBlocks'][2]['innerBlocks'][0];
|
||||
$this->assertEquals( '215px', $image_block['email_attrs']['width'] );
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,18 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Cleanup_Preprocessor;
|
||||
|
||||
/**
|
||||
* Unit test for Cleanup_Preprocessor
|
||||
*/
|
||||
class Cleanup_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
private const PARAGRAPH_BLOCK = array(
|
||||
@@ -24,16 +33,31 @@ class Cleanup_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Cleanup_Preprocessor */
|
||||
/**
|
||||
* Instance of Cleanup_Preprocessor
|
||||
*
|
||||
* @var Cleanup_Preprocessor
|
||||
*/
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
/**
|
||||
* Layout settings
|
||||
*
|
||||
* @var array{contentSize: string}
|
||||
*/
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
/**
|
||||
* Styles settings
|
||||
*
|
||||
* @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles
|
||||
*/
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$this->preprocessor = new Cleanup_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
@@ -50,6 +74,9 @@ class Cleanup_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it removes unwanted blocks
|
||||
*/
|
||||
public function testItRemovesUnwantedBlocks(): void {
|
||||
$blocks = array(
|
||||
self::COLUMNS_BLOCK,
|
||||
@@ -66,6 +93,9 @@ class Cleanup_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
$this->assertEquals( self::PARAGRAPH_BLOCK, $result[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it preserves all relevant blocks
|
||||
*/
|
||||
public function testItPreservesAllRelevantBlocks(): void {
|
||||
$blocks = array(
|
||||
self::COLUMNS_BLOCK,
|
||||
|
@@ -1,21 +1,45 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Spacing_Preprocessor;
|
||||
|
||||
/**
|
||||
* Unit test for Spacing_Preprocessor
|
||||
*/
|
||||
class Spacing_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Spacing_Preprocessor */
|
||||
/**
|
||||
* Spacing_Preprocessor instance
|
||||
*
|
||||
* @var Spacing_Preprocessor
|
||||
*/
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
/**
|
||||
* Layout settings
|
||||
*
|
||||
* @var array{contentSize: string}
|
||||
*/
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
/**
|
||||
* Styles settings
|
||||
*
|
||||
* @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles
|
||||
*/
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$this->preprocessor = new Spacing_Preprocessor();
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
@@ -32,6 +56,9 @@ class Spacing_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it adds default horizontal spacing
|
||||
*/
|
||||
public function testItAddsDefaultVerticalSpacing(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -71,18 +98,18 @@ class Spacing_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
$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_columns = $result[0];
|
||||
$second_columns = $result[1];
|
||||
$nested_column = $first_columns['innerBlocks'][0];
|
||||
$nested_column_first_item = $nested_column['innerBlocks'][0];
|
||||
$nested_column_second_item = $nested_column['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'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $first_columns['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $second_columns['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $nested_column['email_attrs'] );
|
||||
$this->assertArrayNotHasKey( 'margin-top', $nested_column_first_item['email_attrs'] );
|
||||
$this->assertArrayHasKey( 'margin-top', $nested_column_second_item['email_attrs'] );
|
||||
$this->assertEquals( '10px', $nested_column_second_item['email_attrs']['margin-top'] );
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,50 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Typography_Preprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
/**
|
||||
* Unit test for Typography_Preprocessor
|
||||
*/
|
||||
class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
|
||||
/** @var Typography_Preprocessor */
|
||||
/**
|
||||
* Instance of Typography_Preprocessor
|
||||
*
|
||||
* @var Typography_Preprocessor
|
||||
*/
|
||||
private $preprocessor;
|
||||
|
||||
/** @var array{contentSize: string} */
|
||||
/**
|
||||
* Layout settings
|
||||
*
|
||||
* @var array{contentSize: string}
|
||||
*/
|
||||
private array $layout;
|
||||
|
||||
/** @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles */
|
||||
/**
|
||||
* Styles settings
|
||||
*
|
||||
* @var array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles
|
||||
*/
|
||||
private array $styles;
|
||||
|
||||
public function _before() {
|
||||
/**
|
||||
* Set up the test
|
||||
*/
|
||||
public function _before() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
||||
parent::_before();
|
||||
$settingsMock = $this->createMock( Settings_Controller::class );
|
||||
$themeMock = $this->createMock( \WP_Theme_JSON::class );
|
||||
$themeMock->method( 'get_data' )->willReturn(
|
||||
$settings_mock = $this->createMock( Settings_Controller::class );
|
||||
$theme_mock = $this->createMock( \WP_Theme_JSON::class );
|
||||
$theme_mock->method( 'get_data' )->willReturn(
|
||||
array(
|
||||
'styles' => array(
|
||||
'color' => array(
|
||||
@@ -49,14 +73,14 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
)
|
||||
);
|
||||
$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(
|
||||
$settings_mock->method( 'get_theme' )->willReturn( $theme_mock );
|
||||
// This slug translate mock expect slugs in format slug-10px and will return 10px.
|
||||
$settings_mock->method( 'translate_slug_to_font_size' )->willReturnCallback(
|
||||
function ( $slug ) {
|
||||
return str_replace( 'slug-', '', $slug );
|
||||
}
|
||||
);
|
||||
$this->preprocessor = new Typography_Preprocessor( $settingsMock );
|
||||
$this->preprocessor = new Typography_Preprocessor( $settings_mock );
|
||||
$this->layout = array( 'contentSize' => '660px' );
|
||||
$this->styles = array(
|
||||
'spacing' => array(
|
||||
@@ -71,8 +95,11 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it copies columns typography
|
||||
*/
|
||||
public function testItCopiesColumnsTypography(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
@@ -105,22 +132,25 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs = array(
|
||||
$expected_email_attrs = array(
|
||||
'color' => '#aa00dd',
|
||||
'font-size' => '12px',
|
||||
'text-decoration' => 'underline',
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$result = $result[0];
|
||||
$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'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][1]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it replaces font family slugs with values
|
||||
*/
|
||||
public function testItReplacesFontSizeSlugsWithValues(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
@@ -145,19 +175,22 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs = array(
|
||||
$expected_email_attrs = array(
|
||||
'color' => '#000000',
|
||||
'font-size' => '20px',
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$result = $result[0];
|
||||
$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'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][1]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it does not copy columns width
|
||||
*/
|
||||
public function testItDoesNotCopyColumnsWidth(): void {
|
||||
$blocks = array(
|
||||
array(
|
||||
@@ -195,17 +228,20 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
$result['email_attrs']
|
||||
);
|
||||
$defaultFontStyles = array(
|
||||
$default_font_styles = 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'] );
|
||||
$this->assertEquals( $default_font_styles, $result['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $default_font_styles, $result['innerBlocks'][1]['email_attrs'] );
|
||||
$this->assertEquals( $default_font_styles, $result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it overrides columns typography
|
||||
*/
|
||||
public function testItOverridesColumnsTypography(): void {
|
||||
$blocks = array(
|
||||
$blocks = array(
|
||||
array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(
|
||||
@@ -281,23 +317,23 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
),
|
||||
);
|
||||
$expectedEmailAttrs1 = array(
|
||||
$expected_email_attrs1 = array(
|
||||
'color' => '#aa00dd',
|
||||
'font-size' => '12px',
|
||||
);
|
||||
$expectedEmailAttrs2 = array(
|
||||
$expected_email_attrs2 = array(
|
||||
'color' => '#cc22aa',
|
||||
'font-size' => '18px',
|
||||
);
|
||||
$result = $this->preprocessor->preprocess( $blocks, $this->layout, $this->styles );
|
||||
$child1 = $result[0];
|
||||
$child2 = $result[1];
|
||||
$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->assertEquals( $expected_email_attrs1, $child1['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs2, $child1['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs2, $child1['innerBlocks'][0]['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs1, $child1['innerBlocks'][1]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs1, $child1['innerBlocks'][1]['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertCount( 1, $child2['innerBlocks'] );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@@ -306,7 +342,7 @@ class Typography_Preprocessor_Test extends \MailPoetUnitTest {
|
||||
),
|
||||
$child2['email_attrs']
|
||||
);
|
||||
$this->assertEquals( $expectedEmailAttrs2, $child2['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expectedEmailAttrs2, $child2['innerBlocks'][0]['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs2, $child2['innerBlocks'][0]['email_attrs'] );
|
||||
$this->assertEquals( $expected_email_attrs2, $child2['innerBlocks'][0]['innerBlocks'][0]['email_attrs'] );
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,11 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Renderer;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\Highlighting_Postprocessor;
|
||||
@@ -10,7 +16,13 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Spacing_P
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Typography_Preprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Process_Manager;
|
||||
|
||||
/**
|
||||
* Unit test class for Process_Manager.
|
||||
*/
|
||||
class Process_Manager_Test extends \MailPoetUnitTest {
|
||||
/**
|
||||
* Test it calls preprocessors properly.
|
||||
*/
|
||||
public function testItCallsPreprocessorsProperly(): void {
|
||||
$layout = array(
|
||||
'contentSize' => '600px',
|
||||
@@ -30,8 +42,8 @@ class Process_Manager_Test extends \MailPoetUnitTest {
|
||||
$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( array() );
|
||||
$blocks_width = $this->createMock( Blocks_Width_Preprocessor::class );
|
||||
$blocks_width->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
|
||||
$typography = $this->createMock( Typography_Preprocessor::class );
|
||||
$typography->expects( $this->once() )->method( 'preprocess' )->willReturn( array() );
|
||||
@@ -45,8 +57,8 @@ class Process_Manager_Test extends \MailPoetUnitTest {
|
||||
$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( array(), $processManager->preprocess( array(), $layout, $styles ) );
|
||||
$this->assertEmpty( $processManager->postprocess( '' ) );
|
||||
$process_nanager = new Process_Manager( $cleanup, $blocks_width, $typography, $spacing, $highlighting, $variables );
|
||||
$this->assertEquals( array(), $process_nanager->preprocess( array(), $layout, $styles ) );
|
||||
$this->assertEmpty( $process_nanager->postprocess( '' ) );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user