Add test for image renderer
[MAILPOET-2086]
This commit is contained in:
committed by
M. Shull
parent
48a6a842da
commit
9a2101f13f
@@ -31,11 +31,10 @@ class Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$image_template = '
|
$image_template = '
|
||||||
<img src="' . EHelper::escapeHtmlLinkAttr($element['src']) . '"
|
<img src="' . EHelper::escapeHtmlLinkAttr($element['src']) . '" width="' . EHelper::escapeHtmlAttr($element['width']) . '" alt="' . EHelper::escapeHtmlAttr($element['alt']) . '"' . $style . '/>
|
||||||
width="' . EHelper::escapeHtmlAttr($element['width']) . '" alt="' . EHelper::escapeHtmlAttr($element['alt']) . '"' . $style . '/>
|
|
||||||
';
|
';
|
||||||
if (!empty($element['link'])) {
|
if (!empty($element['link'])) {
|
||||||
$image_template = '<a href="' . EHelper::escapeHtmlLinkAttr($element['link']) . '">' . $image_template . '</a>';
|
$image_template = '<a href="' . EHelper::escapeHtmlLinkAttr($element['link']) . '">' . trim($image_template) . '</a>';
|
||||||
}
|
}
|
||||||
$align = 'center';
|
$align = 'center';
|
||||||
if (!empty($element['styles']['block']['textAlign']) && in_array($element['styles']['block']['textAlign'], ['left', 'right'])) {
|
if (!empty($element['styles']['block']['textAlign']) && in_array($element['styles']['block']['textAlign'], ['left', 'right'])) {
|
||||||
@@ -45,7 +44,7 @@ class Image {
|
|||||||
$template = '
|
$template = '
|
||||||
<tr>
|
<tr>
|
||||||
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_vertical mailpoet_padded_side' : '') . '" align="' . EHelper::escapeHtmlAttr($align) . '" valign="top">
|
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_vertical mailpoet_padded_side' : '') . '" align="' . EHelper::escapeHtmlAttr($align) . '" valign="top">
|
||||||
' . $image_template . '
|
' . trim($image_template) . '
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
return $template;
|
return $template;
|
||||||
|
43
tests/unit/Newsletter/Renderer/Blocks/ImageTest.php
Normal file
43
tests/unit/Newsletter/Renderer/Blocks/ImageTest.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Newsletter\Renderer\Blocks;
|
||||||
|
|
||||||
|
class ImageTest extends \MailPoetUnitTest {
|
||||||
|
|
||||||
|
private $block = [
|
||||||
|
'type' => 'image',
|
||||||
|
'link' => 'http://example.com',
|
||||||
|
'src' => 'http://mailpoet.localhost/image.jpg',
|
||||||
|
'alt' => 'Alt text',
|
||||||
|
'fullWidth' => false,
|
||||||
|
'width' => '310.015625px',
|
||||||
|
'height' => '390px',
|
||||||
|
'styles' => [
|
||||||
|
'block' => [
|
||||||
|
'textAlign' => 'center',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
function testItRendersCorrectly() {
|
||||||
|
$output = Image::render($this->block, 200);
|
||||||
|
$expected_result = '
|
||||||
|
<tr>
|
||||||
|
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top">
|
||||||
|
<a href="http://example.com"><img src="http://mailpoet.localhost/image.jpg" width="160" alt="Alt text"/></a>
|
||||||
|
</td>
|
||||||
|
</tr>';
|
||||||
|
expect($output)->equals($expected_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItRendersWithoutLink() {
|
||||||
|
$this->block['link'] = null;
|
||||||
|
$output = Image::render($this->block, 200);
|
||||||
|
$expected_result = '
|
||||||
|
<tr>
|
||||||
|
<td class="mailpoet_image mailpoet_padded_vertical mailpoet_padded_side" align="center" valign="top">
|
||||||
|
<img src="http://mailpoet.localhost/image.jpg" width="160" alt="Alt text"/>
|
||||||
|
</td>
|
||||||
|
</tr>';
|
||||||
|
expect($output)->equals($expected_result);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user