whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Activity / IcalTest.php
CommitLineData
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
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28require_once 'CiviTest/CiviMailUtils.php';
29require_once 'ezc/Base/src/ezc_bootstrap.php';
30require_once 'ezc/autoload/mail_autoload.php';
31
32class WebTest_Activity_IcalTest extends CiviSeleniumTestCase {
33
34 // This variable is a bit awkward, but the ezc callback function needed to walk through the email parts needs to be static, so use this variable to "report back" on whether we found what we're looking for or not.
35 private static $foundIt = false;
36
6a488035
TO
37 protected function setUp() {
38 parent::setUp();
39 }
40
41 function testStandaloneActivityAdd() {
6a488035
TO
42 $this->webtestLogin();
43
bb21371e 44 $this->openCivipage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics");
6a488035
TO
45
46 // Notify assignees should be checked by default, so we just need to click the ical setting which is off by default.
bb21371e 47 $this->check("name=activity_assignee_notification_ics");
6a488035
TO
48 $this->click("_qf_Display_next");
49 $this->waitForPageToLoad($this->getTimeoutMsec());
50
51 // Start spooling emails
42daf119 52 $mailer = new CiviMailUtils($this, true);
6a488035
TO
53 self::$foundIt = false;
54
55 $firstName1 = substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
57
bb21371e 58 $this->openCivipage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
6a488035
TO
59
60 $this->select("activity_type_id", "value=1");
61
42daf119 62 $this->click("token-input-assignee_contact_id");
efb29358
CW
63 // Because it tends to cause problems, all uses of sleep() must be justified in comments
64 // Sleep should never be used for wait for anything to load from the server
65 // Justification for this instance: tokeninput has a slight delay
42daf119
CW
66 sleep(1);
67 $this->type("token-input-assignee_contact_id", "$firstName1");
68 $this->typeKeys("token-input-assignee_contact_id", "$firstName1");
6a488035
TO
69
70 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
71 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
72 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
73 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
74
75 $subject = "Testing Ical attachment for activity assignee";
76 $this->type("subject", $subject);
77
78 $location = 'Some location needs to be put in this field.';
79 $this->type("location", $location);
80
81 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
82 $this->select("status_id", "value=1");
83
84 $this->click("_qf_Activity_upload");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86
bb21371e 87 $this->assertElementContainsText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
6a488035
TO
88
89 // check the resulting email
76e86fd8
CW
90 $mail = $mailer->getMostRecentEmail('ezc');
91 $this->assertNotNull($mail, ts('Assignee email not generated or problem locating it.'));
92 $this->assertEquals($mail->subject, "$subject");
93 $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
94 $mail->walkParts($context, $mail);
6a488035
TO
95
96 $mailer->stop();
97
76e86fd8 98 $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.'));
6a488035
TO
99 }
100
76e86fd8
CW
101 public static function mailWalkCallback($context, $mailPart) {
102
6a488035 103 $disp = $mailPart->contentDisposition;
76e86fd8
CW
104 if ($disp) {
105 if ($disp->disposition == 'attachment') {
106 if ($mailPart instanceof ezcMailText) {
107 if ($mailPart->subType == 'calendar') {
6a488035
TO
108 // For now we just check for existence.
109 self::$foundIt = true;
110
6a488035
TO
111 }
112 }
113 }
114 }
115 }
116}
117