diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php index 8a8cc762e5..7445c4d8f1 100644 --- a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php +++ b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php @@ -16,6 +16,9 @@ class BlocksWidthPreprocessor implements Preprocessor { if ($alignment !== 'full') { $layoutWidth -= $this->parseNumberFromStringWithPixels($layoutStyles['padding']['left'] ?? '0px'); $layoutWidth -= $this->parseNumberFromStringWithPixels($layoutStyles['padding']['right'] ?? '0px'); + $borderWidth = $block['attrs']['style']['border']['width'] ?? '0px'; + $layoutWidth -= $this->parseNumberFromStringWithPixels($block['attrs']['style']['border']['left']['width'] ?? $borderWidth); + $layoutWidth -= $this->parseNumberFromStringWithPixels($block['attrs']['style']['border']['right']['width'] ?? $borderWidth); } $widthInput = $block['attrs']['width'] ?? '100%'; @@ -75,6 +78,9 @@ class BlocksWidthPreprocessor implements Preprocessor { $definedColumnWidth += $this->parseNumberFromStringWithPixels($column['attrs']['style']['spacing']['padding']['left'] ?? '0px'); $definedColumnWidth += $this->parseNumberFromStringWithPixels($column['attrs']['style']['spacing']['padding']['right'] ?? '0px'); } + $borderWidth = $column['attrs']['style']['border']['width'] ?? '0px'; + $definedColumnWidth += $this->parseNumberFromStringWithPixels($column['attrs']['style']['border']['left']['width'] ?? $borderWidth); + $definedColumnWidth += $this->parseNumberFromStringWithPixels($column['attrs']['style']['border']['right']['width'] ?? $borderWidth); } if ($columnsCount - $columnsCountWithDefinedWidth > 0) { diff --git a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php index 26269973ad..5a359e164c 100644 --- a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php +++ b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php @@ -362,4 +362,92 @@ class BlocksWidthPreprocessorTest extends \MailPoetUnitTest { verify($result[0]['innerBlocks'][0]['email_attrs']['width'])->equals('140px'); verify($result[0]['innerBlocks'][1]['email_attrs']['width'])->equals('500px'); } + + 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' => [], + ], + ], + ], + ], + ]]; + + $result = $this->preprocessor->preprocess($blocks, ['width' => '660px', 'padding' => ['left' => '10px', 'right' => '10px']]); + verify($result[0]['innerBlocks'])->arrayCount(3); + verify($result[0]['innerBlocks'][0]['email_attrs']['width'])->equals('140px'); + verify($result[0]['innerBlocks'][1]['email_attrs']['width'])->equals('180px'); + verify($result[0]['innerBlocks'][2]['email_attrs']['width'])->equals('220px'); + $imageBlock = $result[0]['innerBlocks'][1]['innerBlocks'][0]; + verify($imageBlock['email_attrs']['width'])->equals('180px'); + $imageBlock = $result[0]['innerBlocks'][2]['innerBlocks'][0]; + verify($imageBlock['email_attrs']['width'])->equals('180px'); + } }