Пример #1
0
 function test_replacements()
 {
     $mail = new TestMailer();
     $replacements = array('@DATE@', '@BROWSER@', '@IPADDRESS@', '@HOSTNAME@', '@TITLE@', '@DOKUWIKIURL@', '@USER@', '@NAME@', '@MAIL@');
     $mail->setBody('A test mail in with replacements ' . join(' ', $replacements));
     $text = $mail->prop('text');
     $html = $mail->prop('html');
     foreach ($replacements as $repl) {
         $this->assertNotRegexp("/{$repl}/", $text, "{$repl} replacement still in text");
         $this->assertNotRegexp("/{$repl}/", $html, "{$repl} replacement still in html");
     }
 }
Пример #2
0
 public function test_should_encode_alternative_message_from_templates_with_external_embeded_images()
 {
     if (!@file_get_contents('http://www.bermilabs.com/images/bermilabs_logo.png')) {
         return;
     }
     // offline mode
     $TestMailer = new TestMailer();
     $Message = $TestMailer->create('alternative_message_from_templates', $this->recipient, true, true);
     //$TestMailer->delivery_method = 'php';
     //$TestMailer->deliver($Message);
     $rendered_message = $TestMailer->getRawMessage();
     $this->assertPattern('/==\\r\\n\\r\\n--[a-f0-9]{32}\\r\\nContent-Type: image\\/png;/', $rendered_message, 'Two images embeded');
 }
Пример #3
0
    /**
     * @group internet
     */
    function test_lint()
    {
        // prepare a simple multipart message
        $mail = new TestMailer();
        $mail->to(array('Möp <*****@*****.**> ', ' foo <*****@*****.**>'));
        $mail->from('Me <*****@*****.**>');
        $mail->subject('This is a töst');
        $mail->setBody('Hello Wörld,

        please don\'t burn, okay?
        ');
        $mail->attachContent('some test data', 'text/plain', 'a text.txt');
        $msg = $mail->dump();
        $msglines = explode("\n", $msg);
        //echo $msg;
        // ask message lint if it is okay
        $html = new HTTPClient();
        $results = $html->post('http://tools.ietf.org/tools/msglint/msglint', array('msg' => $msg));
        if ($results === false) {
            $this->markTestSkipped('no response from validator');
            return;
        }
        // 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' || substr($line, 0, 7) == 'WARNING') {
                // ignore some errors
                if (strpos($line, "missing mandatory header 'return-path'")) {
                    continue;
                }
                #set by MDA
                if (strpos($line, "bare newline in text body decoded")) {
                    continue;
                }
                #seems to be false positive
                // 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);
            }
        }
    }
Пример #4
0
 public function test_should_add_from_name()
 {
     $TestMailer = new TestMailer();
     $Message = $TestMailer->create('message_from_first_name', array('No One' => '*****@*****.**'));
     $rendered_message = $TestMailer->getRawMessage();
     $this->assertPattern('/To: "No One" <no\\.one@example\\.com>/', $rendered_message);
     $this->assertPattern('/From: "Some \\\\"One" <some\\.one@example\\.com>/', $rendered_message);
 }