Skip to content

Commit

Permalink
Improve Windows compatibility for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Mar 29, 2016
1 parent 0e992c6 commit b7151db
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions test/phpmailerTest.php
Expand Up @@ -13,7 +13,7 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

require_once '../PHPMailerAutoload.php';
require_once realpath('../PHPMailerAutoload.php');

/**
* PHPMailer - PHP email transport unit test class
Expand Down Expand Up @@ -49,26 +49,26 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
*/
public $NoteLog = array();

/**
* Default include path
* @var string
*/
public $INCLUDE_DIR = '../';

/**
* PIDs of any processes we need to kill
* @var array
* @access private
*/
private $pids = array();

/**
* Default include path
* @var string
*/
const INCLUDE_DIR = '../';

/**
* Run before each test is started.
*/
public function setUp()
{
if (file_exists('./testbootstrap.php')) {
include './testbootstrap.php'; //Overrides go in here
if (file_exists('testbootstrap.php')) {
include 'testbootstrap.php'; //Overrides go in here
}
$this->Mail = new PHPMailer;
$this->Mail->SMTPDebug = 3; //Full debug output
Expand Down Expand Up @@ -100,7 +100,6 @@ public function setUp()
$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) {
Expand Down Expand Up @@ -300,7 +299,7 @@ public function setAddress($sAddress, $sName = '', $sType = 'to')
public function testBootstrap()
{
$this->assertTrue(
file_exists('./testbootstrap.php'),
file_exists('testbootstrap.php'),
'Test config params missing - copy testbootstrap.php to testbootstrap-dist.php and change as appropriate'
);
}
Expand Down Expand Up @@ -725,7 +724,7 @@ public function testMultiplePlainFileAttachment()
$this->Mail->Body = 'Here is the text body';
$this->Mail->Subject .= ': Plain + Multiple FileAttachments';

if (!$this->Mail->addAttachment('../examples/images/phpmailer.png')) {
if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'))) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
Expand Down Expand Up @@ -831,7 +830,7 @@ public function testHtmlIso8859()

//This file is in ISO-8859-1 charset
//Needs to be external because this file is in UTF-8
$content = file_get_contents('../examples/contents.html');
$content = file_get_contents(realpath('../examples/contents.html'));
// This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded
$check = base64_decode('6eju/OfF8ebf');
//Make sure it really is in ISO-8859-1!
Expand All @@ -841,7 +840,7 @@ public function testHtmlIso8859()
"ISO-8859-1",
mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true)
),
'../examples'
realpath(self::INCLUDE_DIR . 'examples')
);
$this->buildBody();
$this->assertTrue(
Expand Down Expand Up @@ -905,7 +904,7 @@ public function testUtf8WithEmbeddedImage()
</html>
EOT;
$this->Mail->addEmbeddedImage(
'../examples/images/phpmailer.png',
realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'),
'my-attach',
'phpmailer.png',
'base64',
Expand Down Expand Up @@ -941,12 +940,12 @@ public function testPlainUtf8()
*/
public function testMsgHTML()
{
$message = file_get_contents('../examples/contentsutf8.html');
$message = file_get_contents(realpath(self::INCLUDE_DIR . 'examples/contentsutf8.html'));
$this->Mail->CharSet = 'utf-8';
$this->Mail->Body = '';
$this->Mail->AltBody = '';
//Uses internal HTML to text conversion
$this->Mail->msgHTML($message, '../examples');
$this->Mail->msgHTML($message, realpath(self::INCLUDE_DIR . 'examples'));
$this->Mail->Subject .= ': msgHTML';

$this->assertNotEmpty($this->Mail->Body, 'Body not set by msgHTML');
Expand All @@ -955,7 +954,7 @@ public function testMsgHTML()

//Again, using a custom HTML to text converter
$this->Mail->AltBody = '';
$this->Mail->msgHTML($message, '../examples', function ($html) {
$this->Mail->msgHTML($message, realpath(self::INCLUDE_DIR . 'examples'), function ($html) {
return strtoupper(strip_tags($html));
});
$this->Mail->Subject .= ' + custom html2text';
Expand All @@ -973,7 +972,9 @@ public function testHTMLAttachment()
$this->Mail->Subject .= ': HTML + Attachment';
$this->Mail->isHTML(true);

if (!$this->Mail->addAttachment('../examples/images/phpmailer_mini.png', 'phpmailer_mini.png')) {
if (!$this->Mail->addAttachment(
realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), 'phpmailer_mini.png')
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
Expand All @@ -995,7 +996,7 @@ public function testHTMLStringEmbedNoName()
$this->Mail->isHTML(true);

if (!$this->Mail->addStringEmbeddedImage(
file_get_contents('../examples/images/phpmailer_mini.png'),
file_get_contents(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png')),
md5('phpmailer_mini.png').'@phpmailer.0',
'', //intentionally empty name
'base64',
Expand All @@ -1019,12 +1020,12 @@ public function testHTMLMultiAttachment()
$this->Mail->Subject .= ': HTML + multiple Attachment';
$this->Mail->isHTML(true);

if (!$this->Mail->addAttachment('../examples/images/phpmailer_mini.png', 'phpmailer_mini.png')) {
if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), 'phpmailer_mini.png')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}

if (!$this->Mail->addAttachment('../examples/images/phpmailer.png', 'phpmailer.png')) {
if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'), 'phpmailer.png')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
Expand All @@ -1044,7 +1045,7 @@ public function testEmbeddedImage()
$this->Mail->isHTML(true);

if (!$this->Mail->addEmbeddedImage(
'../examples/images/phpmailer.png',
realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'),
'my-attach',
'phpmailer.png',
'base64',
Expand Down Expand Up @@ -1073,7 +1074,7 @@ public function testMultiEmbeddedImage()
$this->Mail->isHTML(true);

if (!$this->Mail->addEmbeddedImage(
'../examples/images/phpmailer.png',
realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'),
'my-attach',
'phpmailer.png',
'base64',
Expand Down Expand Up @@ -1135,7 +1136,7 @@ public function testAltBodyAttachment()
public function testIcal()
{
//Standalone ICS tests
require_once '../extras/EasyPeasyICS.php';
require_once realpath(self::INCLUDE_DIR . 'extras/EasyPeasyICS.php');
$ICS = new EasyPeasyICS("PHPMailer test calendar");
$this->assertNotEmpty(
$ICS->addEvent(
Expand Down Expand Up @@ -2027,8 +2028,8 @@ public function testPopBeforeSmtpGood()
}

/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-bad login
* Use a fake POP3 server to test POP-before-SMTP auth
* with a known-bad login.
*/
public function testPopBeforeSmtpBad()
{
Expand Down

0 comments on commit b7151db

Please sign in to comment.