Add Renderer class tests

[MAILPOET-6043]
This commit is contained in:
Pavel Dohnal
2024-11-14 15:39:24 +01:00
committed by Rostislav Wolný
parent 97729b21ae
commit d68e1c7960
2 changed files with 54 additions and 3 deletions

View File

@@ -41,7 +41,7 @@ class Templates {
*
* @var string $template_directory
*/
private string $template_directory;
private string $template_directory = __DIR__ . DIRECTORY_SEPARATOR;
/**
* The templates.
*
@@ -64,7 +64,6 @@ class Templates {
Utils $utils
) {
$this->utils = $utils;
$this->template_directory = __DIR__ . DIRECTORY_SEPARATOR;
}
/**

View File

@@ -10,6 +10,8 @@ namespace MailPoet\EmailEditor\Engine\Renderer;
use MailPoet\EmailEditor\Engine\Email_Editor;
use MailPoet\EmailEditor\Engine\Settings_Controller;
use MailPoet\EmailEditor\Engine\Templates\Templates;
use MailPoet\EmailEditor\Engine\Templates\Utils;
use MailPoet\EmailEditor\Engine\Theme_Controller;
/**
@@ -65,11 +67,39 @@ class Renderer_Test extends \MailPoetTest {
$theme_controller_mock->method( 'get_styles' )->willReturn( $styles );
$theme_controller_mock->method( 'get_layout_settings' )->willReturn( array( 'contentSize' => '660px' ) );
// We need to mock only the get_block_template_theme method and templates need to be initialized.
$templates_mock = $this->getMockBuilder( Templates::class )
->setConstructorArgs( array( $this->di_container->get( Utils::class ) ) )
->onlyMethods( array( 'get_block_template_theme' ) )
->getMock();
$templates_mock->initialize();
$templates_mock->method( 'get_block_template_theme' )->willReturn(
array(
'version' => 3,
'styles' => array(
'elements' => array(
'h1' => array(
'typography' => array(
'fontFamily' => 'lato test',
),
),
'heading' => array(
'color' => array(
'background' => 'pale-pink',
),
),
),
),
)
);
$this->renderer = $this->getServiceWithOverrides(
Renderer::class,
array(
'settings_controller' => $settings_controller_mock,
'theme_controller' => $theme_controller_mock,
'templates' => $templates_mock,
)
);
$this->email_post = $this->tester->create_post(
@@ -152,6 +182,28 @@ class Renderer_Test extends \MailPoetTest {
verify( $style )->stringContainsString( 'max-width: 660px;' );
}
/**
* Test it inlines block styles from template.
*/
public function testItRendersTemplateStyles(): void {
$email = $this->tester->create_post(
array(
'post_content' => '<!-- wp:heading {"level":1} --><h1 class="wp-block-heading">Hello!</h1><!-- /wp:heading -->',
)
);
$rendered = $this->renderer->render(
$email,
'Subject 1',
'Preheader content 2',
'en',
'noindex,nofollow'
);
verify( $rendered['html'] )->stringContainsString( 'Subject' );
verify( $rendered['html'] )->stringContainsString( 'font-family: lato test;' );
verify( $rendered['html'] )->stringContainsString( ' background-color: pale-pink;' );
}
/**
* Returns the value of the style attribute for the first tag that matches the query.
*