Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | require_once 'CiviTest/CiviMailUtils.php'; | |
30 | require_once 'ezc/Base/src/ezc_bootstrap.php'; | |
31 | require_once 'ezc/autoload/mail_autoload.php'; | |
32 | class WebTest_Mailing_SpoolTest extends CiviSeleniumTestCase { | |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testSpooledMailing() { | |
39 | ||
6a488035 TO |
40 | $this->webtestLogin(); |
41 | ||
42 | // Start spooling mail | |
43 | $mut = new CiviMailUtils( $this, true ); | |
44 | ||
45 | // Add a contact | |
46 | $fname = substr(sha1(rand()), 0, 6); | |
47 | $lname = substr(sha1(rand()), 0, 6); | |
48 | $email = $this->webtestAddContact($fname, $lname, TRUE); | |
49 | ||
50 | // Get the contact id of the newly added contact | |
51 | $urlElements = $this->parseURL(); | |
52 | $cid = $urlElements['queryString']['cid']; | |
53 | $this->assertNotEmpty( $cid, 'Could not find cid after adding contact' ); | |
54 | ||
55 | // Send an email to the added contact | |
acd28991 | 56 | $this->openCiviPage("activity/email/add", "action=add&reset=1&cid={$cid}&selectedChild=activity&atype=3"); |
6a488035 TO |
57 | $this->type( 'subject', 'test spool' ); |
58 | $this->fillRichTextField( 'html_message', 'Unit tests keep children safe.' ); | |
59 | $this->click( "_qf_Email_upload" ); | |
60 | ||
61 | // Retrieve an ezc mail object version of the email | |
62 | $msg = $mut->getMostRecentEmail( 'ezc' ); | |
63 | // print_r($msg); | |
64 | ||
65 | $this->assertNotEmpty( $msg, 'Mail message empty or not found.' ); | |
66 | $this->assertEquals( $msg->subject, 'test spool' ); | |
67 | $this->assertContains( $email, implode(';', $msg->to), 'Recipient incorrect.' ); // should really walk through the 'to' array, but this is legal according to the docs | |
68 | ||
69 | $context = new ezcMailPartWalkContext( array( get_class($this), 'mailWalkCallback' ) ); | |
70 | $msg->walkParts( $context, $msg ); | |
71 | ||
72 | /* | |
73 | * Now try a regular activity with cc to assignee | |
74 | */ | |
75 | $this->WebtestAddActivity(); | |
76 | $msg = $mut->getMostRecentEmail( 'raw' ); | |
77 | // echo $msg; | |
78 | $this->assertNotEmpty( $msg, 'Mail message empty or not found.' ); | |
79 | $this->assertContains( 'Subject: This is subject of test activity', $msg, 'Subject of email is wrong.' ); | |
80 | ||
81 | $mut->stop(); | |
82 | } | |
83 | ||
84 | public static function mailWalkCallback( $context, $mailPart ) { | |
85 | // print_r($mailPart); | |
86 | if ( $mailPart instanceof ezcMailText ) { | |
87 | self::assertEquals( $mailPart->subType, 'html' ); | |
88 | self::assertContains( 'Unit tests keep children safe', $mailPart->generateBody() ); | |
89 | } | |
90 | ||
91 | $disp = $mailPart->contentDisposition; | |
92 | if ( $disp ) { | |
93 | // print_r($disp); | |
94 | } | |
95 | } | |
96 | } |