Merge pull request #12003 from vinuvarshith/dev/core/69-fix-state-province-name-token...
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / SpoolTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 require_once 'CiviTest/CiviMailUtils.php';
29
30 /**
31 * Class WebTest_Mailing_SpoolTest
32 */
33 class WebTest_Mailing_SpoolTest extends CiviSeleniumTestCase {
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 public function testSpooledMailing() {
40 $this->markTestSkipped('Skipping for now as it works fine locally.');
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 $cid = $this->urlArg('cid');
53
54 // Send an email to the added contact
55 $this->openCiviPage("activity/email/add", "action=add&reset=1&cid={$cid}&selectedChild=activity&atype=3");
56 $this->type('subject', 'test spool');
57 $this->fillRichTextField('html_message', 'Unit tests keep children safe.');
58 $this->click("_qf_Email_upload");
59
60 // Retrieve an ezc mail object version of the email
61 $msg = $mut->getMostRecentEmail('ezc');
62
63 $this->assertNotEmpty($msg, 'Mail message empty or not found.');
64 $this->assertEquals($msg->subject, 'test spool');
65 // should really walk through the 'to' array, but this is legal according to the docs
66 $this->assertContains($email, implode(';', $msg->to), 'Recipient incorrect.');
67
68 $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
69 $msg->walkParts($context, $msg);
70
71 /*
72 * Now try a regular activity with cc to assignee
73 */
74 $this->WebtestAddActivity();
75 $msg = $mut->getMostRecentEmail('raw');
76 $this->assertNotEmpty($msg, 'Mail message empty or not found.');
77 $this->assertContains('Subject: This is subject of test activity', $msg, 'Subject of email is wrong.');
78
79 $mut->stop();
80 }
81
82 /**
83 * @param $context
84 * @param $mailPart
85 */
86 public static function mailWalkCallback($context, $mailPart) {
87 if ($mailPart instanceof ezcMailText) {
88 self::assertEquals($mailPart->subType, 'html');
89 self::assertContains('Unit tests keep children safe', $mailPart->generateBody());
90 }
91
92 $disp = $mailPart->contentDisposition;
93 if ($disp) {
94
95 }
96 }
97
98 }