diff --git a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php index 0b54536ed7..6c0193bf13 100644 --- a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php +++ b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php @@ -131,13 +131,14 @@ class Content_Renderer { } /** - * Render block + * Renders block + * Translates block's HTML to HTML suitable for email clients. The method is intended as a callback for 'render_block' filter. * * @param string $block_content Block content. * @param array $parsed_block Parsed block. * @return string */ - public function render_block( $block_content, $parsed_block ) { + public function render_block( string $block_content, array $parsed_block ): string { $renderer = $this->blocks_registry->get_block_renderer( $parsed_block['blockName'] ); if ( ! $renderer ) { $renderer = $this->blocks_registry->get_fallback_renderer(); @@ -213,7 +214,7 @@ class Content_Renderer { ); /* - *Layout CSS assumes the top level block will have a single DIV wrapper with children. Since our blocks use tables, + * Layout CSS assumes the top level block will have a single DIV wrapper with children. Since our blocks use tables, * we need to adjust this to look for children in the TD element. This may requires more advanced replacement but * this works in the current version of Gutenberg. * Example rule we're targetting: .wp-container-core-group-is-layout-1.wp-container-core-group-is-layout-1 > * diff --git a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php index 7211dd4a0a..7f23446c24 100644 --- a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php +++ b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php @@ -72,6 +72,60 @@ class Content_Renderer_Test extends \MailPoetTest { verify( $paragraph_styles )->stringContainsString( 'display: block' ); } + /** + * Test It Renders Block With Fallback Renderer + */ + public function testItRendersBlockWithFallbackRenderer(): void { + $fallback_renderer = $this->createMock( Block_Renderer::class ); + $fallback_renderer->expects( $this->once() )->method( 'render' ); + $blocks_registry = $this->createMock( Blocks_Registry::class ); + $blocks_registry->expects( $this->once() )->method( 'get_block_renderer' )->willReturn( null ); + $blocks_registry->expects( $this->once() )->method( 'get_fallback_renderer' )->willReturn( $fallback_renderer ); + $renderer = $this->getServiceWithOverrides( + Content_Renderer::class, + array( + 'blocks_registry' => $blocks_registry, + ) + ); + + $renderer->render_block( 'content', array( 'blockName' => 'block' ) ); + } + + /** + * Test It Renders Block With Block Renderer + */ + public function testItRendersBlockWithBlockRenderer(): void { + $renderer = $this->createMock( Block_Renderer::class ); + $blocks_registry = $this->createMock( Blocks_Registry::class ); + $blocks_registry->expects( $this->once() )->method( 'get_block_renderer' )->willReturn( $renderer ); + $blocks_registry->expects( $this->never() )->method( 'get_fallback_renderer' )->willReturn( null ); + $renderer = $this->getServiceWithOverrides( + Content_Renderer::class, + array( + 'blocks_registry' => $blocks_registry, + ) + ); + + $renderer->render_block( 'content', array( 'blockName' => 'block' ) ); + } + + /** + * Test It Renders Block When no Renderer available + */ + public function testItReturnsContentIfNoRendererAvailable(): void { + $blocks_registry = $this->createMock( Blocks_Registry::class ); + $blocks_registry->expects( $this->once() )->method( 'get_block_renderer' )->willReturn( null ); + $blocks_registry->expects( $this->once() )->method( 'get_fallback_renderer' )->willReturn( null ); + $renderer = $this->getServiceWithOverrides( + Content_Renderer::class, + array( + 'blocks_registry' => $blocks_registry, + ) + ); + + verify( $renderer->render_block( 'content', array( 'blockName' => 'block' ) ) )->equals( 'content' ); + } + /** * Get the value of the style attribute for a given tag in the HTML. *