summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-10-12 12:41:24 +0200
committerAndreas Gohr <andi@splitbrain.org>2013-10-12 12:41:24 +0200
commit0ee5ed1e998c1e67c4a0b7687977c4e2e0f29494 (patch)
treee3420b8afb6873ec040532e2e5e00bd27ab106b6 /_test
parent6540219fb5954ad1962bc07750e3c1bbcd5aafde (diff)
downloadrpg-0ee5ed1e998c1e67c4a0b7687977c4e2e0f29494.tar.gz
rpg-0ee5ed1e998c1e67c4a0b7687977c4e2e0f29494.tar.bz2
IETF's message lint service as a test for Mailer class
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/mailer.test.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php
index ef78692b3..fefb6f508 100644
--- a/_test/tests/inc/mailer.test.php
+++ b/_test/tests/inc/mailer.test.php
@@ -156,5 +156,61 @@ class mailer_test extends DokuWikiTest {
$this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.');
$this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.');
}
+
+ /**
+ * @group internet
+ */
+ function test_lint(){
+ // prepare a simple multipart message
+ $mail = new TestMailer();
+ $mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
+ $mail->subject('This is a töst');
+ $mail->setBody('Hello Wörld,
+
+ please don\'t burn, okay?
+ ');
+ $mail->attachContent('some test data', 'text/plain', 'text.txt');
+ $msg = $mail->dump();
+ $msglines = explode("\n", $msg);
+
+ // ask message lint if it is okay
+ $html = new HTTPClient();
+ $results = $html->post('http://tools.ietf.org/tools/msglint/msglint', array('msg'=>$msg));
+ $this->assertTrue($results !== false);
+
+ // parse the result lines
+ $lines = explode("\n", $results);
+ $rows = count($lines);
+ $i=0;
+ while(trim($lines[$i]) != '-----------' && $i<$rows) $i++; //skip preamble
+ for($i=$i+1; $i<$rows; $i++){
+ $line = trim($lines[$i]);
+ if($line == '-----------') break; //skip appendix
+
+ // get possible continuation of the line
+ while($lines[$i+1][0] == ' '){
+ $line .= ' '.trim($lines[$i+1]);
+ $i++;
+ }
+
+ // check the line for errors
+ if(substr($line,0,5) == 'ERROR'){
+ // get the context in which the error occured
+ $errorin = '';
+ if(preg_match('/line (\d+)$/', $line, $m)){
+ $errorin .= "\n".$msglines[$m[1] - 1];
+ }
+ if(preg_match('/lines (\d+)-(\d+)$/', $line, $m)){
+ for($x=$m[1]-1; $x<$m[2]; $x++){
+ $errorin .= "\n".$msglines[$x];
+ }
+ }
+
+ // raise the error
+ throw new Exception($line.$errorin);
+ }
+ }
+
+ }
}
//Setup VIM: ex: et ts=4 :