Add a test for image alignment rendering [MAILPOET-1124]
This commit is contained in:
@@ -20,11 +20,13 @@ class Image {
|
|||||||
if(!empty($element['link'])) {
|
if(!empty($element['link'])) {
|
||||||
$image_template = '<a href="' . $element['link'] . '">' . $image_template . '</a>';
|
$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 = '
|
$template = '
|
||||||
<tr>
|
<tr>
|
||||||
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_bottom mailpoet_padded_side' : '') . '"
|
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_bottom mailpoet_padded_side' : '') . '" align="' . $align . '" valign="top">
|
||||||
align="' . $element['styles']['block']['textAlign'] . '"
|
|
||||||
valign="top">
|
|
||||||
' . $image_template . '
|
' . $image_template . '
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
@@ -133,6 +133,29 @@ class RendererTest extends \MailPoetTest {
|
|||||||
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
|
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() {
|
function testItDoesNotRenderImageWithoutSrc() {
|
||||||
$image = array(
|
$image = array(
|
||||||
'src' => '',
|
'src' => '',
|
||||||
|
Reference in New Issue
Block a user