From 4d1fbcd1572a5d1bd93daf2b5793640ec41d8cc6 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Thu, 2 Jul 2020 16:14:48 +0200 Subject: [PATCH] Add gradient rendering to columns on front end [MAILPOET-3005] --- lib/Form/Block/Columns.php | 7 +++++-- tests/unit/Form/Block/ColumnsTest.php | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Form/Block/Columns.php b/lib/Form/Block/Columns.php index d8c0986c86..cd8a850c40 100644 --- a/lib/Form/Block/Columns.php +++ b/lib/Form/Block/Columns.php @@ -12,9 +12,12 @@ class Columns { if (isset($params['text_color'])) { $styles[] = "color:{$params['text_color']};"; } - if (isset($params['background_color'])) { + if (isset($params['background_color']) && !isset($params['gradient'])) { $styles[] = "background-color:{$params['background_color']};"; } + if (isset($params['gradient'])) { + $styles[] = "background:{$params['gradient']};"; + } if (count($styles)) { return ' style="' . implode('', $styles) . '"'; } @@ -26,7 +29,7 @@ class Columns { if (!empty($params['vertical_alignment'])) { $classes[] = "mailpoet_vertically_align_{$params['vertical_alignment']}"; } - if (!empty($params['background_color'])) { + if (!empty($params['background_color']) || !empty($params['gradient'])) { $classes[] = "mailpoet_column_with_background"; } if (!empty($params['text_color'])) { diff --git a/tests/unit/Form/Block/ColumnsTest.php b/tests/unit/Form/Block/ColumnsTest.php index abde535b0b..76502255c5 100644 --- a/tests/unit/Form/Block/ColumnsTest.php +++ b/tests/unit/Form/Block/ColumnsTest.php @@ -48,7 +48,7 @@ class ColumnsTest extends \MailPoetUnitTest { expect($class->textContent)->contains('my-class'); } - public function testItShouldCustomBackground() { + public function testItShouldRenderCustomBackground() { $block = $this->block; $block['params']['background_color'] = '#ffffff'; $html = $this->columns->render($block, 'content'); @@ -59,7 +59,7 @@ class ColumnsTest extends \MailPoetUnitTest { expect($class->textContent)->contains('mailpoet_column_with_background'); } - public function testItShouldCustomTextColor() { + public function testItShouldRenderCustomTextColor() { $block = $this->block; $block['params']['text_color'] = '#ffffee'; $html = $this->columns->render($block, 'content'); @@ -67,4 +67,15 @@ class ColumnsTest extends \MailPoetUnitTest { $style = $this->htmlParser->getAttribute($columns, 'style'); expect($style->textContent)->contains('color:#ffffee;'); } + + public function testItShouldGradientBackground() { + $block = $this->block; + $block['params']['gradient'] = 'linear-gradient(red, yellow)'; + $html = $this->columns->render($block, 'content'); + $columns = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $style = $this->htmlParser->getAttribute($columns, 'style'); + expect($style->textContent)->contains('background:linear-gradient(red, yellow);'); + $class = $this->htmlParser->getAttribute($columns, 'class'); + expect($class->textContent)->contains('mailpoet_column_with_background'); + } }