Commit 169385aa authored by efalcy's avatar efalcy Committed by Ghislain Loas
Browse files

hotline#91113 : fix newsletter image articles display

parent 7e7ca8fd
Pipeline #6868 passed with stage
in 36 minutes and 11 seconds
- ticket #91113 : Lettre d'information : correction de l'affichage des images d'articles.
\ No newline at end of file
......@@ -41,8 +41,8 @@ class Class_Article_MailRenderer {
return '';
return '<div style="padding:5px">' .
'<h1>' . $article->getLabel() . '</h1>' .
'<div>' . $article->getFullContent() . '</div>' .
'<h1>' . Class_CmsUrlTransformer::transformLinksToAbsoluteUrl($article->getLabel()). '</h1>' .
'<div>' . Class_CmsUrlTransformer::transformLinksToAbsoluteUrl($article->getFullContent()) . '</div>' .
'<div style="clear:both"></div>'.
'</div>';
}
......
......@@ -46,6 +46,18 @@ class Class_CmsUrlTransformer {
: $content;
}
public function transformLinksToAbsoluteUrl($content) {
preg_match_all('/< *(img|a)[^>]*(src|href) *= *["\']?(\/[^"\']*)/i',
$content,
$matches);
foreach ($matches[3] as $match)
$content = preg_replace( "@(href|src)=('|\")" . $match . "@i",
"$1=$2" . Class_Url::absolute($match), $content);
return $content;
}
public function forSaving($content) {
return $this->imgUrlAbsoluteToRelative($content);
......
......@@ -841,8 +841,8 @@ class Admin_NewsletterControllerSendActionWithCommandFailureTest extends Admin_N
class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterControllerTestCase {
public function setUp() {
parent::setUp();
parent::setUp();
$marcus = $this->fixture('Class_Users', ['id' => 345,
'login' => 'mmiller',
'password' => 'pass',
......@@ -882,7 +882,7 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro
$l_arnaque = $this->fixture('Class_Article',
['id' => 13,
'titre' => 'Gilets Jaunes',
'contenu' => 'La révolution a commencé.']);
'contenu' => '<a href="'.BASE_URL.'/viewarticle/gilets-jaunes"> La révolution a commencé.<img src=\'/userfiles/jaunes.gif\' /> . <img SRC="/userfiles/gilets.gif" /></a><a href="http://lienexterne/maquereau"><img src=\'http://imageexterne/maquereau.gif\' /></a>', ]);
$this->fixture('Class_ArticleCategorie',
['id' => 89,
......@@ -925,11 +925,6 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro
}
public function testBodyHtml() {
$this->assertXPath('//div//img[@src="zork.jpg"]', $this->_response->getBody());
}
/** @test */
public function noticeShouldBePresent() {
$this->assertQueryContentContains('p', 'Martine à la plage', $this->_response->getBody());
......@@ -950,26 +945,56 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro
/** @test */
public function leRoiDesConsShouldBeDisplay() {
$this->assertXPathContentContains('//div', 'Le Roi des cons', $this->_response->getBody());
$this->assertXPathContentContains('//div', 'Le Roi des cons');
}
/** @test */
public function lArnaqueShouldBeDisplay() {
$this->assertXPathContentContains('//div', 'L\'arnaque', $this->_response->getBody());
$this->assertXPathContentContains('//div', 'L\'arnaque');
}
/** @test */
public function GiletsJaunesShouldBeDisplay() {
$this->assertXPathContentContains('//div', 'Gilets Jaunes', $this->_response->getBody());
$this->assertXPathContentContains('//div', 'Gilets Jaunes');
}
/** @test */
public function giletsImageUrlShouldContainsDomain() {
$this->assertXPath('//div//img[@src="http://localhost'.BASE_URL.'/userfiles/gilets.gif"]');
}
/** @test */
public function jaunesImageUrlShouldContainsDomain() {
$this->assertXPath('//div//img[@src=\'http://localhost'.BASE_URL.'/userfiles/jaunes.gif\']');
}
/** @test */
public function imageMaquereauShouldKeepSameUrl() {
$this->assertXPath('//div//img[@src=\'http://imageexterne/maquereau.gif\']');
}
/** @test */
public function linkMaquereauShouldKeepSameUrl() {
$this->assertXPath('//div//a[@href=\'http://lienexterne/maquereau\']');
}
/** @test */
public function linkArticleGiletJauneShouldContainsDomain() {
$this->assertXPath('//div//a[@href="http://localhost'.BASE_URL.'/viewarticle/gilets-jaunes"]');
}
/** @test */
public function septanteMillionsShouldBeDisplay() {
$this->assertXPathContentContains('//div', '70 millions', $this->_response->getBody());
$this->assertXPathContentContains('//div', '70 millions');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment