Skip to content

Commit

Permalink
Fix message rendering tests for iframed message parts
Browse files Browse the repository at this point in the history
  • Loading branch information
pabzm committed Feb 20, 2025
1 parent be4db97 commit c6d9d0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
10 changes: 8 additions & 2 deletions tests/MessageRendering/InlineImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public function testImageFromDataUri(): void

$this->assertSame('***SPAM*** wir gratulieren Ihnen recht herzlich.', $this->getScrubbedSubject($domxpath));

$divElements = $domxpath->query('//div[@class="rcmBody"]/div/div');
$bodyParts = $domxpath->query('//iframe[contains(@class, "framed-message-part")]');
$this->assertCount(1, $bodyParts, 'Message body parts');
$params = $this->getSrcParams($bodyParts[0]);
$this->assertSrcUrlParams($params, '1');
$domxpath_body = $this->renderIframedBodyContent($params);

$divElements = $domxpath_body->query('//body/div/div');
$this->assertCount(3, $divElements, 'Body HTML DIV elements');

$this->assertSame('wir gratulieren Ihnen recht herzlich.', $divElements[0]->textContent);
Expand All @@ -24,7 +30,7 @@ public function testImageFromDataUri(): void
$this->assertStringContainsString('?_task=mail&_action=get&_mbox=INBOX&_uid=', $src);
$this->assertStringContainsString('&_part=2&_embed=1&_mimeclass=image', $src);

$this->assertSame('v1signature', $divElements[2]->attributes->getNamedItem('class')->textContent);
$this->assertSame('signature', $divElements[2]->attributes->getNamedItem('class')->textContent);
// This matches a non-breakable space.
$this->assertMatchesRegularExpression('|^\x{00a0}$|u', $divElements[2]->textContent);

Expand Down
2 changes: 1 addition & 1 deletion tests/MessageRendering/MessageRenderingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function assertIframedContent(\DOMNode $elem, string $partId, string $
$this->assertSame($content, trim($body));
}

private function assertSrcUrlParams(array $params, string $partId): void
protected function assertSrcUrlParams(array $params, string $partId): void
{
$this->assertSame('mail', $params['_task']);
$this->assertSame('get', $params['_action']);
Expand Down
5 changes: 0 additions & 5 deletions tests/MessageRendering/SingleImageNoTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class SingleImageNoTextTest extends MessageRenderingTestCase
*/
public function testShowMultipartMixedSingleImageToo(): void
{
$this->markTestSkipped('TBD: test for fixing GH issue 9443');
// This next comment line prevents phpstan from reporting this as
// unreachable code (technically it is right, but that's on purpose
// here...).
// @phpstan-ignore-next-line
$domxpath = $this->renderMessage('[email protected]');

$this->assertSame('Not OK', $this->getScrubbedSubject($domxpath));
Expand Down
19 changes: 16 additions & 3 deletions tests/MessageRendering/TnefEmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public function testTnefEmail1(): void
{
$domxpath = $this->renderMessage('[email protected]');

$this->assertSame('', $this->getBody($domxpath));
$bodyParts = $domxpath->query('//iframe[contains(@class, "framed-message-part")]');
$this->assertCount(0, $bodyParts, 'Message body parts');

$attchNames = $domxpath->query('//span[@class="attachment-name"]');
$this->assertCount(1, $attchNames, 'Attachments');
Expand All @@ -22,7 +23,13 @@ public function testTnefEmail2(): void
{
$domxpath = $this->renderMessage('[email protected]');

$this->assertStringStartsWith('THE BILL OF RIGHTSAmendments 1-10 of the', $this->getBody($domxpath));
$bodyParts = $domxpath->query('//iframe[contains(@class, "framed-message-part")]');
$this->assertCount(1, $bodyParts, 'Message body parts');
$params = $this->getSrcParams($bodyParts[0]);
$this->assertSrcUrlParams($params, 'winmail.1.html');
$body = $this->getIframedContent($params);

$this->assertStringStartsWith('THE BILL OF RIGHTSAmendments 1-10 of the', trim($body));

$attchNames = $domxpath->query('//span[@class="attachment-name"]');
$this->assertCount(0, $attchNames, 'Attachments');
Expand All @@ -32,7 +39,13 @@ public function testTnefEmail3(): void
{
$domxpath = $this->renderMessage('[email protected]');

$bodyParagraphs = $domxpath->query('//div[@class="rcmBody"]/p');
$bodyParts = $domxpath->query('//iframe[contains(@class, "framed-message-part")]');
$this->assertCount(1, $bodyParts, 'Message body parts');
$params = $this->getSrcParams($bodyParts[0]);
$this->assertSrcUrlParams($params, 'winmail.1.html');
$domxpath_body = $this->renderIframedBodyContent($params);

$bodyParagraphs = $domxpath_body->query('//p');
$this->assertCount(8, $bodyParagraphs, 'Body HTML paragraphs');
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[0]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[1]->textContent);
Expand Down

0 comments on commit c6d9d0c

Please sign in to comment.