Do not render images or social icons if image src is not defined
This commit is contained in:
@@ -6,6 +6,10 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||
|
||||
class Image {
|
||||
static function render($element, $column_count) {
|
||||
if(empty($element['src'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$element['width'] = (int)$element['width'];
|
||||
$element['height'] = (int)$element['height'];
|
||||
$element = self::adjustImageDimensions($element, $column_count);
|
||||
|
@@ -6,11 +6,17 @@ class Social {
|
||||
$icons_block = '';
|
||||
if(is_array($element['icons'])) {
|
||||
foreach($element['icons'] as $index => $icon) {
|
||||
if(empty($icon['image'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$icons_block .= '
|
||||
<a href="' . $icon['link'] . '" style="text-decoration:none!important;">
|
||||
<img src="' . $icon['image'] . '" width="' . (int)$icon['width'] . '" height="' . (int)$icon['height'] . '" style="width:' . $icon['width'] . ';height:' . $icon['width'] . ';-ms-interpolation-mode:bicubic;border:0;display:inline;outline:none;" alt="' . $icon['iconType'] . '">
|
||||
</a>';
|
||||
}
|
||||
}
|
||||
if(!empty($icons_block)) {
|
||||
$template = '
|
||||
<tr>
|
||||
<td class="mailpoet_padded_side mailpoet_padded_bottom" valign="top" align="center">
|
||||
|
@@ -150,6 +150,18 @@ class NewsletterRendererTest extends MailPoetTest {
|
||||
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
|
||||
}
|
||||
|
||||
function testItDoesNotRenderImageWithoutSrc() {
|
||||
$image = array(
|
||||
'src' => '',
|
||||
'width' => '100',
|
||||
'height' => '200',
|
||||
'link' => '',
|
||||
'alt' => 'some test alt text'
|
||||
);
|
||||
$rendered_image = Image::render($image, $columnCount = 1);
|
||||
expect($rendered_image)->equals('');
|
||||
}
|
||||
|
||||
function testItRendersImageWithLink() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||
@@ -306,6 +318,20 @@ class NewsletterRendererTest extends MailPoetTest {
|
||||
expect(count($DOM('a > img')))->equals(10);
|
||||
}
|
||||
|
||||
function testItDoesNotRenderSocialIconsWithoutImageSrc() {
|
||||
$block = array(
|
||||
'icons' => array(
|
||||
'image' => '',
|
||||
'width' => '100',
|
||||
'height' => '100',
|
||||
'link' => '',
|
||||
'iconType' => 'custom',
|
||||
)
|
||||
);
|
||||
$rendered_block = Social::render($block, $columnCount = 1);
|
||||
expect($rendered_block)->equals('');
|
||||
}
|
||||
|
||||
function testItRendersFooter() {
|
||||
$newsletter = $this->newsletter['body'];
|
||||
$template = $newsletter['content']['blocks'][3]['blocks'][0]['blocks'][0];
|
||||
|
Reference in New Issue
Block a user