diff --git a/test/phpmailerLangTest.php b/test/phpmailerLangTest.php new file mode 100644 index 00000000..1baa24a0 --- /dev/null +++ b/test/phpmailerLangTest.php @@ -0,0 +1,344 @@ +INCLUDE_DIR . 'class.phpmailer.php'; + $this->Mail = new PHPMailer; + + $this->Mail->Priority = 3; + $this->Mail->Encoding = "8bit"; + $this->Mail->CharSet = "iso-8859-1"; + if (array_key_exists('mail_from', $_REQUEST)) { + $this->Mail->From = $_REQUEST['mail_from']; + } else { + $this->Mail->From = 'unit_test@phpmailer.example.com'; + } + $this->Mail->FromName = "Unit Tester"; + $this->Mail->Sender = ""; + $this->Mail->Subject = "Unit Test"; + $this->Mail->Body = ""; + $this->Mail->AltBody = ""; + $this->Mail->WordWrap = 0; + if (array_key_exists('mail_host', $_REQUEST)) { + $this->Mail->Host = $_REQUEST['mail_host']; + } else { + $this->Mail->Host = 'mail.example.com'; + } + if (array_key_exists('mail_port', $_REQUEST)) { + $this->Mail->Port = $_REQUEST['mail_port']; + } else { + $this->Mail->Port = 25; + } + $this->Mail->Helo = "localhost.localdomain"; + $this->Mail->SMTPAuth = false; + $this->Mail->Username = ""; + $this->Mail->Password = ""; + $this->Mail->PluginDir = $this->INCLUDE_DIR; + $this->Mail->AddReplyTo("no_reply@phpmailer.example.com", "Reply Guy"); + $this->Mail->Sender = "unit_test@phpmailer.example.com"; + + if (strlen($this->Mail->Host) > 0) { + $this->Mail->Mailer = "smtp"; + } else { + $this->Mail->Mailer = "mail"; + $this->Mail->Sender = "unit_test@phpmailer.example.com"; + } + + if (array_key_exists('mail_to', $_REQUEST)) { + $this->SetAddress($_REQUEST['mail_to'], 'Test User', 'to'); + } + if (array_key_exists('mail_cc', $_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) { + $this->SetAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc'); + } + } + + /** + * Run after each test is completed. + */ + function tearDown() + { + // Clean global variables + $this->Mail = null; + $this->ChangeLog = array(); + $this->NoteLog = array(); + } + + + /** + * Build the body of the message in the appropriate format. + * @private + * @returns void + */ + function BuildBody() + { + $this->CheckChanges(); + + // Determine line endings for message + if ($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0) { + $eol = "
"; + $bullet = "
  • "; + $bullet_start = ""; + } else { + $eol = "\n"; + $bullet = " - "; + $bullet_start = ""; + $bullet_end = ""; + } + + $ReportBody = ""; + + $ReportBody .= "---------------------" . $eol; + $ReportBody .= "Unit Test Information" . $eol; + $ReportBody .= "---------------------" . $eol; + $ReportBody .= "phpmailer version: " . $this->Mail->Version . $eol; + $ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol; + + if (strlen($this->Mail->Host) > 0) { + $ReportBody .= "Host: " . $this->Mail->Host . $eol; + } + + // If attachments then create an attachment list + $attachments = $this->Mail->GetAttachments(); + if (count($attachments) > 0) { + $ReportBody .= "Attachments:" . $eol; + $ReportBody .= $bullet_start; + foreach ($attachments as $attachment) { + $ReportBody .= $bullet . "Name: " . $attachment[1] . ", "; + $ReportBody .= "Encoding: " . $attachment[3] . ", "; + $ReportBody .= "Type: " . $attachment[4] . $eol; + } + $ReportBody .= $bullet_end . $eol; + } + + // If there are changes then list them + if (count($this->ChangeLog) > 0) { + $ReportBody .= "Changes" . $eol; + $ReportBody .= "-------" . $eol; + + $ReportBody .= $bullet_start; + for ($i = 0; $i < count($this->ChangeLog); $i++) { + $ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" . + $this->ChangeLog[$i][1] . "]" . $eol; + } + $ReportBody .= $bullet_end . $eol . $eol; + } + + // If there are notes then list them + if (count($this->NoteLog) > 0) { + $ReportBody .= "Notes" . $eol; + $ReportBody .= "-----" . $eol; + + $ReportBody .= $bullet_start; + for ($i = 0; $i < count($this->NoteLog); $i++) { + $ReportBody .= $bullet . $this->NoteLog[$i] . $eol; + } + $ReportBody .= $bullet_end; + } + + // Re-attach the original body + $this->Mail->Body .= $eol . $eol . $ReportBody; + } + + /** + * Check which default settings have been changed for the report. + * @private + * @returns void + */ + function CheckChanges() + { + if ($this->Mail->Priority != 3) { + $this->AddChange("Priority", $this->Mail->Priority); + } + if ($this->Mail->Encoding != "8bit") { + $this->AddChange("Encoding", $this->Mail->Encoding); + } + if ($this->Mail->CharSet != "iso-8859-1") { + $this->AddChange("CharSet", $this->Mail->CharSet); + } + if ($this->Mail->Sender != "") { + $this->AddChange("Sender", $this->Mail->Sender); + } + if ($this->Mail->WordWrap != 0) { + $this->AddChange("WordWrap", $this->Mail->WordWrap); + } + if ($this->Mail->Mailer != "mail") { + $this->AddChange("Mailer", $this->Mail->Mailer); + } + if ($this->Mail->Port != 25) { + $this->AddChange("Port", $this->Mail->Port); + } + if ($this->Mail->Helo != "localhost.localdomain") { + $this->AddChange("Helo", $this->Mail->Helo); + } + if ($this->Mail->SMTPAuth) { + $this->AddChange("SMTPAuth", "true"); + } + } + + /** + * Add a changelog entry. + * @access private + * @param string $sName + * @param string $sNewValue + * @return void + */ + function AddChange($sName, $sNewValue) + { + $this->ChangeLog[] = array($sName, $sNewValue); + } + + /** + * Adds a simple note to the message. + * @public + * @param string $sValue + * @return void + */ + function AddNote($sValue) + { + $this->NoteLog[] = $sValue; + } + + /** + * Adds all of the addresses + * @access public + * @param string $sAddress + * @param string $sName + * @param string $sType + * @return boolean + */ + function SetAddress($sAddress, $sName = '', $sType = 'to') + { + switch ($sType) { + case 'to': + return $this->Mail->AddAddress($sAddress, $sName); + case 'cc': + return $this->Mail->AddCC($sAddress, $sName); + case "bcc": + return $this->Mail->AddBCC($sAddress, $sName); + } + return false; + } + + ///////////////////////////////////////////////// + // UNIT TESTS + ///////////////////////////////////////////////// + + /** + * Test language files for missing and excess translations + * All languages are compared with English + */ + function test_Translations() + { + $this->Mail->SetLanguage('en'); + $definedStrings = $this->Mail->GetTranslations(); + $err = ''; + foreach (new DirectoryIterator('../language') as $fileInfo) { + if ($fileInfo->isDot()) { + continue; + } + $matches = array(); + //Only look at language files, ignore anything else in there + if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) { + $lang = $matches[1]; //Extract language code + $PHPMAILER_LANG = array(); //Language strings get put in here + include $fileInfo->getPathname(); //Get language strings + $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG)); + $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings)); + if (!empty($missing)) { + $err .= "\nMissing translations in $lang: " . implode(', ', $missing); + } + if (!empty($extra)) { + $err .= "\nExtra translations in $lang: " . implode(', ', $extra); + } + } + } + $this->assertEmpty($err, $err); + } +} + +/** + * This is a sample form for setting appropriate test values through a browser + * These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script + * which is probably more useful if you run these tests a lot + + +

    phpmailer Unit Test

    +By entering a SMTP hostname it will automatically perform tests with SMTP. + +
    + +From Address: "/> +
    +To Address: "/> +
    +Cc Address: "/> +
    +SMTP Hostname: "/> +

    + + +

    + + + */ diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 992e5a80..dcf6253a 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -1009,38 +1009,6 @@ EOT; $this->Mail->ClearReplyTos(); } - /** - * Test language files for missing and excess translations - * All languages are compared with English - */ - function test_Translations() - { - $this->Mail->SetLanguage('en'); - $definedStrings = $this->Mail->GetTranslations(); - $err = ''; - foreach (new DirectoryIterator('../language') as $fileInfo) { - if ($fileInfo->isDot()) { - continue; - } - $matches = array(); - //Only look at language files, ignore anything else in there - if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) { - $lang = $matches[1]; //Extract language code - $PHPMAILER_LANG = array(); //Language strings get put in here - include $fileInfo->getPathname(); //Get language strings - $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG)); - $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings)); - if (!empty($missing)) { - $err .= "\nMissing translations in $lang: " . implode(', ', $missing); - } - if (!empty($extra)) { - $err .= "\nExtra translations in $lang: " . implode(', ', $extra); - } - } - } - $this->assertEmpty($err, $err); - } - /** * Encoding tests */