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,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.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user