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:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user