diff --git a/lib/Newsletter/Renderer/Blocks/Footer.php b/lib/Newsletter/Renderer/Blocks/Footer.php index e410480227..e44cac4b81 100644 --- a/lib/Newsletter/Renderer/Blocks/Footer.php +++ b/lib/Newsletter/Renderer/Blocks/Footer.php @@ -14,6 +14,9 @@ class Footer { $lineHeight = sprintf( '%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize'] ); + if (!is_string($element['text'])) { + throw new \RuntimeException('$element[\'text\'] should be a string.'); + } $dOMParser = new pQuery(); $DOM = $dOMParser->parseStr($element['text']); if (isset($element['styles']['link'])) { diff --git a/lib/Newsletter/Renderer/Blocks/Header.php b/lib/Newsletter/Renderer/Blocks/Header.php index 93d266ec9e..cb3eda3f95 100644 --- a/lib/Newsletter/Renderer/Blocks/Header.php +++ b/lib/Newsletter/Renderer/Blocks/Header.php @@ -14,6 +14,9 @@ class Header { $lineHeight = sprintf( '%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize'] ); + if (!is_string($element['text'])) { + throw new \RuntimeException('$element[\'text\'] should be a string.'); + } $dOMParser = new pQuery(); $DOM = $dOMParser->parseStr($element['text']); if (isset($element['styles']['link'])) { diff --git a/tests/unit/Newsletter/Renderer/Blocks/FooterTest.php b/tests/unit/Newsletter/Renderer/Blocks/FooterTest.php index 9d80e5c3ab..1298dd5d7b 100644 --- a/tests/unit/Newsletter/Renderer/Blocks/FooterTest.php +++ b/tests/unit/Newsletter/Renderer/Blocks/FooterTest.php @@ -52,4 +52,10 @@ class FooterTest extends \MailPoetUnitTest { $output = (new Footer)->render($this->block); expect($output)->stringContainsString('link'); } + + public function testItRaisesExceptionIfTextIsNotString() { + $this->block['text'] = ['some', 'array']; + $this->expectException('RuntimeException'); + (new Footer)->render($this->block); + } } diff --git a/tests/unit/Newsletter/Renderer/Blocks/HeaderTest.php b/tests/unit/Newsletter/Renderer/Blocks/HeaderTest.php index 79090b29f3..12e6051f31 100644 --- a/tests/unit/Newsletter/Renderer/Blocks/HeaderTest.php +++ b/tests/unit/Newsletter/Renderer/Blocks/HeaderTest.php @@ -52,4 +52,10 @@ class HeaderTest extends \MailPoetUnitTest { $output = (new Footer)->render($this->block); expect($output)->stringContainsString('link'); } + + public function testItRaisesExceptionIfTextIsNotString() { + $this->block['text'] = ['some', 'array']; + $this->expectException('RuntimeException'); + (new Header)->render($this->block); + } }