source: trunk/tests/EmailTest.php

Last change on this file was 653, checked in by anonymous, 5 years ago

Update fancyTxt()

File size: 4.1 KB
Line 
1<?php
2
3/**
4 * The Strangecode Codebase - a general application development framework for PHP
5 * For details visit the project site: <http://trac.strangecode.com/codebase/>
6 * Copyright 2001-2012 Strangecode, LLC
7 *
8 * This file is part of The Strangecode Codebase.
9 *
10 * The Strangecode Codebase is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by the
12 * Free Software Foundation, either version 3 of the License, or (at your option)
13 * any later version.
14 *
15 * The Strangecode Codebase is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/**
25 * PHPUnit test case for codebase/lib/Email.inc.php
26 *
27 * The method skeletons below need to be filled in with
28 * real data so that the tests will run correctly. Replace
29 * all EXPECTED_VAL and PARAM strings with real data.
30 *
31 * Created with PHPUnit_Skeleton on 2005-12-01
32 */
33
34class EmailTest extends PHPUnit_Framework_TestCase {
35
36    var $Email;
37
38    function setUp()
39    {
40        require dirname(__FILE__) . '/_config.inc.php';
41        require_once '../lib/Email.inc.php';
42        $this->Email = new Email();
43    }
44
45    function tearDown()
46    {
47        unset($this->Email);
48    }
49
50//     function testsetparam()
51//     {
52//         $result   = $this->Email->setparam(PARAM);
53//         $expected = EXPECTED_VAL;
54//         $this->assertEquals($expected, $result);
55//     }
56//
57//     function testgetparam()
58//     {
59//         $result   = $this->Email->getparam(PARAM);
60//         $expected = EXPECTED_VAL;
61//         $this->assertEquals($expected, $result);
62//     }
63//
64//     function testsettemplate()
65//     {
66//         $result   = $this->Email->settemplate(PARAM);
67//         $expected = EXPECTED_VAL;
68//         $this->assertEquals($expected, $result);
69//     }
70//
71//     function testsetstring()
72//     {
73//         $result   = $this->Email->setstring(PARAM);
74//         $expected = EXPECTED_VAL;
75//         $this->assertEquals($expected, $result);
76//     }
77//
78//     function testreplace()
79//     {
80//         $result   = $this->Email->replace(PARAM);
81//         $expected = EXPECTED_VAL;
82//         $this->assertEquals($expected, $result);
83//     }
84//
85    function testsend()
86    {
87
88        $this->Email = new Email(array(
89            'to' => 'Rob Recipient <to@example.com>',
90            'from' => 'Sam Sender <from@example.com>',
91            'subject' => 'EmailTest',
92            'headers' => array(
93                'CC' => 'This header removed in REDIRECT sandbox mode <remove-me@example.com>',
94                'X-Hello' => 'Hi there',
95            ),
96            'sandbox_mode' => Email::SANDBOX_MODE_REDIRECT,
97            'sandbox_to_addr' => 'quinn@strangecode.com',
98        ));
99        $this->Email->setString('This is a {TEST}');
100        $this->Email->replace(array(
101            'test' => '– you guessed it – a test! Sent from ' . __FILE__
102        ));
103        $result   = $this->Email->send();
104        $expected = true;
105        $this->assertEquals($expected, $result);
106    }
107
108    function testvalidemail()
109    {
110        $testpool = file('_email_test_addresses.txt');
111
112        $gc = 0;
113        $bc = 0;
114        $good = array();
115        $bad = array();
116        if (is_array($testpool) && !empty($testpool)) {
117            foreach ($testpool as $a) {
118                if ($this->Email->validEmail($a)) {
119                    $good[] = trim($a);
120                    $gc++;
121                } else {
122                    $bad[] = trim($a);
123                    $bc++;
124                }
125            }
126        }
127        $this->assertEquals(45, $gc, 'Unexpected number of valid emails found.');
128        $this->assertEquals(45, $bc, 'Unexpected number of invalid emails found.');
129        // echo "Good addresses: $gc\n";
130        // echo "Bad addresses: $bc\n";
131        // echo join("\n", $bad);
132        // echo "\n";
133    }
134
135}
Note: See TracBrowser for help on using the repository browser.