Files
xxx/tests/php/Unit/EmailTest.php
T
tim ed959888b4 Add PHP unit tests and page tests.
Run "composer install", then "composer test".
2026-09-26 03:48:09 +02:00

46 lines
2.0 KiB
PHP

<?php
namespace Xxx\Tests\Unit;
use Xxx\Tests\Support\Mail;
use Xxx\Tests\Support\TestCase;
// send_email() in publish/post.lib.php
class EmailTest extends TestCase {
private function send(string $title, string $author, string $story): array {
$result = Mail::run('send_email(' . var_export($title, TRUE) . ', ' . var_export($author, TRUE) . ', ' . var_export($story, TRUE) . ');');
$this->assertSame(0, $result['status'], $result['stderr']);
$this->assertCount(1, $result['mails'], $result['stderr']);
$this->assertSame('', $result['log']);
return $result['mails'][0];
}
public function testGoesToTheEditorsFromTheQueue(): void {
$mail = $this->send('A title', 'Ann', '<p>Hello.</p>');
$this->assertSame('editor@xxx.org.za', $mail['headers']['to']);
$this->assertSame('x.x.x Queue <editor@xxx.org.za>', $mail['headers']['from']);
$this->assertSame('New submission: A title', $mail['subject']);
}
public function testSubjectKeepsNonAsciiTitles(): void {
$this->assertSame('New submission: Ōmega café', $this->send('Ōmega café', 'Ann', '<p>x</p>')['subject']);
}
public function testBodyIsPlainTextOfTheStory(): void {
$mail = $this->send('T', 'Ann', "<p>First &amp; <strong>bold</strong>.</p>\n<p>Line one<br />line two</p><p></p><p>&lt;b&gt; is text &#8220;quoted&#8221;</p>");
$this->assertSame("Please review the queue. Ann has sent the following new submission:\n\n"
. "First & bold.\n\nLine one\nline two\n\n<b> is text “quoted”"
. "\n\nhttp://xxx.org.za/publish/edit", trim($mail['body']));
}
public function testLongLinesAreWrapped(): void {
$body = $this->send('T', 'Ann', '<p>' . str_repeat('word ', 40) . '</p>')['body'];
foreach (explode("\n", trim($body)) as $line)
$this->assertLessThanOrEqual(75, strlen($line));
}
public function testImageSubmissionSaysSo(): void {
$body = $this->send('T', 'Ann', '')['body'];
$this->assertStringContainsString("new submission:\n\n<Submission is an image. Review on the site.>", $body);
}
}