* Copyright 2001-2012 Strangecode, LLC
*
* This file is part of The Strangecode Codebase.
*
* The Strangecode Codebase is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* The Strangecode Codebase is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* The Strangecode Codebase. If not, see .
*/
/**
* PHPUnit test case for codebase/lib/Email.inc.php
*
* The method skeletons below need to be filled in with
* real data so that the tests will run correctly. Replace
* all EXPECTED_VAL and PARAM strings with real data.
*
* Created with PHPUnit_Skeleton on 2005-12-01
*/
class EmailTest extends PHPUnit_Framework_TestCase {
var $Email;
function setUp()
{
require dirname(__FILE__) . '/_config.inc.php';
require_once '../lib/Email.inc.php';
$this->Email = new Email();
}
function tearDown()
{
unset($this->Email);
}
// function testsetparam()
// {
// $result = $this->Email->setparam(PARAM);
// $expected = EXPECTED_VAL;
// $this->assertEquals($expected, $result);
// }
//
// function testgetparam()
// {
// $result = $this->Email->getparam(PARAM);
// $expected = EXPECTED_VAL;
// $this->assertEquals($expected, $result);
// }
//
// function testsettemplate()
// {
// $result = $this->Email->settemplate(PARAM);
// $expected = EXPECTED_VAL;
// $this->assertEquals($expected, $result);
// }
//
// function testsetstring()
// {
// $result = $this->Email->setstring(PARAM);
// $expected = EXPECTED_VAL;
// $this->assertEquals($expected, $result);
// }
//
// function testreplace()
// {
// $result = $this->Email->replace(PARAM);
// $expected = EXPECTED_VAL;
// $this->assertEquals($expected, $result);
// }
//
function testsend()
{
$this->Email = new Email(array(
'to' => 'Rob Recipient ',
'from' => 'Sam Sender ',
'subject' => 'EmailTest',
'headers' => array(
'CC' => 'This header removed in REDIRECT sandbox mode ',
'X-Hello' => 'Hi there',
),
'sandbox_mode' => Email::SANDBOX_MODE_REDIRECT,
'sandbox_to_addr' => 'quinn@strangecode.com',
));
$this->Email->setString('This is a {TEST}');
$this->Email->replace(array(
'test' => '– you guessed it – a test! Sent from ' . __FILE__
));
$result = $this->Email->send();
$expected = true;
$this->assertEquals($expected, $result);
}
function testvalidemail()
{
$testpool = file('_email_test_addresses.txt');
$gc = 0;
$bc = 0;
$good = array();
$bad = array();
if (is_array($testpool) && !empty($testpool)) {
foreach ($testpool as $a) {
if ($this->Email->validEmail($a)) {
$good[] = trim($a);
$gc++;
} else {
$bad[] = trim($a);
$bc++;
}
}
}
$this->assertEquals(45, $gc, 'Unexpected number of valid emails found.');
$this->assertEquals(45, $bc, 'Unexpected number of invalid emails found.');
// echo "Good addresses: $gc\n";
// echo "Bad addresses: $bc\n";
// echo join("\n", $bad);
// echo "\n";
}
}