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 | ||
40 | $this->open($this->sboxPath); | |
41 | $this->webtestLogin(); | |
42 | ||
43 | // Start spooling mail | |
44 | $mut = new CiviMailUtils( $this, true ); | |
45 | ||
46 | // Add a contact | |
47 | $fname = substr(sha1(rand()), 0, 6); | |
48 | $lname = substr(sha1(rand()), 0, 6); | |
49 | $email = $this->webtestAddContact($fname, $lname, TRUE); | |
50 | ||
51 | // Get the contact id of the newly added contact | |
52 | $urlElements = $this->parseURL(); | |
53 | $cid = $urlElements['queryString']['cid']; | |
54 | $this->assertNotEmpty( $cid, 'Could not find cid after adding contact' ); | |
55 | ||
56 | // Send an email to the added contact | |
57 | $this->open( $this->sboxPath . 'civicrm/activity/email/add?action=add&reset=1&cid=' . $cid . '&selectedChild=activity&atype=3' ); | |
58 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
59 | $this->type( 'subject', 'test spool' ); | |
60 | $this->fillRichTextField( 'html_message', 'Unit tests keep children safe.' ); | |
61 | $this->click( "_qf_Email_upload" ); | |
62 | ||
63 | // Retrieve an ezc mail object version of the email | |
64 | $msg = $mut->getMostRecentEmail( 'ezc' ); | |
65 | // print_r($msg); | |
66 | ||
67 | $this->assertNotEmpty( $msg, 'Mail message empty or not found.' ); | |
68 | $this->assertEquals( $msg->subject, 'test spool' ); | |
69 | $this->assertContains( $email, implode(';', $msg->to), 'Recipient incorrect.' ); // should really walk through the 'to' array, but this is legal according to the docs | |
70 | ||
71 | $context = new ezcMailPartWalkContext( array( get_class($this), 'mailWalkCallback' ) ); | |
72 | $msg->walkParts( $context, $msg ); | |
73 | ||
74 | /* | |
75 | * Now try a regular activity with cc to assignee | |
76 | */ | |
77 | $this->WebtestAddActivity(); | |
78 | $msg = $mut->getMostRecentEmail( 'raw' ); | |
79 | // echo $msg; | |
80 | $this->assertNotEmpty( $msg, 'Mail message empty or not found.' ); | |
81 | $this->assertContains( 'Subject: This is subject of test activity', $msg, 'Subject of email is wrong.' ); | |
82 | ||
83 | $mut->stop(); | |
84 | } | |
85 | ||
86 | public static function mailWalkCallback( $context, $mailPart ) { | |
87 | // print_r($mailPart); | |
88 | if ( $mailPart instanceof ezcMailText ) { | |
89 | self::assertEquals( $mailPart->subType, 'html' ); | |
90 | self::assertContains( 'Unit tests keep children safe', $mailPart->generateBody() ); | |
91 | } | |
92 | ||
93 | $disp = $mailPart->contentDisposition; | |
94 | if ( $disp ) { | |
95 | // print_r($disp); | |
96 | } | |
97 | } | |
98 | } |