Update Posts transformer to extract images by splitting the DOM tree

This commit is contained in:
Tautvidas Sipavičius
2017-07-28 14:36:12 +03:00
parent 60b3c066a5
commit 6de746162e
4 changed files with 105 additions and 12 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace MailPoet\Test\Newsletter\Editor;
use pQuery;
use MailPoet\Newsletter\Editor\StructureTransformer;
class StructureTransformerTest extends \MailPoetTest {
function _before() {
$this->transformer = new StructureTransformer();
}
function testItExtractsImagesAsImageBlocks() {
$html = '<p><i>italic</i><em>previous text<a href="#mylink"><img src="#myimage" /></a>next text</em><b>bolded</b></p>';
$blocks = $this->transformer->transform($html, false);
expect($blocks)->count(3);
expect($blocks[0]['type'])->equals('text');
expect($blocks[0]['text'])->equals('<p><i>italic</i><em>previous text</em></p>');
expect($blocks[1]['type'])->equals('image');
expect($blocks[1]['src'])->equals('#myimage');
expect($blocks[1]['link'])->equals('#mylink');
expect($blocks[2]['type'])->equals('text');
expect($blocks[2]['text'])->equals('<p><em>next text</em><b>bolded</b></p>');
}
}