Add a test for image alignment rendering [MAILPOET-1124]

This commit is contained in:
stoletniy
2017-10-09 09:37:31 +03:00
parent 26241afb86
commit 9d93f3ea95
2 changed files with 28 additions and 3 deletions

View File

@@ -20,11 +20,13 @@ class Image {
if(!empty($element['link'])) {
$image_template = '<a href="' . $element['link'] . '">' . $image_template . '</a>';
}
$align = 'center';
if(!empty($element['styles']['block']['textAlign']) && in_array($element['styles']['block']['textAlign'], array('left', 'right'))) {
$align = $element['styles']['block']['textAlign'];
}
$template = '
<tr>
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_bottom mailpoet_padded_side' : '') . '"
align="' . $element['styles']['block']['textAlign'] . '"
valign="top">
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_bottom mailpoet_padded_side' : '') . '" align="' . $align . '" valign="top">
' . $image_template . '
</td>
</tr>';

View File

@@ -133,6 +133,29 @@ class RendererTest extends \MailPoetTest {
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
}
function testItRendersAlignedImage() {
$newsletter = $this->newsletter['body'];
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
// default alignment (center)
unset($template['styles']['block']['textAlign']);
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 1));
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
$template['styles']['block']['textAlign'] = 'center';
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 1));
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
$template['styles']['block']['textAlign'] = 'something odd';
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 1));
expect($DOM('tr > td', 0)->attr('align'))->equals('center');
// left alignment
$template['styles']['block']['textAlign'] = 'left';
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 1));
expect($DOM('tr > td', 0)->attr('align'))->equals('left');
// right alignment
$template['styles']['block']['textAlign'] = 'right';
$DOM = $this->DOM_parser->parseStr(Image::render($template, $columnCount = 1));
expect($DOM('tr > td', 0)->attr('align'))->equals('right');
}
function testItDoesNotRenderImageWithoutSrc() {
$image = array(
'src' => '',