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:
@@ -3,6 +3,7 @@
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
*
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
@@ -15,37 +16,37 @@
|
||||
* @method void pause()
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class IntegrationTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\IntegrationTesterActions;
|
||||
*/
|
||||
class IntegrationTester extends \Codeception\Actor {
|
||||
|
||||
private $wpTermIds = [];
|
||||
use _generated\IntegrationTesterActions;
|
||||
|
||||
private $createdCommentIds = [];
|
||||
private $wpTermIds = array();
|
||||
|
||||
private $posts = [];
|
||||
private $createdCommentIds = array();
|
||||
|
||||
public function createPost(array $params): \WP_Post {
|
||||
$postId = wp_insert_post($params);
|
||||
if ($postId instanceof WP_Error) {
|
||||
throw new \Exception('Failed to create post');
|
||||
}
|
||||
$post = get_post($postId);
|
||||
if (!$post instanceof WP_Post) {
|
||||
throw new \Exception('Failed to fetch the post');
|
||||
}
|
||||
$this->posts[] = $post;
|
||||
return $post;
|
||||
}
|
||||
private $posts = array();
|
||||
|
||||
public function cleanup() {
|
||||
$this->deletePosts();
|
||||
}
|
||||
public function createPost( array $params ): \WP_Post {
|
||||
$postId = wp_insert_post( $params );
|
||||
if ( $postId instanceof WP_Error ) {
|
||||
throw new \Exception( 'Failed to create post' );
|
||||
}
|
||||
$post = get_post( $postId );
|
||||
if ( ! $post instanceof WP_Post ) {
|
||||
throw new \Exception( 'Failed to fetch the post' );
|
||||
}
|
||||
$this->posts[] = $post;
|
||||
return $post;
|
||||
}
|
||||
|
||||
private function deletePosts() {
|
||||
foreach ($this->posts as $post) {
|
||||
wp_delete_post($post->ID, true);
|
||||
}
|
||||
}
|
||||
public function cleanup() {
|
||||
$this->deletePosts();
|
||||
}
|
||||
|
||||
private function deletePosts() {
|
||||
foreach ( $this->posts as $post ) {
|
||||
wp_delete_post( $post->ID, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
*
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
@@ -16,12 +17,12 @@ use _generated\UnitTesterActions;
|
||||
* @method void pause()
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use UnitTesterActions;
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor {
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
use UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
|
@@ -3,34 +3,34 @@
|
||||
namespace MailPoet\EmailEditor\Engine;
|
||||
|
||||
class Email_Editor_Test extends \MailPoetTest {
|
||||
/** @var Email_Editor */
|
||||
private $emailEditor;
|
||||
/** @var Email_Editor */
|
||||
private $emailEditor;
|
||||
|
||||
/** @var callable */
|
||||
private $postRegisterCallback;
|
||||
/** @var callable */
|
||||
private $postRegisterCallback;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->emailEditor = $this->diContainer->get(Email_Editor::class);
|
||||
$this->postRegisterCallback = function ($postTypes) {
|
||||
$postTypes[] = [
|
||||
'name' => 'custom_email_type',
|
||||
'args' => [],
|
||||
'meta' => [],
|
||||
];
|
||||
return $postTypes;
|
||||
};
|
||||
add_filter('mailpoet_email_editor_post_types', $this->postRegisterCallback);
|
||||
$this->emailEditor->initialize();
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->emailEditor = $this->diContainer->get( Email_Editor::class );
|
||||
$this->postRegisterCallback = function ( $postTypes ) {
|
||||
$postTypes[] = array(
|
||||
'name' => 'custom_email_type',
|
||||
'args' => array(),
|
||||
'meta' => array(),
|
||||
);
|
||||
return $postTypes;
|
||||
};
|
||||
add_filter( 'mailpoet_email_editor_post_types', $this->postRegisterCallback );
|
||||
$this->emailEditor->initialize();
|
||||
}
|
||||
|
||||
public function testItRegistersCustomPostTypeAddedViaHook() {
|
||||
$postTypes = get_post_types();
|
||||
$this->assertArrayHasKey('custom_email_type', $postTypes);
|
||||
}
|
||||
public function testItRegistersCustomPostTypeAddedViaHook() {
|
||||
$postTypes = get_post_types();
|
||||
$this->assertArrayHasKey( 'custom_email_type', $postTypes );
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
remove_filter('mailpoet_email_editor_post_types', $this->postRegisterCallback);
|
||||
}
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
remove_filter( 'mailpoet_email_editor_post_types', $this->postRegisterCallback );
|
||||
}
|
||||
}
|
||||
|
@@ -8,30 +8,30 @@ require_once __DIR__ . '/Dummy_Block_Renderer.php';
|
||||
|
||||
class Blocks_Registry_Test extends \MailPoetTest {
|
||||
|
||||
/** @var Blocks_Registry */
|
||||
private $registry;
|
||||
/** @var Blocks_Registry */
|
||||
private $registry;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->registry = $this->diContainer->get(Blocks_Registry::class);
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->registry = $this->diContainer->get( Blocks_Registry::class );
|
||||
}
|
||||
|
||||
public function testItReturnsNullForUnknownRenderer() {
|
||||
$storedRenderer = $this->registry->get_block_renderer('test');
|
||||
verify($storedRenderer)->null();
|
||||
}
|
||||
public function testItReturnsNullForUnknownRenderer() {
|
||||
$storedRenderer = $this->registry->get_block_renderer( 'test' );
|
||||
verify( $storedRenderer )->null();
|
||||
}
|
||||
|
||||
public function testItStoresAddedRenderer() {
|
||||
$renderer = new Text();
|
||||
$this->registry->add_block_renderer('test', $renderer);
|
||||
$storedRenderer = $this->registry->get_block_renderer('test');
|
||||
verify($storedRenderer)->equals($renderer);
|
||||
}
|
||||
public function testItStoresAddedRenderer() {
|
||||
$renderer = new Text();
|
||||
$this->registry->add_block_renderer( 'test', $renderer );
|
||||
$storedRenderer = $this->registry->get_block_renderer( 'test' );
|
||||
verify( $storedRenderer )->equals( $renderer );
|
||||
}
|
||||
|
||||
public function testItReportsWhichRenderersAreRegistered() {
|
||||
$renderer = new Text();
|
||||
$this->registry->add_block_renderer('test', $renderer);
|
||||
verify($this->registry->has_block_renderer('test'))->true();
|
||||
verify($this->registry->has_block_renderer('unknown'))->false();
|
||||
}
|
||||
public function testItReportsWhichRenderersAreRegistered() {
|
||||
$renderer = new Text();
|
||||
$this->registry->add_block_renderer( 'test', $renderer );
|
||||
verify( $this->registry->has_block_renderer( 'test' ) )->true();
|
||||
verify( $this->registry->has_block_renderer( 'unknown' ) )->false();
|
||||
}
|
||||
}
|
||||
|
@@ -8,46 +8,48 @@ use MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController;
|
||||
require_once __DIR__ . '/Dummy_Block_Renderer.php';
|
||||
|
||||
class Content_Renderer_Test extends \MailPoetTest {
|
||||
private Content_Renderer $renderer;
|
||||
private Content_Renderer $renderer;
|
||||
|
||||
private \WP_Post $emailPost;
|
||||
private \WP_Post $emailPost;
|
||||
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->diContainer->get(BlockTypesController::class)->initialize();
|
||||
$this->renderer = $this->diContainer->get(Content_Renderer::class);
|
||||
$this->emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
|
||||
]);
|
||||
}
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->diContainer->get( BlockTypesController::class )->initialize();
|
||||
$this->renderer = $this->diContainer->get( Content_Renderer::class );
|
||||
$this->emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testItRendersContent(): void {
|
||||
$template = new \WP_Block_Template();
|
||||
$template->id = 'template-id';
|
||||
$template->content = '<!-- wp:core/post-content /-->';
|
||||
$content = $this->renderer->render(
|
||||
$this->emailPost,
|
||||
$template
|
||||
);
|
||||
verify($content)->stringContainsString('Hello!');
|
||||
}
|
||||
public function testItRendersContent(): void {
|
||||
$template = new \WP_Block_Template();
|
||||
$template->id = 'template-id';
|
||||
$template->content = '<!-- wp:core/post-content /-->';
|
||||
$content = $this->renderer->render(
|
||||
$this->emailPost,
|
||||
$template
|
||||
);
|
||||
verify( $content )->stringContainsString( 'Hello!' );
|
||||
}
|
||||
|
||||
public function testItInlinesContentStyles(): void {
|
||||
$template = new \WP_Block_Template();
|
||||
$template->id = 'template-id';
|
||||
$template->content = '<!-- wp:core/post-content /-->';
|
||||
$rendered = $this->renderer->render($this->emailPost, $template);
|
||||
$paragraphStyles = $this->getStylesValueForTag($rendered, 'p');
|
||||
verify($paragraphStyles)->stringContainsString('margin: 0');
|
||||
verify($paragraphStyles)->stringContainsString('display: block');
|
||||
}
|
||||
public function testItInlinesContentStyles(): void {
|
||||
$template = new \WP_Block_Template();
|
||||
$template->id = 'template-id';
|
||||
$template->content = '<!-- wp:core/post-content /-->';
|
||||
$rendered = $this->renderer->render( $this->emailPost, $template );
|
||||
$paragraphStyles = $this->getStylesValueForTag( $rendered, 'p' );
|
||||
verify( $paragraphStyles )->stringContainsString( 'margin: 0' );
|
||||
verify( $paragraphStyles )->stringContainsString( 'display: block' );
|
||||
}
|
||||
|
||||
private function getStylesValueForTag($html, $tag): ?string {
|
||||
$html = new \WP_HTML_Tag_Processor($html);
|
||||
if ($html->next_tag($tag)) {
|
||||
return $html->get_attribute('style');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function getStylesValueForTag( $html, $tag ): ?string {
|
||||
$html = new \WP_HTML_Tag_Processor( $html );
|
||||
if ( $html->next_tag( $tag ) ) {
|
||||
return $html->get_attribute( 'style' );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ namespace MailPoet\EmailEditor\Engine\Renderer\ContentRenderer;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Dummy_Block_Renderer implements Block_Renderer {
|
||||
public function render(string $block_content, array $parsed_block, Settings_Controller $settings_controller): string {
|
||||
return $parsed_block['innerHtml'];
|
||||
}
|
||||
public function render( string $block_content, array $parsed_block, Settings_Controller $settings_controller ): string {
|
||||
return $parsed_block['innerHtml'];
|
||||
}
|
||||
}
|
||||
|
@@ -9,227 +9,226 @@ require_once __DIR__ . '/../Dummy_Block_Renderer.php';
|
||||
|
||||
class Flex_Layout_Renderer_Test extends \MailPoetTest {
|
||||
|
||||
/** @var Flex_Layout_Renderer */
|
||||
private $renderer;
|
||||
/** @var Flex_Layout_Renderer */
|
||||
private $renderer;
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
$this->renderer = new Flex_Layout_Renderer();
|
||||
register_block_type('dummy/block', []);
|
||||
add_filter('render_block', [$this, 'renderDummyBlock'], 10, 2);
|
||||
}
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
$this->renderer = new Flex_Layout_Renderer();
|
||||
register_block_type( 'dummy/block', array() );
|
||||
add_filter( 'render_block', array( $this, 'renderDummyBlock' ), 10, 2 );
|
||||
}
|
||||
|
||||
public function testItRendersInnerBlocks(): void {
|
||||
$parsedBlock = [
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
],
|
||||
],
|
||||
'email_attrs' => [],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
verify($output)->stringContainsString('Dummy 1');
|
||||
verify($output)->stringContainsString('Dummy 2');
|
||||
}
|
||||
public function testItRendersInnerBlocks(): void {
|
||||
$parsedBlock = array(
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
),
|
||||
),
|
||||
'email_attrs' => array(),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'Dummy 1' );
|
||||
verify( $output )->stringContainsString( 'Dummy 2' );
|
||||
}
|
||||
|
||||
public function testItHandlesJustification(): void {
|
||||
$parsedBlock = [
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
],
|
||||
],
|
||||
'email_attrs' => [],
|
||||
];
|
||||
// Default justification is left
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
verify($output)->stringContainsString('text-align: left');
|
||||
verify($output)->stringContainsString('align="left"');
|
||||
// Right justification
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = 'right';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
verify($output)->stringContainsString('text-align: right');
|
||||
verify($output)->stringContainsString('align="right"');
|
||||
// Center justification
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = 'center';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
verify($output)->stringContainsString('text-align: center');
|
||||
verify($output)->stringContainsString('align="center"');
|
||||
}
|
||||
public function testItHandlesJustification(): void {
|
||||
$parsedBlock = array(
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
),
|
||||
),
|
||||
'email_attrs' => array(),
|
||||
);
|
||||
// Default justification is left
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'text-align: left' );
|
||||
verify( $output )->stringContainsString( 'align="left"' );
|
||||
// Right justification
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = 'right';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'text-align: right' );
|
||||
verify( $output )->stringContainsString( 'align="right"' );
|
||||
// Center justification
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = 'center';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'text-align: center' );
|
||||
verify( $output )->stringContainsString( 'align="center"' );
|
||||
}
|
||||
|
||||
public function testItEscapesAttributes(): void {
|
||||
$parsedBlock = [
|
||||
'innerBlocks' => [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
],
|
||||
],
|
||||
'email_attrs' => [],
|
||||
];
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = '"> <script>alert("XSS")</script><div style="text-align: right';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
verify($output)->stringNotContainsString('<script>alert("XSS")</script>');
|
||||
}
|
||||
public function testItEscapesAttributes(): void {
|
||||
$parsedBlock = array(
|
||||
'innerBlocks' => array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
),
|
||||
),
|
||||
'email_attrs' => array(),
|
||||
);
|
||||
$parsedBlock['attrs']['layout']['justifyContent'] = '"> <script>alert("XSS")</script><div style="text-align: right';
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
verify( $output )->stringNotContainsString( '<script>alert("XSS")</script>' );
|
||||
}
|
||||
|
||||
public function testInComputesProperWidthsForReasonableSettings(): void {
|
||||
$parsedBlock = [
|
||||
'innerBlocks' => [],
|
||||
'email_attrs' => [
|
||||
'width' => '640px',
|
||||
],
|
||||
];
|
||||
public function testInComputesProperWidthsForReasonableSettings(): void {
|
||||
$parsedBlock = array(
|
||||
'innerBlocks' => array(),
|
||||
'email_attrs' => array(
|
||||
'width' => '640px',
|
||||
),
|
||||
);
|
||||
|
||||
// 50% and 25%
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '50'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => ['width' => '25'],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:312px;');
|
||||
verify($flexItems[1])->stringContainsString('width:148px;');
|
||||
// 50% and 25%
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '50' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array( 'width' => '25' ),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:312px;' );
|
||||
verify( $flexItems[1] )->stringContainsString( 'width:148px;' );
|
||||
|
||||
// 25% and 25% and auto
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '25'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => ['width' => '25'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 3',
|
||||
'attrs' => [],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:148px;');
|
||||
verify($flexItems[1])->stringContainsString('width:148px;');
|
||||
verify($flexItems[2])->stringNotContainsString('width:');
|
||||
// 25% and 25% and auto
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '25' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array( 'width' => '25' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 3',
|
||||
'attrs' => array(),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:148px;' );
|
||||
verify( $flexItems[1] )->stringContainsString( 'width:148px;' );
|
||||
verify( $flexItems[2] )->stringNotContainsString( 'width:' );
|
||||
|
||||
// 50% and 50%
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '50'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => ['width' => '50'],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:312px;');
|
||||
verify($flexItems[1])->stringContainsString('width:312px;');
|
||||
}
|
||||
// 50% and 50%
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '50' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array( 'width' => '50' ),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:312px;' );
|
||||
verify( $flexItems[1] )->stringContainsString( 'width:312px;' );
|
||||
}
|
||||
|
||||
public function testInComputesWidthsForStrangeSettingsValues(): void {
|
||||
$parsedBlock = [
|
||||
'innerBlocks' => [],
|
||||
'email_attrs' => [
|
||||
'width' => '640px',
|
||||
],
|
||||
];
|
||||
public function testInComputesWidthsForStrangeSettingsValues(): void {
|
||||
$parsedBlock = array(
|
||||
'innerBlocks' => array(),
|
||||
'email_attrs' => array(
|
||||
'width' => '640px',
|
||||
),
|
||||
);
|
||||
|
||||
// 100% and 25%
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '100'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => ['width' => '25'],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:508px;');
|
||||
verify($flexItems[1])->stringContainsString('width:105px;');
|
||||
// 100% and 25%
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '100' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array( 'width' => '25' ),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:508px;' );
|
||||
verify( $flexItems[1] )->stringContainsString( 'width:105px;' );
|
||||
|
||||
// 100% and 100%
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '100'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => ['width' => '100'],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:312px;');
|
||||
verify($flexItems[1])->stringContainsString('width:312px;');
|
||||
// 100% and 100%
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '100' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array( 'width' => '100' ),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:312px;' );
|
||||
verify( $flexItems[1] )->stringContainsString( 'width:312px;' );
|
||||
|
||||
// 100% and auto
|
||||
$parsedBlock['innerBlocks'] = array(
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => array( 'width' => '100' ),
|
||||
),
|
||||
array(
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => array(),
|
||||
),
|
||||
);
|
||||
$output = $this->renderer->render_inner_blocks_in_layout( $parsedBlock, $this->settingsController );
|
||||
$flexItems = $this->getFlexItemsFromOutput( $output );
|
||||
verify( $flexItems[0] )->stringContainsString( 'width:508px;' );
|
||||
verify( $flexItems[1] )->stringNotContainsString( 'width:' );
|
||||
}
|
||||
|
||||
// 100% and auto
|
||||
$parsedBlock['innerBlocks'] = [
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 1',
|
||||
'attrs' => ['width' => '100'],
|
||||
],
|
||||
[
|
||||
'blockName' => 'dummy/block',
|
||||
'innerHtml' => 'Dummy 2',
|
||||
'attrs' => [],
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->render_inner_blocks_in_layout($parsedBlock, $this->settingsController);
|
||||
$flexItems = $this->getFlexItemsFromOutput($output);
|
||||
verify($flexItems[0])->stringContainsString('width:508px;');
|
||||
verify($flexItems[1])->stringNotContainsString('width:');
|
||||
}
|
||||
private function getFlexItemsFromOutput( string $output ): array {
|
||||
$matches = array();
|
||||
preg_match_all( '/<td class="layout-flex-item" style="(.*)">/', $output, $matches );
|
||||
return explode( '><', $matches[0][0] ?? array() );
|
||||
}
|
||||
|
||||
private function getFlexItemsFromOutput(string $output): array {
|
||||
$matches = [];
|
||||
preg_match_all('/<td class="layout-flex-item" style="(.*)">/', $output, $matches);
|
||||
return explode('><', $matches[0][0] ?? []);
|
||||
}
|
||||
public function renderDummyBlock( $blockContent, $parsedBlock ): string {
|
||||
$dummyRenderer = new Dummy_Block_Renderer();
|
||||
return $dummyRenderer->render( $blockContent, $parsedBlock, $this->settingsController );
|
||||
}
|
||||
|
||||
public function renderDummyBlock($blockContent, $parsedBlock): string {
|
||||
$dummyRenderer = new Dummy_Block_Renderer();
|
||||
return $dummyRenderer->render($blockContent, $parsedBlock, $this->settingsController);
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
unregister_block_type('dummy/block');
|
||||
remove_filter('render_block', [$this, 'renderDummyBlock'], 10);
|
||||
}
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
unregister_block_type( 'dummy/block' );
|
||||
remove_filter( 'render_block', array( $this, 'renderDummyBlock' ), 10 );
|
||||
}
|
||||
}
|
||||
|
@@ -7,116 +7,123 @@ use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
use MailPoet\EmailEditor\Engine\Theme_Controller;
|
||||
|
||||
class Renderer_Test extends \MailPoetTest {
|
||||
private Renderer $renderer;
|
||||
private Renderer $renderer;
|
||||
|
||||
private \WP_Post $emailPost;
|
||||
private \WP_Post $emailPost;
|
||||
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->renderer = $this->diContainer->get(Renderer::class);
|
||||
$styles = [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'bottom' => '4px',
|
||||
'top' => '3px',
|
||||
'left' => '2px',
|
||||
'right' => '1px',
|
||||
],
|
||||
],
|
||||
'typography' => [
|
||||
'fontFamily' => 'Test Font Family',
|
||||
],
|
||||
'color' => [
|
||||
'background' => '#123456',
|
||||
],
|
||||
];
|
||||
$themeJsonMock = $this->createMock(\WP_Theme_JSON::class);
|
||||
$themeJsonMock->method('get_data')->willReturn([
|
||||
'styles' => $styles,
|
||||
]);
|
||||
$settingsControllerMock = $this->createMock(Settings_Controller::class);
|
||||
$settingsControllerMock->method('get_email_styles')->willReturn($styles);
|
||||
$themeControllerMock = $this->createMock(Theme_Controller::class);
|
||||
$themeControllerMock->method('get_theme')->willReturn($themeJsonMock);
|
||||
$themeControllerMock->method('get_styles')->willReturn($styles);
|
||||
$themeControllerMock->method('get_layout_settings')->willReturn(['contentSize' => '660px']);
|
||||
public function _before(): void {
|
||||
parent::_before();
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->renderer = $this->diContainer->get( Renderer::class );
|
||||
$styles = array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'bottom' => '4px',
|
||||
'top' => '3px',
|
||||
'left' => '2px',
|
||||
'right' => '1px',
|
||||
),
|
||||
),
|
||||
'typography' => array(
|
||||
'fontFamily' => 'Test Font Family',
|
||||
),
|
||||
'color' => array(
|
||||
'background' => '#123456',
|
||||
),
|
||||
);
|
||||
$themeJsonMock = $this->createMock( \WP_Theme_JSON::class );
|
||||
$themeJsonMock->method( 'get_data' )->willReturn(
|
||||
array(
|
||||
'styles' => $styles,
|
||||
)
|
||||
);
|
||||
$settingsControllerMock = $this->createMock( Settings_Controller::class );
|
||||
$settingsControllerMock->method( 'get_email_styles' )->willReturn( $styles );
|
||||
$themeControllerMock = $this->createMock( Theme_Controller::class );
|
||||
$themeControllerMock->method( 'get_theme' )->willReturn( $themeJsonMock );
|
||||
$themeControllerMock->method( 'get_styles' )->willReturn( $styles );
|
||||
$themeControllerMock->method( 'get_layout_settings' )->willReturn( array( 'contentSize' => '660px' ) );
|
||||
|
||||
$this->renderer = $this->getServiceWithOverrides(Renderer::class, [
|
||||
'settingsController' => $settingsControllerMock,
|
||||
'themeController' => $themeControllerMock,
|
||||
]);
|
||||
$this->emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
|
||||
]);
|
||||
}
|
||||
$this->renderer = $this->getServiceWithOverrides(
|
||||
Renderer::class,
|
||||
array(
|
||||
'settingsController' => $settingsControllerMock,
|
||||
'themeController' => $themeControllerMock,
|
||||
)
|
||||
);
|
||||
$this->emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testItRendersTemplateWithContent(): void {
|
||||
$rendered = $this->renderer->render(
|
||||
$this->emailPost,
|
||||
'Subject',
|
||||
'Preheader content',
|
||||
'en',
|
||||
'noindex,nofollow'
|
||||
);
|
||||
verify($rendered['html'])->stringContainsString('Subject');
|
||||
verify($rendered['html'])->stringContainsString('Preheader content');
|
||||
verify($rendered['html'])->stringContainsString('noindex,nofollow');
|
||||
verify($rendered['html'])->stringContainsString('Hello!');
|
||||
public function testItRendersTemplateWithContent(): void {
|
||||
$rendered = $this->renderer->render(
|
||||
$this->emailPost,
|
||||
'Subject',
|
||||
'Preheader content',
|
||||
'en',
|
||||
'noindex,nofollow'
|
||||
);
|
||||
verify( $rendered['html'] )->stringContainsString( 'Subject' );
|
||||
verify( $rendered['html'] )->stringContainsString( 'Preheader content' );
|
||||
verify( $rendered['html'] )->stringContainsString( 'noindex,nofollow' );
|
||||
verify( $rendered['html'] )->stringContainsString( 'Hello!' );
|
||||
|
||||
verify($rendered['text'])->stringContainsString('Preheader content');
|
||||
verify($rendered['text'])->stringContainsString('Hello!');
|
||||
}
|
||||
verify( $rendered['text'] )->stringContainsString( 'Preheader content' );
|
||||
verify( $rendered['text'] )->stringContainsString( 'Hello!' );
|
||||
}
|
||||
|
||||
public function testItInlinesStyles(): void {
|
||||
$stylesCallback = function ($styles) {
|
||||
return $styles . 'body { color: pink; }';
|
||||
};
|
||||
add_filter('mailpoet_email_renderer_styles', $stylesCallback);
|
||||
$rendered = $this->renderer->render($this->emailPost, 'Subject', '', 'en');
|
||||
$style = $this->getStylesValueForTag($rendered['html'], ['tag_name' => 'body']);
|
||||
verify($style)->stringContainsString('color: pink');
|
||||
remove_filter('mailpoet_email_renderer_styles', $stylesCallback);
|
||||
}
|
||||
public function testItInlinesStyles(): void {
|
||||
$stylesCallback = function ( $styles ) {
|
||||
return $styles . 'body { color: pink; }';
|
||||
};
|
||||
add_filter( 'mailpoet_email_renderer_styles', $stylesCallback );
|
||||
$rendered = $this->renderer->render( $this->emailPost, 'Subject', '', 'en' );
|
||||
$style = $this->getStylesValueForTag( $rendered['html'], array( 'tag_name' => 'body' ) );
|
||||
verify( $style )->stringContainsString( 'color: pink' );
|
||||
remove_filter( 'mailpoet_email_renderer_styles', $stylesCallback );
|
||||
}
|
||||
|
||||
public function testItInlinesBodyStyles(): void {
|
||||
$rendered = $this->renderer->render($this->emailPost, 'Subject', '', 'en');
|
||||
$style = $this->getStylesValueForTag($rendered['html'], ['tag_name' => 'body']);
|
||||
verify($style)->stringContainsString('margin: 0; padding: 0;');
|
||||
}
|
||||
public function testItInlinesBodyStyles(): void {
|
||||
$rendered = $this->renderer->render( $this->emailPost, 'Subject', '', 'en' );
|
||||
$style = $this->getStylesValueForTag( $rendered['html'], array( 'tag_name' => 'body' ) );
|
||||
verify( $style )->stringContainsString( 'margin: 0; padding: 0;' );
|
||||
}
|
||||
|
||||
public function testItInlinesWrappersStyles(): void {
|
||||
$rendered = $this->renderer->render($this->emailPost, 'Subject', '', 'en');
|
||||
public function testItInlinesWrappersStyles(): void {
|
||||
$rendered = $this->renderer->render( $this->emailPost, 'Subject', '', 'en' );
|
||||
|
||||
// Verify body element styles
|
||||
$style = $this->getStylesValueForTag($rendered['html'], ['tag_name' => 'body']);
|
||||
verify($style)->stringContainsString('background-color: #123456');
|
||||
// Verify body element styles
|
||||
$style = $this->getStylesValueForTag( $rendered['html'], array( 'tag_name' => 'body' ) );
|
||||
verify( $style )->stringContainsString( 'background-color: #123456' );
|
||||
|
||||
// Verify layout element styles
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML($rendered['html']);
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$wrapper = null;
|
||||
$nodes = $xpath->query('//div[contains(@class, "email_layout_wrapper")]');
|
||||
if (($nodes instanceof \DOMNodeList) && $nodes->length > 0) {
|
||||
$wrapper = $nodes->item(0);
|
||||
}
|
||||
$this->assertInstanceOf(\DOMElement::class, $wrapper);
|
||||
$style = $wrapper->getAttribute('style');
|
||||
verify($style)->stringContainsString('background-color: #123456');
|
||||
verify($style)->stringContainsString('font-family: Test Font Family;');
|
||||
verify($style)->stringContainsString('padding-top: 3px;');
|
||||
verify($style)->stringContainsString('padding-bottom: 4px;');
|
||||
verify($style)->stringContainsString('padding-left: 2px;');
|
||||
verify($style)->stringContainsString('padding-right: 1px;');
|
||||
verify($style)->stringContainsString('max-width: 660px;');
|
||||
}
|
||||
// Verify layout element styles
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML( $rendered['html'] );
|
||||
$xpath = new \DOMXPath( $doc );
|
||||
$wrapper = null;
|
||||
$nodes = $xpath->query( '//div[contains(@class, "email_layout_wrapper")]' );
|
||||
if ( ( $nodes instanceof \DOMNodeList ) && $nodes->length > 0 ) {
|
||||
$wrapper = $nodes->item( 0 );
|
||||
}
|
||||
$this->assertInstanceOf( \DOMElement::class, $wrapper );
|
||||
$style = $wrapper->getAttribute( 'style' );
|
||||
verify( $style )->stringContainsString( 'background-color: #123456' );
|
||||
verify( $style )->stringContainsString( 'font-family: Test Font Family;' );
|
||||
verify( $style )->stringContainsString( 'padding-top: 3px;' );
|
||||
verify( $style )->stringContainsString( 'padding-bottom: 4px;' );
|
||||
verify( $style )->stringContainsString( 'padding-left: 2px;' );
|
||||
verify( $style )->stringContainsString( 'padding-right: 1px;' );
|
||||
verify( $style )->stringContainsString( 'max-width: 660px;' );
|
||||
}
|
||||
|
||||
private function getStylesValueForTag(string $html, array $query): ?string {
|
||||
$html = new \WP_HTML_Tag_Processor($html);
|
||||
if ($html->next_tag($query)) {
|
||||
return $html->get_attribute('style');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function getStylesValueForTag( string $html, array $query ): ?string {
|
||||
$html = new \WP_HTML_Tag_Processor( $html );
|
||||
if ( $html->next_tag( $query ) ) {
|
||||
return $html->get_attribute( 'style' );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,109 +3,109 @@
|
||||
namespace MailPoet\EmailEditor\Engine;
|
||||
|
||||
class Theme_Controller_Test extends \MailPoetTest {
|
||||
private Theme_Controller $themeController;
|
||||
private Theme_Controller $themeController;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->themeController = $this->diContainer->get(Theme_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->themeController = $this->diContainer->get( Theme_Controller::class );
|
||||
}
|
||||
|
||||
public function testItGeneratesCssStylesForRenderer() {
|
||||
$css = $this->themeController->get_stylesheet_for_rendering();
|
||||
// Font families
|
||||
verify($css)->stringContainsString('.has-arial-font-family');
|
||||
verify($css)->stringContainsString('.has-comic-sans-ms-font-family');
|
||||
verify($css)->stringContainsString('.has-courier-new-font-family');
|
||||
verify($css)->stringContainsString('.has-georgia-font-family');
|
||||
verify($css)->stringContainsString('.has-lucida-font-family');
|
||||
verify($css)->stringContainsString('.has-tahoma-font-family');
|
||||
verify($css)->stringContainsString('.has-times-new-roman-font-family');
|
||||
verify($css)->stringContainsString('.has-trebuchet-ms-font-family');
|
||||
verify($css)->stringContainsString('.has-verdana-font-family');
|
||||
verify($css)->stringContainsString('.has-arvo-font-family');
|
||||
verify($css)->stringContainsString('.has-lato-font-family');
|
||||
verify($css)->stringContainsString('.has-merriweather-font-family');
|
||||
verify($css)->stringContainsString('.has-merriweather-sans-font-family');
|
||||
verify($css)->stringContainsString('.has-noticia-text-font-family');
|
||||
verify($css)->stringContainsString('.has-open-sans-font-family');
|
||||
verify($css)->stringContainsString('.has-playfair-display-font-family');
|
||||
verify($css)->stringContainsString('.has-roboto-font-family');
|
||||
verify($css)->stringContainsString('.has-source-sans-pro-font-family');
|
||||
verify($css)->stringContainsString('.has-oswald-font-family');
|
||||
verify($css)->stringContainsString('.has-raleway-font-family');
|
||||
verify($css)->stringContainsString('.has-permanent-marker-font-family');
|
||||
verify($css)->stringContainsString('.has-pacifico-font-family');
|
||||
public function testItGeneratesCssStylesForRenderer() {
|
||||
$css = $this->themeController->get_stylesheet_for_rendering();
|
||||
// Font families
|
||||
verify( $css )->stringContainsString( '.has-arial-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-comic-sans-ms-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-courier-new-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-georgia-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-lucida-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-tahoma-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-times-new-roman-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-trebuchet-ms-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-verdana-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-arvo-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-lato-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-merriweather-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-merriweather-sans-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-noticia-text-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-open-sans-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-playfair-display-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-roboto-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-source-sans-pro-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-oswald-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-raleway-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-permanent-marker-font-family' );
|
||||
verify( $css )->stringContainsString( '.has-pacifico-font-family' );
|
||||
|
||||
verify($css)->stringContainsString('.has-small-font-size');
|
||||
verify($css)->stringContainsString('.has-medium-font-size');
|
||||
verify($css)->stringContainsString('.has-large-font-size');
|
||||
verify($css)->stringContainsString('.has-x-large-font-size');
|
||||
verify( $css )->stringContainsString( '.has-small-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-medium-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-large-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-x-large-font-size' );
|
||||
|
||||
// Font sizes
|
||||
verify($css)->stringContainsString('.has-small-font-size');
|
||||
verify($css)->stringContainsString('.has-medium-font-size');
|
||||
verify($css)->stringContainsString('.has-large-font-size');
|
||||
verify($css)->stringContainsString('.has-x-large-font-size');
|
||||
// Font sizes
|
||||
verify( $css )->stringContainsString( '.has-small-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-medium-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-large-font-size' );
|
||||
verify( $css )->stringContainsString( '.has-x-large-font-size' );
|
||||
|
||||
// Colors
|
||||
verify($css)->stringContainsString('.has-black-color');
|
||||
verify($css)->stringContainsString('.has-black-background-color');
|
||||
verify($css)->stringContainsString('.has-black-border-color');
|
||||
// Colors
|
||||
verify( $css )->stringContainsString( '.has-black-color' );
|
||||
verify( $css )->stringContainsString( '.has-black-background-color' );
|
||||
verify( $css )->stringContainsString( '.has-black-border-color' );
|
||||
|
||||
verify($css)->stringContainsString('.has-black-color');
|
||||
verify($css)->stringContainsString('.has-black-background-color');
|
||||
verify($css)->stringContainsString('.has-black-border-color');
|
||||
verify( $css )->stringContainsString( '.has-black-color' );
|
||||
verify( $css )->stringContainsString( '.has-black-background-color' );
|
||||
verify( $css )->stringContainsString( '.has-black-border-color' );
|
||||
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
if (wp_get_theme()->get('Name') === 'Twenty Twenty-One') {
|
||||
verify($css)->stringContainsString('.has-yellow-background-color');
|
||||
verify($css)->stringContainsString('.has-yellow-color');
|
||||
verify($css)->stringContainsString('.has-yellow-border-color');
|
||||
}
|
||||
}
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
if ( wp_get_theme()->get( 'Name' ) === 'Twenty Twenty-One' ) {
|
||||
verify( $css )->stringContainsString( '.has-yellow-background-color' );
|
||||
verify( $css )->stringContainsString( '.has-yellow-color' );
|
||||
verify( $css )->stringContainsString( '.has-yellow-border-color' );
|
||||
}
|
||||
}
|
||||
|
||||
public function testItCanTranslateFontSizeSlug() {
|
||||
verify($this->themeController->translate_slug_to_font_size('small'))->equals('13px');
|
||||
verify($this->themeController->translate_slug_to_font_size('medium'))->equals('16px');
|
||||
verify($this->themeController->translate_slug_to_font_size('large'))->equals('28px');
|
||||
verify($this->themeController->translate_slug_to_font_size('x-large'))->equals('42px');
|
||||
verify($this->themeController->translate_slug_to_font_size('unknown'))->equals('unknown');
|
||||
}
|
||||
public function testItCanTranslateFontSizeSlug() {
|
||||
verify( $this->themeController->translate_slug_to_font_size( 'small' ) )->equals( '13px' );
|
||||
verify( $this->themeController->translate_slug_to_font_size( 'medium' ) )->equals( '16px' );
|
||||
verify( $this->themeController->translate_slug_to_font_size( 'large' ) )->equals( '28px' );
|
||||
verify( $this->themeController->translate_slug_to_font_size( 'x-large' ) )->equals( '42px' );
|
||||
verify( $this->themeController->translate_slug_to_font_size( 'unknown' ) )->equals( 'unknown' );
|
||||
}
|
||||
|
||||
public function testItCanTranslateColorSlug() {
|
||||
verify($this->themeController->translate_slug_to_color('black'))->equals('#000000');
|
||||
verify($this->themeController->translate_slug_to_color('white'))->equals('#ffffff');
|
||||
verify($this->themeController->translate_slug_to_color('cyan-bluish-gray'))->equals('#abb8c3');
|
||||
verify($this->themeController->translate_slug_to_color('pale-pink'))->equals('#f78da7');
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
if (wp_get_theme()->get('Name') === 'Twenty Twenty-One') {
|
||||
verify($this->themeController->translate_slug_to_color('yellow'))->equals('#eeeadd');
|
||||
}
|
||||
}
|
||||
public function testItCanTranslateColorSlug() {
|
||||
verify( $this->themeController->translate_slug_to_color( 'black' ) )->equals( '#000000' );
|
||||
verify( $this->themeController->translate_slug_to_color( 'white' ) )->equals( '#ffffff' );
|
||||
verify( $this->themeController->translate_slug_to_color( 'cyan-bluish-gray' ) )->equals( '#abb8c3' );
|
||||
verify( $this->themeController->translate_slug_to_color( 'pale-pink' ) )->equals( '#f78da7' );
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
if ( wp_get_theme()->get( 'Name' ) === 'Twenty Twenty-One' ) {
|
||||
verify( $this->themeController->translate_slug_to_color( 'yellow' ) )->equals( '#eeeadd' );
|
||||
}
|
||||
}
|
||||
|
||||
public function testItLoadsColorPaletteFromSiteTheme() {
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
$settings = $this->themeController->get_settings();
|
||||
if (wp_get_theme()->get('Name') === 'Twenty Twenty-One') {
|
||||
verify($settings['color']['palette']['theme'])->notEmpty();
|
||||
}
|
||||
}
|
||||
public function testItLoadsColorPaletteFromSiteTheme() {
|
||||
$this->checkCorrectThemeConfiguration();
|
||||
$settings = $this->themeController->get_settings();
|
||||
if ( wp_get_theme()->get( 'Name' ) === 'Twenty Twenty-One' ) {
|
||||
verify( $settings['color']['palette']['theme'] )->notEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public function testItReturnsCorrectPresetVariablesMap() {
|
||||
$variableMap = $this->themeController->get_variables_values_map();
|
||||
verify($variableMap['--wp--preset--color--black'])->equals('#000000');
|
||||
verify($variableMap['--wp--preset--spacing--20'])->equals('20px');
|
||||
}
|
||||
public function testItReturnsCorrectPresetVariablesMap() {
|
||||
$variableMap = $this->themeController->get_variables_values_map();
|
||||
verify( $variableMap['--wp--preset--color--black'] )->equals( '#000000' );
|
||||
verify( $variableMap['--wp--preset--spacing--20'] )->equals( '20px' );
|
||||
}
|
||||
|
||||
/**
|
||||
* This test depends on using Twenty Twenty-One or Twenty Nineteen theme.
|
||||
* This method checks if the theme is correctly configured and trigger a failure if not
|
||||
* to prevent silent failures in case we change theme configuration in the test environment.
|
||||
*/
|
||||
private function checkCorrectThemeConfiguration() {
|
||||
$expectedThemes = ['Twenty Twenty-One'];
|
||||
if (!in_array(wp_get_theme()->get('Name'), $expectedThemes)) {
|
||||
$this->fail('Test depends on using Twenty Twenty-One or Twenty Nineteen theme. If you changed the theme, please update the test.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This test depends on using Twenty Twenty-One or Twenty Nineteen theme.
|
||||
* This method checks if the theme is correctly configured and trigger a failure if not
|
||||
* to prevent silent failures in case we change theme configuration in the test environment.
|
||||
*/
|
||||
private function checkCorrectThemeConfiguration() {
|
||||
$expectedThemes = array( 'Twenty Twenty-One' );
|
||||
if ( ! in_array( wp_get_theme()->get( 'Name' ), $expectedThemes ) ) {
|
||||
$this->fail( 'Test depends on using Twenty Twenty-One or Twenty Nineteen theme. If you changed the theme, please update the test.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,156 +6,168 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Button_Test extends \MailPoetTest {
|
||||
/** @var Button */
|
||||
private $buttonRenderer;
|
||||
/** @var Button */
|
||||
private $buttonRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedButton = [
|
||||
'blockName' => 'core/button',
|
||||
'attrs' => [
|
||||
'width' => 50,
|
||||
'style' => [
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
'top' => '10px',
|
||||
'bottom' => '10px',
|
||||
],
|
||||
],
|
||||
'color' => [
|
||||
'background' => '#dddddd',
|
||||
'text' => '#111111',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<div class="wp-block-button has-custom-width wp-block-button__width-50"><a href="http://example.com" class="wp-block-button__link has-text-color has-background has-link-color wp-element-button" style="color:#111111;background-color:#dddddd;padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px">Button Text</a></div>',
|
||||
'innerContent' => ['<div class="wp-block-button has-custom-width wp-block-button__width-50"><a href="http://example.com" class="wp-block-button__link has-text-color has-background has-link-color wp-element-button" style="color:#111111;background-color:#dddddd;padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px">Button Text</a></div>'],
|
||||
'email_attrs' => [
|
||||
'color' => '#111111',
|
||||
'width' => '320px',
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedButton = array(
|
||||
'blockName' => 'core/button',
|
||||
'attrs' => array(
|
||||
'width' => 50,
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'left' => '10px',
|
||||
'right' => '10px',
|
||||
'top' => '10px',
|
||||
'bottom' => '10px',
|
||||
),
|
||||
),
|
||||
'color' => array(
|
||||
'background' => '#dddddd',
|
||||
'text' => '#111111',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<div class="wp-block-button has-custom-width wp-block-button__width-50"><a href="http://example.com" class="wp-block-button__link has-text-color has-background has-link-color wp-element-button" style="color:#111111;background-color:#dddddd;padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px">Button Text</a></div>',
|
||||
'innerContent' => array( '<div class="wp-block-button has-custom-width wp-block-button__width-50"><a href="http://example.com" class="wp-block-button__link has-text-color has-background has-link-color wp-element-button" style="color:#111111;background-color:#dddddd;padding-top:10px;padding-right:10px;padding-bottom:10px;padding-left:10px">Button Text</a></div>' ),
|
||||
'email_attrs' => array(
|
||||
'color' => '#111111',
|
||||
'width' => '320px',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before(): void {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->buttonRenderer = new Button();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before(): void {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->buttonRenderer = new Button();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersLink(): void {
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('href="http://example.com"');
|
||||
verify($output)->stringContainsString('Button Text');
|
||||
}
|
||||
public function testItRendersLink(): void {
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'href="http://example.com"' );
|
||||
verify( $output )->stringContainsString( 'Button Text' );
|
||||
}
|
||||
|
||||
public function testItRendersPaddingBasedOnAttributesValue(): void {
|
||||
$this->parsedButton['attrs']['style']['spacing']['padding'] = [
|
||||
'left' => '10px',
|
||||
'right' => '20px',
|
||||
'top' => '30px',
|
||||
'bottom' => '40px',
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('padding-left:10px;');
|
||||
verify($output)->stringContainsString('padding-right:20px;');
|
||||
verify($output)->stringContainsString('padding-top:30px;');
|
||||
verify($output)->stringContainsString('padding-bottom:40px;');
|
||||
}
|
||||
public function testItRendersPaddingBasedOnAttributesValue(): void {
|
||||
$this->parsedButton['attrs']['style']['spacing']['padding'] = array(
|
||||
'left' => '10px',
|
||||
'right' => '20px',
|
||||
'top' => '30px',
|
||||
'bottom' => '40px',
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'padding-left:10px;' );
|
||||
verify( $output )->stringContainsString( 'padding-right:20px;' );
|
||||
verify( $output )->stringContainsString( 'padding-top:30px;' );
|
||||
verify( $output )->stringContainsString( 'padding-bottom:40px;' );
|
||||
}
|
||||
|
||||
public function testItRendersColors(): void {
|
||||
$this->parsedButton['attrs']['style']['color'] = [
|
||||
'background' => '#000000',
|
||||
'text' => '#111111',
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('background-color:#000000;');
|
||||
verify($output)->stringContainsString('color:#111111;');
|
||||
}
|
||||
public function testItRendersColors(): void {
|
||||
$this->parsedButton['attrs']['style']['color'] = array(
|
||||
'background' => '#000000',
|
||||
'text' => '#111111',
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'background-color:#000000;' );
|
||||
verify( $output )->stringContainsString( 'color:#111111;' );
|
||||
}
|
||||
|
||||
public function testItRendersBorder(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = [
|
||||
'width' => '10px',
|
||||
'color' => '#111111',
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('border-color:#111111;');
|
||||
verify($output)->stringContainsString('border-width:10px;');
|
||||
verify($output)->stringContainsString('border-style:solid;');
|
||||
}
|
||||
public function testItRendersBorder(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = array(
|
||||
'width' => '10px',
|
||||
'color' => '#111111',
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'border-color:#111111;' );
|
||||
verify( $output )->stringContainsString( 'border-width:10px;' );
|
||||
verify( $output )->stringContainsString( 'border-style:solid;' );
|
||||
}
|
||||
|
||||
public function testItRendersEachSideSpecificBorder(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = [
|
||||
'top' => ['width' => '1px', 'color' => '#111111'],
|
||||
'right' => ['width' => '2px', 'color' => '#222222'],
|
||||
'bottom' => ['width' => '3px', 'color' => '#333333'],
|
||||
'left' => ['width' => '4px', 'color' => '#444444'],
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('border-top-width:1px;');
|
||||
verify($output)->stringContainsString('border-top-color:#111111;');
|
||||
public function testItRendersEachSideSpecificBorder(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = array(
|
||||
'top' => array(
|
||||
'width' => '1px',
|
||||
'color' => '#111111',
|
||||
),
|
||||
'right' => array(
|
||||
'width' => '2px',
|
||||
'color' => '#222222',
|
||||
),
|
||||
'bottom' => array(
|
||||
'width' => '3px',
|
||||
'color' => '#333333',
|
||||
),
|
||||
'left' => array(
|
||||
'width' => '4px',
|
||||
'color' => '#444444',
|
||||
),
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'border-top-width:1px;' );
|
||||
verify( $output )->stringContainsString( 'border-top-color:#111111;' );
|
||||
|
||||
verify($output)->stringContainsString('border-right-width:2px;');
|
||||
verify($output)->stringContainsString('border-right-color:#222222;');
|
||||
verify( $output )->stringContainsString( 'border-right-width:2px;' );
|
||||
verify( $output )->stringContainsString( 'border-right-color:#222222;' );
|
||||
|
||||
verify($output)->stringContainsString('border-bottom-width:3px;');
|
||||
verify($output)->stringContainsString('border-bottom-color:#333333;');
|
||||
verify( $output )->stringContainsString( 'border-bottom-width:3px;' );
|
||||
verify( $output )->stringContainsString( 'border-bottom-color:#333333;' );
|
||||
|
||||
verify($output)->stringContainsString('border-left-width:4px;');
|
||||
verify($output)->stringContainsString('border-left-color:#444444;');
|
||||
verify( $output )->stringContainsString( 'border-left-width:4px;' );
|
||||
verify( $output )->stringContainsString( 'border-left-color:#444444;' );
|
||||
|
||||
verify($output)->stringContainsString('border-style:solid;');
|
||||
}
|
||||
verify( $output )->stringContainsString( 'border-style:solid;' );
|
||||
}
|
||||
|
||||
public function testItRendersBorderRadius(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = [
|
||||
'radius' => '10px',
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('border-radius:10px;');
|
||||
}
|
||||
public function testItRendersBorderRadius(): void {
|
||||
$this->parsedButton['attrs']['style']['border'] = array(
|
||||
'radius' => '10px',
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'border-radius:10px;' );
|
||||
}
|
||||
|
||||
public function testItRendersFontSize(): void {
|
||||
$this->parsedButton['attrs']['style']['typography']['fontSize'] = '10px';
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('font-size:10px;');
|
||||
}
|
||||
public function testItRendersFontSize(): void {
|
||||
$this->parsedButton['attrs']['style']['typography']['fontSize'] = '10px';
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'font-size:10px;' );
|
||||
}
|
||||
|
||||
public function testItRendersCornerSpecificBorderRadius(): void {
|
||||
$this->parsedButton['attrs']['style']['border']['radius'] = [
|
||||
'topLeft' => '1px',
|
||||
'topRight' => '2px',
|
||||
'bottomLeft' => '3px',
|
||||
'bottomRight' => '4px',
|
||||
];
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
verify($output)->stringContainsString('border-top-left-radius:1px;');
|
||||
verify($output)->stringContainsString('border-top-right-radius:2px;');
|
||||
verify($output)->stringContainsString('border-bottom-left-radius:3px;');
|
||||
verify($output)->stringContainsString('border-bottom-right-radius:4px;');
|
||||
}
|
||||
public function testItRendersCornerSpecificBorderRadius(): void {
|
||||
$this->parsedButton['attrs']['style']['border']['radius'] = array(
|
||||
'topLeft' => '1px',
|
||||
'topRight' => '2px',
|
||||
'bottomLeft' => '3px',
|
||||
'bottomRight' => '4px',
|
||||
);
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
verify( $output )->stringContainsString( 'border-top-left-radius:1px;' );
|
||||
verify( $output )->stringContainsString( 'border-top-right-radius:2px;' );
|
||||
verify( $output )->stringContainsString( 'border-bottom-left-radius:3px;' );
|
||||
verify( $output )->stringContainsString( 'border-bottom-right-radius:4px;' );
|
||||
}
|
||||
|
||||
public function testItRendersBackgroundColorSetBySlug(): void {
|
||||
unset($this->parsedButton['attrs']['style']['color']);
|
||||
unset($this->parsedButton['attrs']['style']['spacing']['padding']);
|
||||
$this->parsedButton['attrs']['backgroundColor'] = 'black';
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
// For other blocks this is handled by CSS-inliner, but for button we need to handle it manually
|
||||
// because of special email HTML markup
|
||||
verify($output)->stringContainsString('background-color:#000000;');
|
||||
}
|
||||
public function testItRendersBackgroundColorSetBySlug(): void {
|
||||
unset( $this->parsedButton['attrs']['style']['color'] );
|
||||
unset( $this->parsedButton['attrs']['style']['spacing']['padding'] );
|
||||
$this->parsedButton['attrs']['backgroundColor'] = 'black';
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
// For other blocks this is handled by CSS-inliner, but for button we need to handle it manually
|
||||
// because of special email HTML markup
|
||||
verify( $output )->stringContainsString( 'background-color:#000000;' );
|
||||
}
|
||||
|
||||
public function testItRendersFontColorSetBySlug(): void {
|
||||
unset($this->parsedButton['attrs']['style']['color']);
|
||||
unset($this->parsedButton['attrs']['style']['spacing']['padding']);
|
||||
$this->parsedButton['attrs']['textColor'] = 'white';
|
||||
$output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController);
|
||||
// For other blocks this is handled by CSS-inliner, but for button we need to handle it manually
|
||||
// because of special email HTML markup
|
||||
verify($output)->stringContainsString('color:#fff');
|
||||
}
|
||||
public function testItRendersFontColorSetBySlug(): void {
|
||||
unset( $this->parsedButton['attrs']['style']['color'] );
|
||||
unset( $this->parsedButton['attrs']['style']['spacing']['padding'] );
|
||||
$this->parsedButton['attrs']['textColor'] = 'white';
|
||||
$output = $this->buttonRenderer->render( $this->parsedButton['innerHTML'], $this->parsedButton, $this->settingsController );
|
||||
// For other blocks this is handled by CSS-inliner, but for button we need to handle it manually
|
||||
// because of special email HTML markup
|
||||
verify( $output )->stringContainsString( 'color:#fff' );
|
||||
}
|
||||
}
|
||||
|
@@ -6,138 +6,138 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Column_Test extends \MailPoetTest {
|
||||
/** @var Column */
|
||||
private $columnRenderer;
|
||||
/** @var Column */
|
||||
private $columnRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedColumn = [
|
||||
'blockName' => 'core/column',
|
||||
'email_attrs' => [
|
||||
'width' => '300px',
|
||||
],
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
0 => [
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<p>Column content</p>',
|
||||
'innerContent' => [
|
||||
0 => '<p>Column content</p>',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerHTML' => '<div class="wp-block-column"></div>',
|
||||
'innerContent' => [
|
||||
0 => '<div class="wp-block-column">',
|
||||
1 => null,
|
||||
2 => '</div>',
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedColumn = array(
|
||||
'blockName' => 'core/column',
|
||||
'email_attrs' => array(
|
||||
'width' => '300px',
|
||||
),
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
0 => array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<p>Column content</p>',
|
||||
'innerContent' => array(
|
||||
0 => '<p>Column content</p>',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerHTML' => '<div class="wp-block-column"></div>',
|
||||
'innerContent' => array(
|
||||
0 => '<div class="wp-block-column">',
|
||||
1 => null,
|
||||
2 => '</div>',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->columnRenderer = new Column();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->columnRenderer = new Column();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersColumnContent() {
|
||||
$rendered = $this->columnRenderer->render('', $this->parsedColumn, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('Column content', $rendered);
|
||||
}
|
||||
public function testItRendersColumnContent() {
|
||||
$rendered = $this->columnRenderer->render( '', $this->parsedColumn, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'Column content', $rendered );
|
||||
}
|
||||
|
||||
public function testItContainsColumnsStyles(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs'] = [
|
||||
'style' => [
|
||||
'border' => [
|
||||
'bottom' => [
|
||||
'color' => '#111111',
|
||||
'width' => '1px',
|
||||
],
|
||||
'left' => [
|
||||
'color' => '#222222',
|
||||
'width' => '2px',
|
||||
],
|
||||
'right' => [
|
||||
'color' => '#333333',
|
||||
'width' => '3px',
|
||||
],
|
||||
'top' => [
|
||||
'color' => '#444444',
|
||||
'width' => '4px',
|
||||
],
|
||||
'radius' => [
|
||||
'bottomLeft' => '5px',
|
||||
'bottomRight' => '10px',
|
||||
'topLeft' => '15px',
|
||||
'topRight' => '20px',
|
||||
],
|
||||
],
|
||||
'color' => [
|
||||
'background' => '#abcdef',
|
||||
],
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'bottom' => '5px',
|
||||
'left' => '15px',
|
||||
'right' => '20px',
|
||||
'top' => '10px',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$rendered = $this->columnRenderer->render('', $parsedColumn, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('background-color:#abcdef;', $rendered);
|
||||
$this->assertStringContainsString('border-bottom-left-radius:5px;', $rendered);
|
||||
$this->assertStringContainsString('border-bottom-right-radius:10px;', $rendered);
|
||||
$this->assertStringContainsString('border-top-left-radius:15px;', $rendered);
|
||||
$this->assertStringContainsString('border-top-right-radius:20px;', $rendered);
|
||||
$this->assertStringContainsString('border-top-color:#444444;', $rendered);
|
||||
$this->assertStringContainsString('border-top-width:4px;', $rendered);
|
||||
$this->assertStringContainsString('border-right-color:#333333;', $rendered);
|
||||
$this->assertStringContainsString('border-right-width:3px;', $rendered);
|
||||
$this->assertStringContainsString('border-bottom-color:#111111;', $rendered);
|
||||
$this->assertStringContainsString('border-bottom-width:1px;', $rendered);
|
||||
$this->assertStringContainsString('border-left-color:#222222;', $rendered);
|
||||
$this->assertStringContainsString('border-left-width:2px;', $rendered);
|
||||
$this->assertStringContainsString('border-style:solid;', $rendered);
|
||||
$this->assertStringContainsString('padding-bottom:5px;', $rendered);
|
||||
$this->assertStringContainsString('padding-left:15px;', $rendered);
|
||||
$this->assertStringContainsString('padding-right:20px;', $rendered);
|
||||
$this->assertStringContainsString('padding-top:10px;', $rendered);
|
||||
$this->assertStringContainsString('vertical-align:top;', $rendered); // Check for the default value of vertical alignment
|
||||
}
|
||||
public function testItContainsColumnsStyles(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs'] = array(
|
||||
'style' => array(
|
||||
'border' => array(
|
||||
'bottom' => array(
|
||||
'color' => '#111111',
|
||||
'width' => '1px',
|
||||
),
|
||||
'left' => array(
|
||||
'color' => '#222222',
|
||||
'width' => '2px',
|
||||
),
|
||||
'right' => array(
|
||||
'color' => '#333333',
|
||||
'width' => '3px',
|
||||
),
|
||||
'top' => array(
|
||||
'color' => '#444444',
|
||||
'width' => '4px',
|
||||
),
|
||||
'radius' => array(
|
||||
'bottomLeft' => '5px',
|
||||
'bottomRight' => '10px',
|
||||
'topLeft' => '15px',
|
||||
'topRight' => '20px',
|
||||
),
|
||||
),
|
||||
'color' => array(
|
||||
'background' => '#abcdef',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'bottom' => '5px',
|
||||
'left' => '15px',
|
||||
'right' => '20px',
|
||||
'top' => '10px',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$rendered = $this->columnRenderer->render( '', $parsedColumn, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'background-color:#abcdef;', $rendered );
|
||||
$this->assertStringContainsString( 'border-bottom-left-radius:5px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-bottom-right-radius:10px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-top-left-radius:15px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-top-right-radius:20px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-top-color:#444444;', $rendered );
|
||||
$this->assertStringContainsString( 'border-top-width:4px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-right-color:#333333;', $rendered );
|
||||
$this->assertStringContainsString( 'border-right-width:3px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-bottom-color:#111111;', $rendered );
|
||||
$this->assertStringContainsString( 'border-bottom-width:1px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-left-color:#222222;', $rendered );
|
||||
$this->assertStringContainsString( 'border-left-width:2px;', $rendered );
|
||||
$this->assertStringContainsString( 'border-style:solid;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-bottom:5px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-left:15px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-right:20px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-top:10px;', $rendered );
|
||||
$this->assertStringContainsString( 'vertical-align:top;', $rendered ); // Check for the default value of vertical alignment
|
||||
}
|
||||
|
||||
public function testItContainsExpectedVerticalAlignment(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs']['verticalAlignment'] = 'bottom';
|
||||
$rendered = $this->columnRenderer->render('', $parsedColumn, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('vertical-align:bottom;', $rendered);
|
||||
}
|
||||
public function testItContainsExpectedVerticalAlignment(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs']['verticalAlignment'] = 'bottom';
|
||||
$rendered = $this->columnRenderer->render( '', $parsedColumn, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'vertical-align:bottom;', $rendered );
|
||||
}
|
||||
|
||||
public function testItSetsCustomColorAndBackground(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs']['style']['color']['text'] = '#123456';
|
||||
$parsedColumn['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnRenderer->render('', $parsedColumn, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('color:#123456;', $rendered);
|
||||
$this->assertStringContainsString('background-color:#654321;', $rendered);
|
||||
}
|
||||
public function testItSetsCustomColorAndBackground(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$parsedColumn['attrs']['style']['color']['text'] = '#123456';
|
||||
$parsedColumn['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnRenderer->render( '', $parsedColumn, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'color:#123456;', $rendered );
|
||||
$this->assertStringContainsString( 'background-color:#654321;', $rendered );
|
||||
}
|
||||
|
||||
public function testItPreservesClassesSetByEditor(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$content = '<div class="wp-block-column editor-class-1 another-class"></div>';
|
||||
$parsedColumn['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnRenderer->render($content, $parsedColumn, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('wp-block-column editor-class-1 another-class', $rendered);
|
||||
}
|
||||
public function testItPreservesClassesSetByEditor(): void {
|
||||
$parsedColumn = $this->parsedColumn;
|
||||
$content = '<div class="wp-block-column editor-class-1 another-class"></div>';
|
||||
$parsedColumn['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnRenderer->render( $content, $parsedColumn, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'wp-block-column editor-class-1 another-class', $rendered );
|
||||
}
|
||||
}
|
||||
|
@@ -6,106 +6,106 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Columns_Test extends \MailPoetTest {
|
||||
/** @var Columns */
|
||||
private $columnsRenderer;
|
||||
/** @var Columns */
|
||||
private $columnsRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedColumns = [
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => [],
|
||||
'email_attrs' => [
|
||||
'width' => '784px',
|
||||
],
|
||||
'innerHTML' => '<div class="wp-block-columns"></div>',
|
||||
'innerBlocks' => [
|
||||
0 => [
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
0 => [
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<p>Column 1</p>',
|
||||
'innerContent' => [
|
||||
0 => '<p>Column 1</p>',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerHTML' => '<div class="wp-block-column"></div>',
|
||||
'innerContent' => [
|
||||
0 => '<div class="wp-block-column">',
|
||||
1 => null,
|
||||
2 => '</div>',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedColumns = array(
|
||||
'blockName' => 'core/columns',
|
||||
'attrs' => array(),
|
||||
'email_attrs' => array(
|
||||
'width' => '784px',
|
||||
),
|
||||
'innerHTML' => '<div class="wp-block-columns"></div>',
|
||||
'innerBlocks' => array(
|
||||
0 => array(
|
||||
'blockName' => 'core/column',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
0 => array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<p>Column 1</p>',
|
||||
'innerContent' => array(
|
||||
0 => '<p>Column 1</p>',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerHTML' => '<div class="wp-block-column"></div>',
|
||||
'innerContent' => array(
|
||||
0 => '<div class="wp-block-column">',
|
||||
1 => null,
|
||||
2 => '</div>',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->columnsRenderer = new Columns();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->columnsRenderer = new Columns();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersInnerColumn() {
|
||||
$rendered = $this->columnsRenderer->render('', $this->parsedColumns, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('Column 1');
|
||||
}
|
||||
public function testItRendersInnerColumn() {
|
||||
$rendered = $this->columnsRenderer->render( '', $this->parsedColumns, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'Column 1' );
|
||||
}
|
||||
|
||||
public function testItContainsColumnsStyles(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$parsedColumns['attrs'] = [
|
||||
'style' => [
|
||||
'border' => [
|
||||
'color' => '#123456',
|
||||
'radius' => '10px',
|
||||
'width' => '2px',
|
||||
],
|
||||
'color' => [
|
||||
'background' => '#abcdef',
|
||||
],
|
||||
'spacing' => [
|
||||
'padding' => [
|
||||
'bottom' => '5px',
|
||||
'left' => '15px',
|
||||
'right' => '20px',
|
||||
'top' => '10px',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$rendered = $this->columnsRenderer->render('', $parsedColumns, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('background-color:#abcdef;');
|
||||
verify($rendered)->stringContainsString('border-color:#123456;');
|
||||
verify($rendered)->stringContainsString('border-radius:10px;');
|
||||
verify($rendered)->stringContainsString('border-width:2px;');
|
||||
verify($rendered)->stringContainsString('border-style:solid;');
|
||||
verify($rendered)->stringContainsString('padding-bottom:5px;');
|
||||
verify($rendered)->stringContainsString('padding-left:15px;');
|
||||
verify($rendered)->stringContainsString('padding-right:20px;');
|
||||
verify($rendered)->stringContainsString('padding-top:10px;');
|
||||
}
|
||||
public function testItContainsColumnsStyles(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$parsedColumns['attrs'] = array(
|
||||
'style' => array(
|
||||
'border' => array(
|
||||
'color' => '#123456',
|
||||
'radius' => '10px',
|
||||
'width' => '2px',
|
||||
),
|
||||
'color' => array(
|
||||
'background' => '#abcdef',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'bottom' => '5px',
|
||||
'left' => '15px',
|
||||
'right' => '20px',
|
||||
'top' => '10px',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$rendered = $this->columnsRenderer->render( '', $parsedColumns, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'background-color:#abcdef;' );
|
||||
verify( $rendered )->stringContainsString( 'border-color:#123456;' );
|
||||
verify( $rendered )->stringContainsString( 'border-radius:10px;' );
|
||||
verify( $rendered )->stringContainsString( 'border-width:2px;' );
|
||||
verify( $rendered )->stringContainsString( 'border-style:solid;' );
|
||||
verify( $rendered )->stringContainsString( 'padding-bottom:5px;' );
|
||||
verify( $rendered )->stringContainsString( 'padding-left:15px;' );
|
||||
verify( $rendered )->stringContainsString( 'padding-right:20px;' );
|
||||
verify( $rendered )->stringContainsString( 'padding-top:10px;' );
|
||||
}
|
||||
|
||||
public function testItSetsCustomColorAndBackground(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$parsedColumns['attrs']['style']['color']['text'] = '#123456';
|
||||
$parsedColumns['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnsRenderer->render('', $parsedColumns, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('color:#123456;', $rendered);
|
||||
$this->assertStringContainsString('background-color:#654321;', $rendered);
|
||||
}
|
||||
public function testItSetsCustomColorAndBackground(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$parsedColumns['attrs']['style']['color']['text'] = '#123456';
|
||||
$parsedColumns['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnsRenderer->render( '', $parsedColumns, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'color:#123456;', $rendered );
|
||||
$this->assertStringContainsString( 'background-color:#654321;', $rendered );
|
||||
}
|
||||
|
||||
public function testItPreservesClassesSetByEditor(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$content = '<div class="wp-block-columns editor-class-1 another-class"></div>';
|
||||
$parsedColumns['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnsRenderer->render($content, $parsedColumns, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('wp-block-columns editor-class-1 another-class', $rendered);
|
||||
}
|
||||
public function testItPreservesClassesSetByEditor(): void {
|
||||
$parsedColumns = $this->parsedColumns;
|
||||
$content = '<div class="wp-block-columns editor-class-1 another-class"></div>';
|
||||
$parsedColumns['attrs']['style']['color']['background'] = '#654321';
|
||||
$rendered = $this->columnsRenderer->render( $content, $parsedColumns, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'wp-block-columns editor-class-1 another-class', $rendered );
|
||||
}
|
||||
}
|
||||
|
@@ -6,67 +6,67 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Heading_Test extends \MailPoetTest {
|
||||
/** @var Text */
|
||||
private $headingRenderer;
|
||||
/** @var Text */
|
||||
private $headingRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedHeading = [
|
||||
'blockName' => 'core/heading',
|
||||
'attrs' => [
|
||||
'level' => 1,
|
||||
'backgroundColor' => 'vivid-red',
|
||||
'textColor' => 'pale-cyan-blue',
|
||||
'textAlign' => 'center',
|
||||
'style' => [
|
||||
'typography' => [
|
||||
'textTransform' => 'lowercase',
|
||||
'fontSize' => '24px',
|
||||
],
|
||||
],
|
||||
],
|
||||
'email_attrs' => [
|
||||
'width' => '640px',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<h1 class="has-pale-cyan-blue-color has-vivid-red-background-color has-text-color has-background">This is Heading 1</h1>',
|
||||
'innerContent' => [
|
||||
0 => '<h1 class="has-pale-cyan-blue-color has-vivid-red-background-color has-text-color has-background">This is Heading 1</h1>',
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedHeading = array(
|
||||
'blockName' => 'core/heading',
|
||||
'attrs' => array(
|
||||
'level' => 1,
|
||||
'backgroundColor' => 'vivid-red',
|
||||
'textColor' => 'pale-cyan-blue',
|
||||
'textAlign' => 'center',
|
||||
'style' => array(
|
||||
'typography' => array(
|
||||
'textTransform' => 'lowercase',
|
||||
'fontSize' => '24px',
|
||||
),
|
||||
),
|
||||
),
|
||||
'email_attrs' => array(
|
||||
'width' => '640px',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<h1 class="has-pale-cyan-blue-color has-vivid-red-background-color has-text-color has-background">This is Heading 1</h1>',
|
||||
'innerContent' => array(
|
||||
0 => '<h1 class="has-pale-cyan-blue-color has-vivid-red-background-color has-text-color has-background">This is Heading 1</h1>',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->headingRenderer = new Text();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->headingRenderer = new Text();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersContent(): void {
|
||||
$rendered = $this->headingRenderer->render('<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('This is Heading 1');
|
||||
verify($rendered)->stringContainsString('width:100%;');
|
||||
verify($rendered)->stringContainsString('font-size:24px;');
|
||||
verify($rendered)->stringNotContainsString('width:640px;');
|
||||
}
|
||||
public function testItRendersContent(): void {
|
||||
$rendered = $this->headingRenderer->render( '<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'This is Heading 1' );
|
||||
verify( $rendered )->stringContainsString( 'width:100%;' );
|
||||
verify( $rendered )->stringContainsString( 'font-size:24px;' );
|
||||
verify( $rendered )->stringNotContainsString( 'width:640px;' );
|
||||
}
|
||||
|
||||
public function testItRendersBlockAttributes(): void {
|
||||
$rendered = $this->headingRenderer->render('<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('text-transform:lowercase;');
|
||||
verify($rendered)->stringContainsString('text-align:center;');
|
||||
}
|
||||
public function testItRendersBlockAttributes(): void {
|
||||
$rendered = $this->headingRenderer->render( '<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'text-transform:lowercase;' );
|
||||
verify( $rendered )->stringContainsString( 'text-align:center;' );
|
||||
}
|
||||
|
||||
public function testItRendersCustomSetColors(): void {
|
||||
$this->parsedHeading['attrs']['style']['color']['background'] = '#000000';
|
||||
$this->parsedHeading['attrs']['style']['color']['text'] = '#ff0000';
|
||||
$rendered = $this->headingRenderer->render('<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('background-color:#000000');
|
||||
verify($rendered)->stringContainsString('color:#ff0000;');
|
||||
}
|
||||
public function testItRendersCustomSetColors(): void {
|
||||
$this->parsedHeading['attrs']['style']['color']['background'] = '#000000';
|
||||
$this->parsedHeading['attrs']['style']['color']['text'] = '#ff0000';
|
||||
$rendered = $this->headingRenderer->render( '<h1>This is Heading 1</h1>', $this->parsedHeading, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'background-color:#000000' );
|
||||
verify( $rendered )->stringContainsString( 'color:#ff0000;' );
|
||||
}
|
||||
|
||||
public function testItReplacesFluidFontSizeInContent(): void {
|
||||
$rendered = $this->headingRenderer->render('<h1 style="font-size:clamp(10px, 20px, 24px)">This is Heading 1</h1>', $this->parsedHeading, $this->settingsController);
|
||||
verify($rendered)->stringContainsString('font-size:24px');
|
||||
}
|
||||
public function testItReplacesFluidFontSizeInContent(): void {
|
||||
$rendered = $this->headingRenderer->render( '<h1 style="font-size:clamp(10px, 20px, 24px)">This is Heading 1</h1>', $this->parsedHeading, $this->settingsController );
|
||||
verify( $rendered )->stringContainsString( 'font-size:24px' );
|
||||
}
|
||||
}
|
||||
|
@@ -6,135 +6,145 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Image_Test extends \MailPoetTest {
|
||||
/** @var Image */
|
||||
private $imageRenderer;
|
||||
/** @var Image */
|
||||
private $imageRenderer;
|
||||
|
||||
private $imageContent = '
|
||||
private $imageContent = '
|
||||
<figure class="wp-block-image alignleft size-full is-style-default">
|
||||
<img src="https://test.com/wp-content/uploads/2023/05/image.jpg" alt="" style="" srcset="https://test.com/wp-content/uploads/2023/05/image.jpg 1000w"/>
|
||||
</figure>
|
||||
';
|
||||
|
||||
/** @var array */
|
||||
private $parsedImage = [
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => [
|
||||
'align' => 'left',
|
||||
'id' => 1,
|
||||
'scale' => 'cover',
|
||||
'sizeSlug' => 'full',
|
||||
'linkDestination' => 'none',
|
||||
'className' => 'is-style-default',
|
||||
'width' => '640px',
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '',
|
||||
'innerContent' => [],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedImage = array(
|
||||
'blockName' => 'core/image',
|
||||
'attrs' => array(
|
||||
'align' => 'left',
|
||||
'id' => 1,
|
||||
'scale' => 'cover',
|
||||
'sizeSlug' => 'full',
|
||||
'linkDestination' => 'none',
|
||||
'className' => 'is-style-default',
|
||||
'width' => '640px',
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->imageRenderer = new Image();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->imageRenderer = new Image();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersMandatoryImageStyles(): void {
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['innerHTML'] = $this->imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
public function testItRendersMandatoryImageStyles(): void {
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['innerHTML'] = $this->imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
|
||||
$rendered = $this->imageRenderer->render($this->imageContent, $parsedImage, $this->settingsController);
|
||||
$this->assertStringNotContainsString('<figure', $rendered);
|
||||
$this->assertStringNotContainsString('<figcaption', $rendered);
|
||||
$this->assertStringNotContainsString('</figure>', $rendered);
|
||||
$this->assertStringNotContainsString('</figcaption>', $rendered);
|
||||
$this->assertStringNotContainsString('srcset', $rendered);
|
||||
$this->assertStringContainsString('width="640"', $rendered);
|
||||
$this->assertStringContainsString('width:640px;', $rendered);
|
||||
$this->assertStringContainsString('<img ', $rendered);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $this->imageContent, $parsedImage, $this->settingsController );
|
||||
$this->assertStringNotContainsString( '<figure', $rendered );
|
||||
$this->assertStringNotContainsString( '<figcaption', $rendered );
|
||||
$this->assertStringNotContainsString( '</figure>', $rendered );
|
||||
$this->assertStringNotContainsString( '</figcaption>', $rendered );
|
||||
$this->assertStringNotContainsString( 'srcset', $rendered );
|
||||
$this->assertStringContainsString( 'width="640"', $rendered );
|
||||
$this->assertStringContainsString( 'width:640px;', $rendered );
|
||||
$this->assertStringContainsString( '<img ', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersBorderRadiusStyle(): void {
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['className'] = 'is-style-rounded';
|
||||
$parsedImage['innerHTML'] = $this->imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
public function testItRendersBorderRadiusStyle(): void {
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['className'] = 'is-style-rounded';
|
||||
$parsedImage['innerHTML'] = $this->imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
|
||||
$rendered = $this->imageRenderer->render($this->imageContent, $parsedImage, $this->settingsController);
|
||||
$this->assertStringNotContainsString('<figure', $rendered);
|
||||
$this->assertStringNotContainsString('<figcaption', $rendered);
|
||||
$this->assertStringNotContainsString('</figure>', $rendered);
|
||||
$this->assertStringNotContainsString('</figcaption>', $rendered);
|
||||
$this->assertStringContainsString('width="640"', $rendered);
|
||||
$this->assertStringContainsString('width:640px;', $rendered);
|
||||
$this->assertStringContainsString('<img ', $rendered);
|
||||
$this->assertStringContainsString('border-radius: 9999px;', $rendered);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $this->imageContent, $parsedImage, $this->settingsController );
|
||||
$this->assertStringNotContainsString( '<figure', $rendered );
|
||||
$this->assertStringNotContainsString( '<figcaption', $rendered );
|
||||
$this->assertStringNotContainsString( '</figure>', $rendered );
|
||||
$this->assertStringNotContainsString( '</figcaption>', $rendered );
|
||||
$this->assertStringContainsString( 'width="640"', $rendered );
|
||||
$this->assertStringContainsString( 'width:640px;', $rendered );
|
||||
$this->assertStringContainsString( '<img ', $rendered );
|
||||
$this->assertStringContainsString( 'border-radius: 9999px;', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersCaption(): void {
|
||||
$imageContent = str_replace('</figure>', '<figcaption class="wp-element-caption">Caption</figcaption></figure>', $this->imageContent);
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['innerHTML'] = $imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
public function testItRendersCaption(): void {
|
||||
$imageContent = str_replace( '</figure>', '<figcaption class="wp-element-caption">Caption</figcaption></figure>', $this->imageContent );
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['innerHTML'] = $imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
|
||||
$rendered = $this->imageRenderer->render($imageContent, $parsedImage, $this->settingsController);
|
||||
$this->assertStringContainsString('>Caption</span>', $rendered);
|
||||
$this->assertStringContainsString('text-align:center;', $rendered);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $imageContent, $parsedImage, $this->settingsController );
|
||||
$this->assertStringContainsString( '>Caption</span>', $rendered );
|
||||
$this->assertStringContainsString( 'text-align:center;', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersImageAlignment(): void {
|
||||
$imageContent = str_replace('style=""', 'style="width:400px;height:300px;"', $this->imageContent);
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['align'] = 'center';
|
||||
$parsedImage['attrs']['width'] = '400px';
|
||||
$parsedImage['innerHTML'] = $imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
public function testItRendersImageAlignment(): void {
|
||||
$imageContent = str_replace( 'style=""', 'style="width:400px;height:300px;"', $this->imageContent );
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['align'] = 'center';
|
||||
$parsedImage['attrs']['width'] = '400px';
|
||||
$parsedImage['innerHTML'] = $imageContent; // To avoid repetition of the image content in the test we need to add it to the parsed block
|
||||
|
||||
$rendered = $this->imageRenderer->render($imageContent, $parsedImage, $this->settingsController);
|
||||
$this->assertStringContainsString('align="center"', $rendered);
|
||||
$this->assertStringContainsString('width="400"', $rendered);
|
||||
$this->assertStringContainsString('height="300"', $rendered);
|
||||
$this->assertStringContainsString('height:300px;', $rendered);
|
||||
$this->assertStringContainsString('width:400px;', $rendered);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $imageContent, $parsedImage, $this->settingsController );
|
||||
$this->assertStringContainsString( 'align="center"', $rendered );
|
||||
$this->assertStringContainsString( 'width="400"', $rendered );
|
||||
$this->assertStringContainsString( 'height="300"', $rendered );
|
||||
$this->assertStringContainsString( 'height:300px;', $rendered );
|
||||
$this->assertStringContainsString( 'width:400px;', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersBorders(): void {
|
||||
$imageContent = $this->imageContent;
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['style']['border'] = [
|
||||
'width' => '10px',
|
||||
'color' => '#000001',
|
||||
'radius' => '20px',
|
||||
];
|
||||
public function testItRendersBorders(): void {
|
||||
$imageContent = $this->imageContent;
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['style']['border'] = array(
|
||||
'width' => '10px',
|
||||
'color' => '#000001',
|
||||
'radius' => '20px',
|
||||
);
|
||||
|
||||
$rendered = $this->imageRenderer->render($imageContent, $parsedImage, $this->settingsController);
|
||||
$html = new \WP_HTML_Tag_Processor($rendered);
|
||||
// Border is rendered on the wrapping table cell
|
||||
$html->next_tag(['tag_name' => 'td', 'class_name' => 'email-image-cell']);
|
||||
$tableCellStyle = $html->get_attribute('style');
|
||||
$this->assertStringContainsString('border-color:#000001', $tableCellStyle);
|
||||
$this->assertStringContainsString('border-radius:20px', $tableCellStyle);
|
||||
$this->assertStringContainsString('border-style:solid;', $tableCellStyle);
|
||||
$html->next_tag(['tag_name' => 'img']);
|
||||
$imgStyle = $html->get_attribute('style');
|
||||
$this->assertStringNotContainsString('border', $imgStyle);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $imageContent, $parsedImage, $this->settingsController );
|
||||
$html = new \WP_HTML_Tag_Processor( $rendered );
|
||||
// Border is rendered on the wrapping table cell
|
||||
$html->next_tag(
|
||||
array(
|
||||
'tag_name' => 'td',
|
||||
'class_name' => 'email-image-cell',
|
||||
)
|
||||
);
|
||||
$tableCellStyle = $html->get_attribute( 'style' );
|
||||
$this->assertStringContainsString( 'border-color:#000001', $tableCellStyle );
|
||||
$this->assertStringContainsString( 'border-radius:20px', $tableCellStyle );
|
||||
$this->assertStringContainsString( 'border-style:solid;', $tableCellStyle );
|
||||
$html->next_tag( array( 'tag_name' => 'img' ) );
|
||||
$imgStyle = $html->get_attribute( 'style' );
|
||||
$this->assertStringNotContainsString( 'border', $imgStyle );
|
||||
}
|
||||
|
||||
public function testItMovesBorderRelatedClasses(): void {
|
||||
$imageContent = str_replace('<img', '<img class="custom-class has-border-color has-border-red-color"',$this->imageContent);
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['style']['border'] = [
|
||||
'width' => '10px',
|
||||
'color' => '#000001',
|
||||
'radius' => '20px',
|
||||
];
|
||||
public function testItMovesBorderRelatedClasses(): void {
|
||||
$imageContent = str_replace( '<img', '<img class="custom-class has-border-color has-border-red-color"', $this->imageContent );
|
||||
$parsedImage = $this->parsedImage;
|
||||
$parsedImage['attrs']['style']['border'] = array(
|
||||
'width' => '10px',
|
||||
'color' => '#000001',
|
||||
'radius' => '20px',
|
||||
);
|
||||
|
||||
$rendered = $this->imageRenderer->render($imageContent, $parsedImage, $this->settingsController);
|
||||
$html = new \WP_HTML_Tag_Processor($rendered);
|
||||
// Border is rendered on the wrapping table cell and the border classes are moved to the wrapping table cell
|
||||
$html->next_tag(['tag_name' => 'td', 'class_name' => 'email-image-cell']);
|
||||
$tableCellClass = $html->get_attribute('class');
|
||||
$this->assertStringContainsString('has-border-red-color', $tableCellClass);
|
||||
$this->assertStringContainsString('has-border-color', $tableCellClass);
|
||||
$this->assertStringNotContainsString('custom-class', $tableCellClass);
|
||||
}
|
||||
$rendered = $this->imageRenderer->render( $imageContent, $parsedImage, $this->settingsController );
|
||||
$html = new \WP_HTML_Tag_Processor( $rendered );
|
||||
// Border is rendered on the wrapping table cell and the border classes are moved to the wrapping table cell
|
||||
$html->next_tag(
|
||||
array(
|
||||
'tag_name' => 'td',
|
||||
'class_name' => 'email-image-cell',
|
||||
)
|
||||
);
|
||||
$tableCellClass = $html->get_attribute( 'class' );
|
||||
$this->assertStringContainsString( 'has-border-red-color', $tableCellClass );
|
||||
$this->assertStringContainsString( 'has-border-color', $tableCellClass );
|
||||
$this->assertStringNotContainsString( 'custom-class', $tableCellClass );
|
||||
}
|
||||
}
|
||||
|
@@ -6,74 +6,74 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class List_Block_Test extends \MailPoetTest {
|
||||
/** @var List_Block */
|
||||
private $listRenderer;
|
||||
/** @var List_Block */
|
||||
private $listRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedList = [
|
||||
'blockName' => 'core/list',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [
|
||||
0 => [
|
||||
'blockName' => 'core/list-item',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<li>Item 1</li>',
|
||||
'innerContent' => [
|
||||
0 => '<li>Item 1</li>',
|
||||
],
|
||||
],
|
||||
1 => [
|
||||
'blockName' => 'core/list-item',
|
||||
'attrs' => [],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<li>Item 2</li>',
|
||||
'innerContent' => [
|
||||
0 => '<li>Item 2</li>',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerHTML' => '<ul></ul>',
|
||||
'innerContent' => [
|
||||
0 => '<ul>',
|
||||
1 => null,
|
||||
2 => '</ul>',
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedList = array(
|
||||
'blockName' => 'core/list',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(
|
||||
0 => array(
|
||||
'blockName' => 'core/list-item',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<li>Item 1</li>',
|
||||
'innerContent' => array(
|
||||
0 => '<li>Item 1</li>',
|
||||
),
|
||||
),
|
||||
1 => array(
|
||||
'blockName' => 'core/list-item',
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<li>Item 2</li>',
|
||||
'innerContent' => array(
|
||||
0 => '<li>Item 2</li>',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerHTML' => '<ul></ul>',
|
||||
'innerContent' => array(
|
||||
0 => '<ul>',
|
||||
1 => null,
|
||||
2 => '</ul>',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->listRenderer = new List_Block();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->listRenderer = new List_Block();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersListContent(): void {
|
||||
$rendered = $this->listRenderer->render('<ul><li>Item 1</li><li>Item 2</li></ul>', $this->parsedList, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('Item 1', $rendered);
|
||||
$this->assertStringContainsString('Item 2', $rendered);
|
||||
}
|
||||
public function testItRendersListContent(): void {
|
||||
$rendered = $this->listRenderer->render( '<ul><li>Item 1</li><li>Item 2</li></ul>', $this->parsedList, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'Item 1', $rendered );
|
||||
$this->assertStringContainsString( 'Item 2', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersFontSizeFromPreprocessor(): void {
|
||||
$parsedList = $this->parsedList;
|
||||
$parsedList['email_attrs'] = [
|
||||
'font-size' => '20px',
|
||||
];
|
||||
$rendered = $this->listRenderer->render('<ul><li>Item 1</li><li>Item 2</li></ul>', $parsedList, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('Item 1', $rendered);
|
||||
$this->assertStringContainsString('Item 2', $rendered);
|
||||
$this->assertStringContainsString('font-size:20px;', $rendered);
|
||||
}
|
||||
public function testItRendersFontSizeFromPreprocessor(): void {
|
||||
$parsedList = $this->parsedList;
|
||||
$parsedList['email_attrs'] = array(
|
||||
'font-size' => '20px',
|
||||
);
|
||||
$rendered = $this->listRenderer->render( '<ul><li>Item 1</li><li>Item 2</li></ul>', $parsedList, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'Item 1', $rendered );
|
||||
$this->assertStringContainsString( 'Item 2', $rendered );
|
||||
$this->assertStringContainsString( 'font-size:20px;', $rendered );
|
||||
}
|
||||
|
||||
public function testItPreservesCustomSetColors(): void {
|
||||
$parsedList = $this->parsedList;
|
||||
$rendered = $this->listRenderer->render('<ul style="color:#ff0000;background-color:#000000"><li>Item 1</li><li>Item 2</li></ul>', $parsedList, $this->settingsController);
|
||||
$this->checkValidHTML($rendered);
|
||||
$this->assertStringContainsString('color:#ff0000;', $rendered);
|
||||
$this->assertStringContainsString('background-color:#000000', $rendered);
|
||||
}
|
||||
public function testItPreservesCustomSetColors(): void {
|
||||
$parsedList = $this->parsedList;
|
||||
$rendered = $this->listRenderer->render( '<ul style="color:#ff0000;background-color:#000000"><li>Item 1</li><li>Item 2</li></ul>', $parsedList, $this->settingsController );
|
||||
$this->checkValidHTML( $rendered );
|
||||
$this->assertStringContainsString( 'color:#ff0000;', $rendered );
|
||||
$this->assertStringContainsString( 'background-color:#000000', $rendered );
|
||||
}
|
||||
}
|
||||
|
@@ -6,110 +6,110 @@ use MailPoet\EmailEditor\Engine\Email_Editor;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
|
||||
class Paragraph_Test extends \MailPoetTest {
|
||||
/** @var Text */
|
||||
private $paragraphRenderer;
|
||||
/** @var Text */
|
||||
private $paragraphRenderer;
|
||||
|
||||
/** @var array */
|
||||
private $parsedParagraph = [
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => [
|
||||
'style' => [
|
||||
'typography' => [
|
||||
'fontSize' => '16px',
|
||||
],
|
||||
],
|
||||
],
|
||||
'innerBlocks' => [],
|
||||
'innerHTML' => '<p>Lorem Ipsum</p>',
|
||||
'innerContent' => [
|
||||
0 => '<p>Lorem Ipsum</p>',
|
||||
],
|
||||
];
|
||||
/** @var array */
|
||||
private $parsedParagraph = array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'typography' => array(
|
||||
'fontSize' => '16px',
|
||||
),
|
||||
),
|
||||
),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '<p>Lorem Ipsum</p>',
|
||||
'innerContent' => array(
|
||||
0 => '<p>Lorem Ipsum</p>',
|
||||
),
|
||||
);
|
||||
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
/** @var Settings_Controller */
|
||||
private $settingsController;
|
||||
|
||||
public function _before() {
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->paragraphRenderer = new Text();
|
||||
$this->settingsController = $this->diContainer->get(Settings_Controller::class);
|
||||
}
|
||||
public function _before() {
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->paragraphRenderer = new Text();
|
||||
$this->settingsController = $this->diContainer->get( Settings_Controller::class );
|
||||
}
|
||||
|
||||
public function testItRendersContent(): void {
|
||||
$rendered = $this->paragraphRenderer->render('<p>Lorem Ipsum</p>', $this->parsedParagraph, $this->settingsController);
|
||||
$this->assertStringContainsString('width:100%', $rendered);
|
||||
$this->assertStringContainsString('Lorem Ipsum', $rendered);
|
||||
$this->assertStringContainsString('font-size:16px;', $rendered);
|
||||
$this->assertStringContainsString('text-align:left;', $rendered); // Check the default text-align
|
||||
$this->assertStringContainsString('align="left"', $rendered); // Check the default align
|
||||
}
|
||||
public function testItRendersContent(): void {
|
||||
$rendered = $this->paragraphRenderer->render( '<p>Lorem Ipsum</p>', $this->parsedParagraph, $this->settingsController );
|
||||
$this->assertStringContainsString( 'width:100%', $rendered );
|
||||
$this->assertStringContainsString( 'Lorem Ipsum', $rendered );
|
||||
$this->assertStringContainsString( 'font-size:16px;', $rendered );
|
||||
$this->assertStringContainsString( 'text-align:left;', $rendered ); // Check the default text-align
|
||||
$this->assertStringContainsString( 'align="left"', $rendered ); // Check the default align
|
||||
}
|
||||
|
||||
public function testItRendersContentWithPadding(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['top'] = '10px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['right'] = '20px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['bottom'] = '30px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['left'] = '40px';
|
||||
$parsedParagraph['attrs']['align'] = 'center';
|
||||
public function testItRendersContentWithPadding(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['top'] = '10px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['right'] = '20px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['bottom'] = '30px';
|
||||
$parsedParagraph['attrs']['style']['spacing']['padding']['left'] = '40px';
|
||||
$parsedParagraph['attrs']['align'] = 'center';
|
||||
|
||||
$rendered = $this->paragraphRenderer->render('<p>Lorem Ipsum</p>', $parsedParagraph, $this->settingsController);
|
||||
$this->assertStringContainsString('padding-top:10px;', $rendered);
|
||||
$this->assertStringContainsString('padding-right:20px;', $rendered);
|
||||
$this->assertStringContainsString('padding-bottom:30px;', $rendered);
|
||||
$this->assertStringContainsString('padding-left:40px;', $rendered);
|
||||
$this->assertStringContainsString('text-align:center;', $rendered);
|
||||
$this->assertStringContainsString('align="center"', $rendered);
|
||||
$this->assertStringContainsString('Lorem Ipsum', $rendered);
|
||||
}
|
||||
$rendered = $this->paragraphRenderer->render( '<p>Lorem Ipsum</p>', $parsedParagraph, $this->settingsController );
|
||||
$this->assertStringContainsString( 'padding-top:10px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-right:20px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-bottom:30px;', $rendered );
|
||||
$this->assertStringContainsString( 'padding-left:40px;', $rendered );
|
||||
$this->assertStringContainsString( 'text-align:center;', $rendered );
|
||||
$this->assertStringContainsString( 'align="center"', $rendered );
|
||||
$this->assertStringContainsString( 'Lorem Ipsum', $rendered );
|
||||
}
|
||||
|
||||
public function testItRendersBorders(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['border']['width'] = '10px';
|
||||
$parsedParagraph['attrs']['style']['border']['color'] = '#000001';
|
||||
$parsedParagraph['attrs']['style']['border']['radius'] = '20px';
|
||||
public function testItRendersBorders(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['border']['width'] = '10px';
|
||||
$parsedParagraph['attrs']['style']['border']['color'] = '#000001';
|
||||
$parsedParagraph['attrs']['style']['border']['radius'] = '20px';
|
||||
|
||||
$content = '<p class="has-border-color test-class has-red-border-color">Lorem Ipsum</p>';
|
||||
$parsedParagraph['innerHTML'] = $content;
|
||||
$parsedParagraph['innerContent'] = [$content];
|
||||
$content = '<p class="has-border-color test-class has-red-border-color">Lorem Ipsum</p>';
|
||||
$parsedParagraph['innerHTML'] = $content;
|
||||
$parsedParagraph['innerContent'] = array( $content );
|
||||
|
||||
$rendered = $this->paragraphRenderer->render($content, $parsedParagraph, $this->settingsController);
|
||||
$html = new \WP_HTML_Tag_Processor($rendered);
|
||||
$html->next_tag(['tag_name' => 'table']);
|
||||
$tableStyle = $html->get_attribute('style');
|
||||
// Table needs to have border-collapse: separate to make border-radius work
|
||||
$this->assertStringContainsString('border-collapse: separate', $tableStyle);
|
||||
$html->next_tag(['tag_name' => 'td']);
|
||||
$tableCellStyle = $html->get_attribute('style');
|
||||
// Border styles are applied to the table cell
|
||||
$this->assertStringContainsString('border-color:#000001', $tableCellStyle);
|
||||
$this->assertStringContainsString('border-radius:20px', $tableCellStyle);
|
||||
$this->assertStringContainsString('border-width:10px', $tableCellStyle);
|
||||
$tableCellClasses = $html->get_attribute('class');
|
||||
$this->assertStringContainsString('has-border-color test-class has-red-border-color', $tableCellClasses);
|
||||
$html->next_tag(['tag_name' => 'p']);
|
||||
// There are no border styles on the paragraph
|
||||
$paragraphStyle = $html->get_attribute('style');
|
||||
$this->assertStringNotContainsString('border', $paragraphStyle);
|
||||
}
|
||||
$rendered = $this->paragraphRenderer->render( $content, $parsedParagraph, $this->settingsController );
|
||||
$html = new \WP_HTML_Tag_Processor( $rendered );
|
||||
$html->next_tag( array( 'tag_name' => 'table' ) );
|
||||
$tableStyle = $html->get_attribute( 'style' );
|
||||
// Table needs to have border-collapse: separate to make border-radius work
|
||||
$this->assertStringContainsString( 'border-collapse: separate', $tableStyle );
|
||||
$html->next_tag( array( 'tag_name' => 'td' ) );
|
||||
$tableCellStyle = $html->get_attribute( 'style' );
|
||||
// Border styles are applied to the table cell
|
||||
$this->assertStringContainsString( 'border-color:#000001', $tableCellStyle );
|
||||
$this->assertStringContainsString( 'border-radius:20px', $tableCellStyle );
|
||||
$this->assertStringContainsString( 'border-width:10px', $tableCellStyle );
|
||||
$tableCellClasses = $html->get_attribute( 'class' );
|
||||
$this->assertStringContainsString( 'has-border-color test-class has-red-border-color', $tableCellClasses );
|
||||
$html->next_tag( array( 'tag_name' => 'p' ) );
|
||||
// There are no border styles on the paragraph
|
||||
$paragraphStyle = $html->get_attribute( 'style' );
|
||||
$this->assertStringNotContainsString( 'border', $paragraphStyle );
|
||||
}
|
||||
|
||||
public function testItConvertsBlockTypography(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['typography'] = [
|
||||
'textTransform' => 'uppercase',
|
||||
'letterSpacing' => '1px',
|
||||
'textDecoration' => 'underline',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => 'bold',
|
||||
'fontSize' => '20px',
|
||||
];
|
||||
public function testItConvertsBlockTypography(): void {
|
||||
$parsedParagraph = $this->parsedParagraph;
|
||||
$parsedParagraph['attrs']['style']['typography'] = array(
|
||||
'textTransform' => 'uppercase',
|
||||
'letterSpacing' => '1px',
|
||||
'textDecoration' => 'underline',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => 'bold',
|
||||
'fontSize' => '20px',
|
||||
);
|
||||
|
||||
$rendered = $this->paragraphRenderer->render('<p>Lorem Ipsum</p>', $parsedParagraph, $this->settingsController);
|
||||
$this->assertStringContainsString('text-transform:uppercase;', $rendered);
|
||||
$this->assertStringContainsString('letter-spacing:1px;', $rendered);
|
||||
$this->assertStringContainsString('text-decoration:underline;', $rendered);
|
||||
$this->assertStringContainsString('font-style:italic;', $rendered);
|
||||
$this->assertStringContainsString('font-weight:bold;', $rendered);
|
||||
$this->assertStringContainsString('font-size:20px;', $rendered);
|
||||
$this->assertStringContainsString('Lorem Ipsum', $rendered);
|
||||
}
|
||||
$rendered = $this->paragraphRenderer->render( '<p>Lorem Ipsum</p>', $parsedParagraph, $this->settingsController );
|
||||
$this->assertStringContainsString( 'text-transform:uppercase;', $rendered );
|
||||
$this->assertStringContainsString( 'letter-spacing:1px;', $rendered );
|
||||
$this->assertStringContainsString( 'text-decoration:underline;', $rendered );
|
||||
$this->assertStringContainsString( 'font-style:italic;', $rendered );
|
||||
$this->assertStringContainsString( 'font-weight:bold;', $rendered );
|
||||
$this->assertStringContainsString( 'font-size:20px;', $rendered );
|
||||
$this->assertStringContainsString( 'Lorem Ipsum', $rendered );
|
||||
}
|
||||
}
|
||||
|
@@ -7,72 +7,83 @@ use MailPoet\EmailEditor\Engine\Renderer\Renderer;
|
||||
use MailPoet\EmailEditor\Integrations\Core\Initializer;
|
||||
|
||||
class Renderer_Test extends \MailPoetTest {
|
||||
/** @var Renderer */
|
||||
private $renderer;
|
||||
/** @var Renderer */
|
||||
private $renderer;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->renderer = $this->diContainer->get(Renderer::class);
|
||||
$this->diContainer->get(Email_Editor::class)->initialize();
|
||||
$this->diContainer->get(Initializer::class)->initialize();
|
||||
}
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->renderer = $this->diContainer->get( Renderer::class );
|
||||
$this->diContainer->get( Email_Editor::class )->initialize();
|
||||
$this->diContainer->get( Initializer::class )->initialize();
|
||||
}
|
||||
|
||||
public function testItInlinesButtonDefaultStyles() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$buttonHtml = $this->extractBlockHtml($rendered['html'], 'wp-block-button', 'td');
|
||||
verify($buttonHtml)->stringContainsString('color: #fff');
|
||||
verify($buttonHtml)->stringContainsString('padding-bottom: .7em;');
|
||||
verify($buttonHtml)->stringContainsString('padding-left: 1.4em;');
|
||||
verify($buttonHtml)->stringContainsString('padding-right: 1.4em;');
|
||||
verify($buttonHtml)->stringContainsString('padding-top: .7em;');
|
||||
verify($buttonHtml)->stringContainsString('background-color: #32373c');
|
||||
}
|
||||
public function testItInlinesButtonDefaultStyles() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$buttonHtml = $this->extractBlockHtml( $rendered['html'], 'wp-block-button', 'td' );
|
||||
verify( $buttonHtml )->stringContainsString( 'color: #fff' );
|
||||
verify( $buttonHtml )->stringContainsString( 'padding-bottom: .7em;' );
|
||||
verify( $buttonHtml )->stringContainsString( 'padding-left: 1.4em;' );
|
||||
verify( $buttonHtml )->stringContainsString( 'padding-right: 1.4em;' );
|
||||
verify( $buttonHtml )->stringContainsString( 'padding-top: .7em;' );
|
||||
verify( $buttonHtml )->stringContainsString( 'background-color: #32373c' );
|
||||
}
|
||||
|
||||
public function testButtonDefaultStylesDontOverwriteUserSetStyles() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:button {"backgroundColor":"white","textColor":"vivid-cyan-blue"} --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$buttonHtml = $this->extractBlockHtml($rendered['html'], 'wp-block-button', 'td');
|
||||
verify($buttonHtml)->stringContainsString('color: #0693e3');
|
||||
verify($buttonHtml)->stringContainsString('background-color: #ffffff');
|
||||
}
|
||||
public function testButtonDefaultStylesDontOverwriteUserSetStyles() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:button {"backgroundColor":"white","textColor":"vivid-cyan-blue"} --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$buttonHtml = $this->extractBlockHtml( $rendered['html'], 'wp-block-button', 'td' );
|
||||
verify( $buttonHtml )->stringContainsString( 'color: #0693e3' );
|
||||
verify( $buttonHtml )->stringContainsString( 'background-color: #ffffff' );
|
||||
}
|
||||
|
||||
public function testItInlinesHeadingFontSize() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:heading {"level":1,"style":{"typography":{"fontSize":"large"}}} --><h1 class="wp-block-heading">Hello</h1><!-- /wp:heading -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$headingHtml = $this->extractBlockHtml($rendered['html'], 'wp-block-heading', 'h1');
|
||||
verify($headingHtml)->stringContainsString('font-size: 42px'); // large is 42px in theme.json
|
||||
}
|
||||
public function testItInlinesHeadingFontSize() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:heading {"level":1,"style":{"typography":{"fontSize":"large"}}} --><h1 class="wp-block-heading">Hello</h1><!-- /wp:heading -->',
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$headingHtml = $this->extractBlockHtml( $rendered['html'], 'wp-block-heading', 'h1' );
|
||||
verify( $headingHtml )->stringContainsString( 'font-size: 42px' ); // large is 42px in theme.json
|
||||
}
|
||||
|
||||
public function testItInlinesHeadingColors() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:heading {"level":1, "backgroundColor":"black", "textColor":"luminous-vivid-orange"} --><h1 class="wp-block-heading has-luminous-vivid-orange-color has-black-background-color">Hello</h1><!-- /wp:heading -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$headingWrapperStyle = $this->extractBlockStyle($rendered['html'], 'has-luminous-vivid-orange-color', 'td');
|
||||
verify($headingWrapperStyle)->stringContainsString('color: #ff6900'); // luminous-vivid-orange is #ff6900
|
||||
verify($headingWrapperStyle)->stringContainsString('background-color: #000'); // black is #000
|
||||
}
|
||||
public function testItInlinesHeadingColors() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:heading {"level":1, "backgroundColor":"black", "textColor":"luminous-vivid-orange"} --><h1 class="wp-block-heading has-luminous-vivid-orange-color has-black-background-color">Hello</h1><!-- /wp:heading -->',
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$headingWrapperStyle = $this->extractBlockStyle( $rendered['html'], 'has-luminous-vivid-orange-color', 'td' );
|
||||
verify( $headingWrapperStyle )->stringContainsString( 'color: #ff6900' ); // luminous-vivid-orange is #ff6900
|
||||
verify( $headingWrapperStyle )->stringContainsString( 'background-color: #000' ); // black is #000
|
||||
}
|
||||
|
||||
public function testItInlinesParagraphColors() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:paragraph {style":{"color":{"background":"black", "text":"luminous-vivid-orange"}}} --><p class="has-luminous-vivid-orange-color has-black-background-color">Hello</p><!-- /wp:paragraph -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$paragraphWrapperStyle = $this->extractBlockStyle($rendered['html'], 'has-luminous-vivid-orange-color', 'td');
|
||||
verify($paragraphWrapperStyle)->stringContainsString('color: #ff6900'); // luminous-vivid-orange is #ff6900
|
||||
verify($paragraphWrapperStyle)->stringContainsString('background-color: #000'); // black is #000
|
||||
}
|
||||
public function testItInlinesParagraphColors() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:paragraph {style":{"color":{"background":"black", "text":"luminous-vivid-orange"}}} --><p class="has-luminous-vivid-orange-color has-black-background-color">Hello</p><!-- /wp:paragraph -->',
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$paragraphWrapperStyle = $this->extractBlockStyle( $rendered['html'], 'has-luminous-vivid-orange-color', 'td' );
|
||||
verify( $paragraphWrapperStyle )->stringContainsString( 'color: #ff6900' ); // luminous-vivid-orange is #ff6900
|
||||
verify( $paragraphWrapperStyle )->stringContainsString( 'background-color: #000' ); // black is #000
|
||||
}
|
||||
|
||||
public function testItInlinesListColors() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:list {"backgroundColor":"black","textColor":"luminous-vivid-orange","style":{"elements":{"link":{"color":{"text":"var:preset|color|vivid-red"}}}}} -->
|
||||
public function testItInlinesListColors() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:list {"backgroundColor":"black","textColor":"luminous-vivid-orange","style":{"elements":{"link":{"color":{"text":"var:preset|color|vivid-red"}}}}} -->
|
||||
<ul class="has-black-background-color has-luminous-vivid-orange-color has-text-color has-background has-link-color"><!-- wp:list-item -->
|
||||
<li>Item 1</li>
|
||||
<!-- /wp:list-item -->
|
||||
@@ -81,62 +92,67 @@ class Renderer_Test extends \MailPoetTest {
|
||||
<li>Item 2</li>
|
||||
<!-- /wp:list-item --></ul>
|
||||
<!-- /wp:list -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$listStyle = $this->extractBlockStyle($rendered['html'], 'has-luminous-vivid-orange-color', 'ul');
|
||||
verify($listStyle)->stringContainsString('color: #ff6900'); // luminous-vivid-orange is #ff6900
|
||||
verify($listStyle)->stringContainsString('background-color: #000'); // black is #000
|
||||
}
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$listStyle = $this->extractBlockStyle( $rendered['html'], 'has-luminous-vivid-orange-color', 'ul' );
|
||||
verify( $listStyle )->stringContainsString( 'color: #ff6900' ); // luminous-vivid-orange is #ff6900
|
||||
verify( $listStyle )->stringContainsString( 'background-color: #000' ); // black is #000
|
||||
}
|
||||
|
||||
public function testItInlinesColumnsColors() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '<!-- wp:columns {"backgroundColor":"vivid-green-cyan", "textColor":"black"} -->
|
||||
public function testItInlinesColumnsColors() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '<!-- wp:columns {"backgroundColor":"vivid-green-cyan", "textColor":"black"} -->
|
||||
<div class="wp-block-columns has-black-background-color has-luminous-vivid-orange-color"><!-- wp:column --><!-- /wp:column --></div>
|
||||
<!-- /wp:columns -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$style = $this->extractBlockStyle($rendered['html'], 'wp-block-columns', 'table');
|
||||
verify($style)->stringContainsString('color: #ff6900'); // luminous-vivid-orange is #ff6900
|
||||
verify($style)->stringContainsString('background-color: #000'); // black is #000
|
||||
}
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$style = $this->extractBlockStyle( $rendered['html'], 'wp-block-columns', 'table' );
|
||||
verify( $style )->stringContainsString( 'color: #ff6900' ); // luminous-vivid-orange is #ff6900
|
||||
verify( $style )->stringContainsString( 'background-color: #000' ); // black is #000
|
||||
}
|
||||
|
||||
public function testItInlinesColumnColors() {
|
||||
$emailPost = $this->tester->createPost([
|
||||
'post_content' => '
|
||||
public function testItInlinesColumnColors() {
|
||||
$emailPost = $this->tester->createPost(
|
||||
array(
|
||||
'post_content' => '
|
||||
<!-- wp:column {"verticalAlignment":"stretch","backgroundColor":"black","textColor":"luminous-vivid-orange"} -->
|
||||
<div class="wp-block-column-test wp-block-column is-vertically-aligned-stretch has-luminous-vivid-orange-color has-black-background-color has-text-color has-background"></div>
|
||||
<!-- /wp:column -->',
|
||||
]);
|
||||
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||
$style = $this->extractBlockStyle($rendered['html'], 'wp-block-column-test', 'td');
|
||||
verify($style)->stringContainsString('color: #ff6900'); // luminous-vivid-orange is #ff6900
|
||||
verify($style)->stringContainsString('background-color: #000'); // black is #000
|
||||
}
|
||||
)
|
||||
);
|
||||
$rendered = $this->renderer->render( $emailPost, 'Subject', '', 'en' );
|
||||
$style = $this->extractBlockStyle( $rendered['html'], 'wp-block-column-test', 'td' );
|
||||
verify( $style )->stringContainsString( 'color: #ff6900' ); // luminous-vivid-orange is #ff6900
|
||||
verify( $style )->stringContainsString( 'background-color: #000' ); // black is #000
|
||||
}
|
||||
|
||||
private function extractBlockHtml(string $html, string $blockClass, string $tag): string {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML($html);
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$nodes = $xpath->query('//' . $tag . '[contains(@class, "' . $blockClass . '")]');
|
||||
$block = null;
|
||||
if (($nodes instanceof \DOMNodeList) && $nodes->length > 0) {
|
||||
$block = $nodes->item(0);
|
||||
}
|
||||
$this->assertInstanceOf(\DOMElement::class, $block);
|
||||
$this->assertInstanceOf(\DOMDocument::class, $block->ownerDocument);
|
||||
return (string)$block->ownerDocument->saveHTML($block);
|
||||
}
|
||||
private function extractBlockHtml( string $html, string $blockClass, string $tag ): string {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML( $html );
|
||||
$xpath = new \DOMXPath( $doc );
|
||||
$nodes = $xpath->query( '//' . $tag . '[contains(@class, "' . $blockClass . '")]' );
|
||||
$block = null;
|
||||
if ( ( $nodes instanceof \DOMNodeList ) && $nodes->length > 0 ) {
|
||||
$block = $nodes->item( 0 );
|
||||
}
|
||||
$this->assertInstanceOf( \DOMElement::class, $block );
|
||||
$this->assertInstanceOf( \DOMDocument::class, $block->ownerDocument );
|
||||
return (string) $block->ownerDocument->saveHTML( $block );
|
||||
}
|
||||
|
||||
private function extractBlockStyle(string $html, string $blockClass, string $tag): string {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML($html);
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$nodes = $xpath->query('//' . $tag . '[contains(@class, "' . $blockClass . '")]');
|
||||
$block = null;
|
||||
if (($nodes instanceof \DOMNodeList) && $nodes->length > 0) {
|
||||
$block = $nodes->item(0);
|
||||
}
|
||||
$this->assertInstanceOf(\DOMElement::class, $block);
|
||||
return $block->getAttribute('style');
|
||||
}
|
||||
private function extractBlockStyle( string $html, string $blockClass, string $tag ): string {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML( $html );
|
||||
$xpath = new \DOMXPath( $doc );
|
||||
$nodes = $xpath->query( '//' . $tag . '[contains(@class, "' . $blockClass . '")]' );
|
||||
$block = null;
|
||||
if ( ( $nodes instanceof \DOMNodeList ) && $nodes->length > 0 ) {
|
||||
$block = $nodes->item( 0 );
|
||||
}
|
||||
$this->assertInstanceOf( \DOMElement::class, $block );
|
||||
return $block->getAttribute( 'style' );
|
||||
}
|
||||
}
|
||||
|
@@ -24,12 +24,12 @@ use MailPoet\EmailEditor\Integrations\Core\Initializer;
|
||||
use MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController;
|
||||
use MailPoet\EmailEditor\Utils\Cdn_Asset_Url;
|
||||
|
||||
if ((boolean)getenv('MULTISITE') === true) {
|
||||
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
||||
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
|
||||
$wpLoadFile = getenv('WP_ROOT_MULTISITE') . '/wp-load.php';
|
||||
if ( (bool) getenv( 'MULTISITE' ) === true ) {
|
||||
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
||||
$_SERVER['REQUEST_URI'] = '/' . getenv( 'WP_TEST_MULTISITE_SLUG' );
|
||||
$wpLoadFile = getenv( 'WP_ROOT_MULTISITE' ) . '/wp-load.php';
|
||||
} else {
|
||||
$wpLoadFile = getenv('WP_ROOT') . '/wp-load.php';
|
||||
$wpLoadFile = getenv( 'WP_ROOT' ) . '/wp-load.php';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,143 +37,209 @@ if ((boolean)getenv('MULTISITE') === true) {
|
||||
* Note that the following are override in the docker-compose file
|
||||
* WP_ROOT, WP_ROOT_MULTISITE, WP_TEST_MULTISITE_SLUG
|
||||
*/
|
||||
$console = new \Codeception\Lib\Console\Output([]);
|
||||
$console->writeln('Loading WP core... (' . $wpLoadFile . ')');
|
||||
require_once($wpLoadFile);
|
||||
$console = new \Codeception\Lib\Console\Output( array() );
|
||||
$console->writeln( 'Loading WP core... (' . $wpLoadFile . ')' );
|
||||
require_once $wpLoadFile;
|
||||
|
||||
/**
|
||||
* @property IntegrationTester $tester
|
||||
*/
|
||||
abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
|
||||
|
||||
public Container $diContainer;
|
||||
public Container $diContainer;
|
||||
|
||||
protected $backupGlobals = false;
|
||||
protected $backupStaticAttributes = false;
|
||||
protected $runTestInSeparateProcess = false;
|
||||
protected $preserveGlobalState = false;
|
||||
protected $backupGlobals = false;
|
||||
protected $backupStaticAttributes = false;
|
||||
protected $runTestInSeparateProcess = false;
|
||||
protected $preserveGlobalState = false;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->initContainer();
|
||||
parent::setUp();
|
||||
}
|
||||
public function setUp(): void {
|
||||
$this->initContainer();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function checkValidHTML(string $html): void {
|
||||
$dom = new \DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML($html);
|
||||
protected function checkValidHTML( string $html ): void {
|
||||
$dom = new \DOMDocument();
|
||||
libxml_use_internal_errors( true );
|
||||
$dom->loadHTML( $html );
|
||||
|
||||
// Check for errors during parsing
|
||||
$errors = libxml_get_errors();
|
||||
libxml_clear_errors();
|
||||
// Check for errors during parsing
|
||||
$errors = libxml_get_errors();
|
||||
libxml_clear_errors();
|
||||
|
||||
$this->assertEmpty($errors, 'HTML is not valid: ' . $html);
|
||||
}
|
||||
$this->assertEmpty( $errors, 'HTML is not valid: ' . $html );
|
||||
}
|
||||
|
||||
public function getServiceWithOverrides(string $id, array $overrides) {
|
||||
$instance = $this->diContainer->get($id);
|
||||
return Stub::copy($instance, $overrides);
|
||||
}
|
||||
public function getServiceWithOverrides( string $id, array $overrides ) {
|
||||
$instance = $this->diContainer->get( $id );
|
||||
return Stub::copy( $instance, $overrides );
|
||||
}
|
||||
|
||||
protected function initContainer(): void {
|
||||
$container = new Container();
|
||||
// Start: MailPoet plugin dependencies
|
||||
$container->set(Initializer::class, function() {
|
||||
return new Initializer();
|
||||
});
|
||||
$container->set(Cdn_Asset_Url::class, function() {
|
||||
return new Cdn_Asset_Url('http://localhost');
|
||||
});
|
||||
$container->set(Email_Api_Controller::class, function() {
|
||||
return new Email_Api_Controller();
|
||||
});
|
||||
$container->set(BlockTypesController::class, function() {
|
||||
return $this->createMock(BlockTypesController::class);
|
||||
});
|
||||
// End: MailPoet plugin dependencies
|
||||
$container->set(Utils::class, function() {
|
||||
return new Utils();
|
||||
});
|
||||
$container->set(Theme_Controller::class, function() {
|
||||
return new Theme_Controller();
|
||||
});
|
||||
$container->set(Settings_Controller::class, function ($container) {
|
||||
return new Settings_Controller($container->get(Theme_Controller::class));
|
||||
});
|
||||
$container->set(Settings_Controller::class, function ($container) {
|
||||
return new Settings_Controller($container->get(Theme_Controller::class));
|
||||
});
|
||||
$container->set(Templates::class, function ($container) {
|
||||
return new Templates($container->get(Utils::class));
|
||||
});
|
||||
$container->set(Template_Preview::class, function ($container) {
|
||||
return new Template_Preview(
|
||||
$container->get(Theme_Controller::class),
|
||||
$container->get(Settings_Controller::class),
|
||||
$container->get(Templates::class),
|
||||
);
|
||||
});
|
||||
$container->set(Patterns::class, function ($container) {
|
||||
return new Patterns(
|
||||
$container->get(Cdn_Asset_Url::class),
|
||||
);
|
||||
});
|
||||
$container->set(Cleanup_Preprocessor::class, function () {
|
||||
return new Cleanup_Preprocessor();
|
||||
});
|
||||
$container->set(Blocks_Width_Preprocessor::class, function () {
|
||||
return new Blocks_Width_Preprocessor();
|
||||
});
|
||||
$container->set(Typography_Preprocessor::class, function ($container) {
|
||||
return new Typography_Preprocessor($container->get(Settings_Controller::class));
|
||||
});
|
||||
$container->set(Spacing_Preprocessor::class, function () {
|
||||
return new Spacing_Preprocessor();
|
||||
});
|
||||
$container->set(Highlighting_Postprocessor::class, function () {
|
||||
return new Highlighting_Postprocessor();
|
||||
});
|
||||
$container->set(Variables_Postprocessor::class, function ($container) {
|
||||
return new Variables_Postprocessor($container->get(Theme_Controller::class));
|
||||
});
|
||||
$container->set(Process_Manager::class, function ($container) {
|
||||
return new Process_Manager(
|
||||
$container->get(Cleanup_Preprocessor::class),
|
||||
$container->get(Blocks_Width_Preprocessor::class),
|
||||
$container->get(Typography_Preprocessor::class),
|
||||
$container->get(Spacing_Preprocessor::class),
|
||||
$container->get(Highlighting_Postprocessor::class),
|
||||
$container->get(Variables_Postprocessor::class),
|
||||
);
|
||||
});
|
||||
$container->set(Blocks_Registry::class, function() {
|
||||
return new Blocks_Registry();
|
||||
});
|
||||
$container->set(Content_Renderer::class, function ($container) {
|
||||
return new Content_Renderer(
|
||||
$container->get(Process_Manager::class),
|
||||
$container->get(Blocks_Registry::class),
|
||||
$container->get(Settings_Controller::class),
|
||||
$container->get(Theme_Controller::class),
|
||||
);
|
||||
});
|
||||
$container->set(Renderer::class, function ($container) {
|
||||
return new Renderer(
|
||||
$container->get(Content_Renderer::class),
|
||||
$container->get(Templates::class),
|
||||
$container->get(Theme_Controller::class),
|
||||
);
|
||||
});
|
||||
$container->set(Email_Editor::class, function ($container) {
|
||||
return new Email_Editor(
|
||||
$container->get(Email_Api_Controller::class),
|
||||
$container->get(Templates::class),
|
||||
$container->get(Template_Preview::class),
|
||||
$container->get(Patterns::class),
|
||||
$container->get(Settings_Controller::class),
|
||||
);
|
||||
});
|
||||
protected function initContainer(): void {
|
||||
$container = new Container();
|
||||
// Start: MailPoet plugin dependencies
|
||||
$container->set(
|
||||
Initializer::class,
|
||||
function () {
|
||||
return new Initializer();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Cdn_Asset_Url::class,
|
||||
function () {
|
||||
return new Cdn_Asset_Url( 'http://localhost' );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Email_Api_Controller::class,
|
||||
function () {
|
||||
return new Email_Api_Controller();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
BlockTypesController::class,
|
||||
function () {
|
||||
return $this->createMock( BlockTypesController::class );
|
||||
}
|
||||
);
|
||||
// End: MailPoet plugin dependencies
|
||||
$container->set(
|
||||
Utils::class,
|
||||
function () {
|
||||
return new Utils();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Theme_Controller::class,
|
||||
function () {
|
||||
return new Theme_Controller();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Settings_Controller::class,
|
||||
function ( $container ) {
|
||||
return new Settings_Controller( $container->get( Theme_Controller::class ) );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Settings_Controller::class,
|
||||
function ( $container ) {
|
||||
return new Settings_Controller( $container->get( Theme_Controller::class ) );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Templates::class,
|
||||
function ( $container ) {
|
||||
return new Templates( $container->get( Utils::class ) );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Template_Preview::class,
|
||||
function ( $container ) {
|
||||
return new Template_Preview(
|
||||
$container->get( Theme_Controller::class ),
|
||||
$container->get( Settings_Controller::class ),
|
||||
$container->get( Templates::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Patterns::class,
|
||||
function ( $container ) {
|
||||
return new Patterns(
|
||||
$container->get( Cdn_Asset_Url::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Cleanup_Preprocessor::class,
|
||||
function () {
|
||||
return new Cleanup_Preprocessor();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Blocks_Width_Preprocessor::class,
|
||||
function () {
|
||||
return new Blocks_Width_Preprocessor();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Typography_Preprocessor::class,
|
||||
function ( $container ) {
|
||||
return new Typography_Preprocessor( $container->get( Settings_Controller::class ) );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Spacing_Preprocessor::class,
|
||||
function () {
|
||||
return new Spacing_Preprocessor();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Highlighting_Postprocessor::class,
|
||||
function () {
|
||||
return new Highlighting_Postprocessor();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Variables_Postprocessor::class,
|
||||
function ( $container ) {
|
||||
return new Variables_Postprocessor( $container->get( Theme_Controller::class ) );
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Process_Manager::class,
|
||||
function ( $container ) {
|
||||
return new Process_Manager(
|
||||
$container->get( Cleanup_Preprocessor::class ),
|
||||
$container->get( Blocks_Width_Preprocessor::class ),
|
||||
$container->get( Typography_Preprocessor::class ),
|
||||
$container->get( Spacing_Preprocessor::class ),
|
||||
$container->get( Highlighting_Postprocessor::class ),
|
||||
$container->get( Variables_Postprocessor::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Blocks_Registry::class,
|
||||
function () {
|
||||
return new Blocks_Registry();
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Content_Renderer::class,
|
||||
function ( $container ) {
|
||||
return new Content_Renderer(
|
||||
$container->get( Process_Manager::class ),
|
||||
$container->get( Blocks_Registry::class ),
|
||||
$container->get( Settings_Controller::class ),
|
||||
$container->get( Theme_Controller::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Renderer::class,
|
||||
function ( $container ) {
|
||||
return new Renderer(
|
||||
$container->get( Content_Renderer::class ),
|
||||
$container->get( Templates::class ),
|
||||
$container->get( Theme_Controller::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
$container->set(
|
||||
Email_Editor::class,
|
||||
function ( $container ) {
|
||||
return new Email_Editor(
|
||||
$container->get( Email_Api_Controller::class ),
|
||||
$container->get( Templates::class ),
|
||||
$container->get( Template_Preview::class ),
|
||||
$container->get( Patterns::class ),
|
||||
$container->get( Settings_Controller::class ),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$this->diContainer = $container;
|
||||
}
|
||||
$this->diContainer = $container;
|
||||
}
|
||||
}
|
||||
|
@@ -7,41 +7,47 @@ use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
class Container_Test extends TestCase {
|
||||
public function testSetAndGetService(): void {
|
||||
$container = new Container();
|
||||
public function testSetAndGetService(): void {
|
||||
$container = new Container();
|
||||
|
||||
$container->set('simple_service', function () {
|
||||
return new stdClass();
|
||||
});
|
||||
$container->set(
|
||||
'simple_service',
|
||||
function () {
|
||||
return new stdClass();
|
||||
}
|
||||
);
|
||||
|
||||
$service = $container->get('simple_service');
|
||||
$service = $container->get( 'simple_service' );
|
||||
|
||||
$this->assertInstanceOf(stdClass::class, $service);
|
||||
}
|
||||
$this->assertInstanceOf( stdClass::class, $service );
|
||||
}
|
||||
|
||||
public function testGetReturnsSameInstance(): void {
|
||||
$container = new Container();
|
||||
public function testGetReturnsSameInstance(): void {
|
||||
$container = new Container();
|
||||
|
||||
$container->set('singleton_service', function () {
|
||||
return new stdClass();
|
||||
});
|
||||
$container->set(
|
||||
'singleton_service',
|
||||
function () {
|
||||
return new stdClass();
|
||||
}
|
||||
);
|
||||
|
||||
// Retrieve the service twice
|
||||
$service1 = $container->get('singleton_service');
|
||||
$service2 = $container->get('singleton_service');
|
||||
// Retrieve the service twice
|
||||
$service1 = $container->get( 'singleton_service' );
|
||||
$service2 = $container->get( 'singleton_service' );
|
||||
|
||||
// Check that both instances are the same
|
||||
$this->assertSame($service1, $service2);
|
||||
}
|
||||
// Check that both instances are the same
|
||||
$this->assertSame( $service1, $service2 );
|
||||
}
|
||||
|
||||
public function testExceptionForNonExistingService(): void {
|
||||
// Create the container instance
|
||||
$container = new Container();
|
||||
public function testExceptionForNonExistingService(): void {
|
||||
// Create the container instance
|
||||
$container = new Container();
|
||||
|
||||
// Attempt to get a non-existing service should throw an exception
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('Service not found: non_existing_service');
|
||||
// Attempt to get a non-existing service should throw an exception
|
||||
$this->expectException( Exception::class );
|
||||
$this->expectExceptionMessage( 'Service not found: non_existing_service' );
|
||||
|
||||
$container->get('non_existing_service');
|
||||
}
|
||||
$container->get( 'non_existing_service' );
|
||||
}
|
||||
}
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
@@ -3,43 +3,43 @@
|
||||
namespace MailPoet\EmailEditor\Integrations\Utils;
|
||||
|
||||
class Dom_Document_Helper_Test extends \MailPoetUnitTest {
|
||||
public function testItFindsElement(): void {
|
||||
$html = '<div><p>Some text</p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper($html);
|
||||
$element = $domDocumentHelper->find_element('p');
|
||||
$empty = $domDocumentHelper->find_element('span');
|
||||
$this->assertInstanceOf(\DOMElement::class, $element);
|
||||
$this->assertEquals('p', $element->tagName);
|
||||
$this->assertNull($empty);
|
||||
}
|
||||
public function testItFindsElement(): void {
|
||||
$html = '<div><p>Some text</p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper( $html );
|
||||
$element = $domDocumentHelper->find_element( 'p' );
|
||||
$empty = $domDocumentHelper->find_element( 'span' );
|
||||
$this->assertInstanceOf( \DOMElement::class, $element );
|
||||
$this->assertEquals( 'p', $element->tagName );
|
||||
$this->assertNull( $empty );
|
||||
}
|
||||
|
||||
public function testItGetsAttributeValue(): void {
|
||||
$html = '<div><p class="some-class">Some text</p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper($html);
|
||||
$element = $domDocumentHelper->find_element('p');
|
||||
$this->assertInstanceOf(\DOMElement::class, $element);
|
||||
$this->assertEquals('some-class', $domDocumentHelper->get_attribute_value($element, 'class'));
|
||||
}
|
||||
public function testItGetsAttributeValue(): void {
|
||||
$html = '<div><p class="some-class">Some text</p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper( $html );
|
||||
$element = $domDocumentHelper->find_element( 'p' );
|
||||
$this->assertInstanceOf( \DOMElement::class, $element );
|
||||
$this->assertEquals( 'some-class', $domDocumentHelper->get_attribute_value( $element, 'class' ) );
|
||||
}
|
||||
|
||||
public function testItGetsOuterHtml(): void {
|
||||
$html = '<div><span>Some <strong>text</strong></span></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper($html);
|
||||
$element = $domDocumentHelper->find_element('span');
|
||||
$this->assertInstanceOf(\DOMElement::class, $element);
|
||||
$this->assertEquals('<span>Some <strong>text</strong></span>', $domDocumentHelper->get_outer_html($element));
|
||||
public function testItGetsOuterHtml(): void {
|
||||
$html = '<div><span>Some <strong>text</strong></span></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper( $html );
|
||||
$element = $domDocumentHelper->find_element( 'span' );
|
||||
$this->assertInstanceOf( \DOMElement::class, $element );
|
||||
$this->assertEquals( '<span>Some <strong>text</strong></span>', $domDocumentHelper->get_outer_html( $element ) );
|
||||
|
||||
// testings encoding of special characters
|
||||
$html = '<div><img src="https://test.com/DALL·E-A®∑oecasƒ-803x1024.jpg"></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper($html);
|
||||
$element = $domDocumentHelper->find_element('img');
|
||||
$this->assertInstanceOf(\DOMElement::class, $element);
|
||||
$this->assertEquals('<img src="https://test.com/DALL%C2%B7E-A%C2%AE%E2%88%91oecas%C6%92-803x1024.jpg">', $domDocumentHelper->get_outer_html($element));
|
||||
}
|
||||
// testings encoding of special characters
|
||||
$html = '<div><img src="https://test.com/DALL·E-A®∑oecasƒ-803x1024.jpg"></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper( $html );
|
||||
$element = $domDocumentHelper->find_element( 'img' );
|
||||
$this->assertInstanceOf( \DOMElement::class, $element );
|
||||
$this->assertEquals( '<img src="https://test.com/DALL%C2%B7E-A%C2%AE%E2%88%91oecas%C6%92-803x1024.jpg">', $domDocumentHelper->get_outer_html( $element ) );
|
||||
}
|
||||
|
||||
public function testItGetsAttributeValueByTagName(): void {
|
||||
$html = '<div><p class="some-class">Some text</p><p class="second-paragraph"></p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper($html);
|
||||
$this->assertEquals('some-class', $domDocumentHelper->get_attribute_value_by_tag_name('p', 'class'));
|
||||
$this->assertNull($domDocumentHelper->get_attribute_value_by_tag_name('span', 'class'));
|
||||
}
|
||||
public function testItGetsAttributeValueByTagName(): void {
|
||||
$html = '<div><p class="some-class">Some text</p><p class="second-paragraph"></p></div>';
|
||||
$domDocumentHelper = new Dom_Document_Helper( $html );
|
||||
$this->assertEquals( 'some-class', $domDocumentHelper->get_attribute_value_by_tag_name( 'p', 'class' ) );
|
||||
$this->assertNull( $domDocumentHelper->get_attribute_value_by_tag_name( 'span', 'class' ) );
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
$console = new \Codeception\Lib\Console\Output([]);
|
||||
$console = new \Codeception\Lib\Console\Output( array() );
|
||||
|
||||
if (!function_exists('esc_attr')) {
|
||||
function esc_attr($attr) {
|
||||
return $attr;
|
||||
}
|
||||
if ( ! function_exists( 'esc_attr' ) ) {
|
||||
function esc_attr( $attr ) {
|
||||
return $attr;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MailPoetUnitTest extends \Codeception\TestCase\Test {
|
||||
protected $runTestInSeparateProcess = false;
|
||||
protected $preserveGlobalState = false;
|
||||
protected $runTestInSeparateProcess = false;
|
||||
protected $preserveGlobalState = false;
|
||||
}
|
||||
|
||||
include '_stubs.php';
|
||||
require '_stubs.php';
|
||||
|
Reference in New Issue
Block a user