PHP Classes

File: test_quoted_printable.php

Recommend this page to a friend!
  Classes of Manuel Lemos   MIME E-mail message sending   test_quoted_printable.php   Download  
File: test_quoted_printable.php
Role: Unit test script
Content type: text/plain
Description: Test suite for verifying the quoted printable encoding support.
Class: MIME E-mail message sending
PHP mailer to compose and send MIME messages
Author: By
Last change: Made the line length limit be 76 characters.
Avoided using an additional line break after each multipart body data.
Date: 11 years ago
Size: 4,030 bytes
 

Contents

Class file image Download
<?php
/*
 * test_quoted_printable.php
 *
 * @(#) $Id: test_quoted_printable.php,v 1.8 2012/08/25 10:01:39 mlemos Exp $
 *
 */

   
require("email_message.php");

Function
test_quoting(&$message, $test_values, $cs, $quote, $email_header, &$tests, &$failed)
{
   
Reset($test_values);
   
$end=(GetType($value=Key($test_values))!="string");
    for(;!
$end;$tests++)
    {
        echo
"Test value \"",$value,"\"...";
       
flush();
       
$encoded=($quote ? $message->QuoteText($value) : $message->QuotedPrintableEncode($value, $cs, 1, $email_header));
        if(
strcmp($encoded,$test_values[$value]))
        {
            echo
"\tFAIL: returned \"",$encoded,"\" and not \"",$test_values[$value],"\" as expected!\n";
           
$failed++;
        }
        else
            echo
"\tOK!\n";
       
Next($test_values);
       
$end=(GetType($value=Key($test_values))!="string");
    }
}

   
$message=new email_message_class;

   
$failed=$tests=0;

    echo
"Testing header q-encoding...\n\n";
   
$cs=$message->default_charset;
   
$test_values=array(
       
""=>"",
       
"Coffee"=>"Coffee",
       
"Coffee?"=>"=?".$cs."?q?Coffee=3F?=",
       
"More coffee?"=>"More =?".$cs."?q?coffee=3F?=",
       
"More coffee, Sir?"=>"More =?".$cs."?q?coffee=2C_Sir=3F?=",
       
"?"=>"=?".$cs."?q?=3F?=",
       
" ?"=>" =?".$cs."?q?=3F?=",
       
" ? "=>" =?".$cs."?q?=3F_?=",
       
"\n.Dot.ted"=>"\n\t.Dot.ted",
       
"\nFrom line\nfrom line"=>"\n\tFrom line\n\tfrom line",
       
"More\ncoffee,\nSir?"=>"=?".$cs."?q?More\n\tcoffee=2C\n\tSir=3F?=",
       
"Café?"=>"=?ISO-8859-1?q?Caf=E9=3F?=",
    );
   
test_quoting($message, $test_values, $cs, 0, 1, $tests, $failed);

    echo
"Testing header q-encoding for non-email address headers...\n\n";
   
$cs=$message->default_charset;
   
$test_values=array(
       
""=>"",
       
"Coffee"=>"Coffee",
       
"Coffee?"=>"Coffee?",
       
"More coffee?"=>"More coffee?",
       
"More coffee, Sir?"=>"More coffee, Sir?",
       
"?"=>"?",
       
" ?"=>" ?",
       
" ? "=>" ? ",
       
"\n.Dot.ted"=>"\n\t.Dot.ted",
       
"\nFrom line\nfrom line"=>"\n\tFrom line\n\tfrom line",
       
"More\ncoffee,\nSir?"=>"More\n\tcoffee,\n\tSir?",
       
"Café?"=>"=?ISO-8859-1?q?Caf=E9=3F?=",
    );
   
test_quoting($message, $test_values, $cs, 0, 0, $tests, $failed);

    echo
"\nTesting quoted-printable encoding...\n\n";
   
$test_values=array(
       
""=>"",
       
"Coffee"=>"Coffee",
       
"Coffee?"=>"Coffee?",
       
"Café"=>"Caf=E9",
       
"Café\nau lait"=>"Caf=E9\nau lait",
       
"Lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lait"=>
       
"Lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lait, lai=\nt",
       
"Lait, lait, lait, lait, lait, lait, lait,\nlait, lait, lait, lait, lait, lait"=>
       
"Lait, lait, lait, lait, lait, lait, lait,\nlait, lait, lait, lait, lait, lait",
       
"Café, Café, Café, Café, Café, Café, Café,\nCafé, Café, Café, Café, Café, Café"=>
       
"Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9,\nCaf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9",
       
"Café, Café, Café, Café, Café, Café, Café, Café, Café Cafe, Café, Café, Café"=>
       
"Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9 Cafe=\n, Caf=E9, Caf=E9, Caf=E9",
       
"Café, Café, Café, Café, Café, Café, Café, Café, Café, Café, Café, Café, Café"=>
       
"Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=E9, Caf=\n=E9, Caf=E9, Caf=E9, Caf=E9",
       
"Dummy line\n.Dotted.line\n."=>
       
"Dummy line\n=2EDotted.line\n=2E",
       
"From line\nfrom line\n"=>
       
"=46rom line\n=66rom line\n",
       
"Very.very.very.very.very.very.very.very.very.very.very.very.very.very.long..text"=>
       
"Very.very.very.very.very.very.very.very.very.very.very.very.very.very.long.=\n=2Etext",
       
"Café?"=>"Caf=E9?",
    );
   
test_quoting($message, $test_values, '', 0, 1, $tests, $failed);

   
$test_values=array(
       
"S XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"=>"> S
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> XXXXXXXXXXXXXXXXXXXXXXXXX
"
,
    );
    echo
"\nTesting quoting text ...\n\n";
   
test_quoting($message, $test_values, '', 1, 1, $tests, $failed);

    echo
"\nPerformed ",$tests," tests: ",($failed ? $failed." failed, ".($tests-$failed)." succeeded" : "all succeeded"),"!\n";
   
?>