commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / WebTest / Activity / IcalTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'ezc/Base/src/ezc_bootstrap.php';
30 require_once 'ezc/autoload/mail_autoload.php';
31
32 /**
33 * Class WebTest_Activity_IcalTest
34 */
35 class WebTest_Activity_IcalTest extends CiviSeleniumTestCase {
36
37 // 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.
38 private static $foundIt = FALSE;
39
40 protected function setUp() {
41 parent::setUp();
42 }
43
44 public function testStandaloneActivityAdd() {
45 $this->webtestLogin();
46
47 $this->openCiviPage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics");
48
49 // Notify assignees should be checked by default, so we just need to click the ical setting which is off by default.
50 $this->check("name=activity_assignee_notification_ics");
51 $this->click("_qf_Display_next");
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53
54 // Start spooling emails
55 $mailer = new CiviMailUtils($this, TRUE);
56 self::$foundIt = FALSE;
57
58 $firstName1 = substr(sha1(rand()), 0, 7);
59 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
60
61 $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
62
63 $this->select("activity_type_id", "value=1");
64
65 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
66 // Because it tends to cause problems, all uses of sleep() must be justified in comments
67 // Sleep should never be used for wait for anything to load from the server
68 // Justification for this instance: tokeninput has a slight delay
69 sleep(1);
70 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
71 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
72 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
73
74 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
75 $this->clickAt("xpath=//div[@class='select2-result-label']");
76 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$firstName1");
77
78 $subject = "Testing Ical attachment for activity assignee";
79 $this->type("subject", $subject);
80
81 $location = 'Some location needs to be put in this field.';
82 $this->type("location", $location);
83
84 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
85 $this->select("status_id", "value=1");
86
87 $this->click("_qf_Activity_upload");
88 $this->waitForPageToLoad($this->getTimeoutMsec());
89
90 $this->waitForText('crm-notification-container', $subject);
91
92 // check the resulting email
93 $mail = $mailer->getMostRecentEmail('ezc');
94 $this->assertNotNull($mail, ts('Assignee email not generated or problem locating it.'));
95 $this->assertEquals($mail->subject, "$subject");
96 $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
97 $mail->walkParts($context, $mail);
98
99 $mailer->stop();
100
101 $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.'));
102 }
103
104 /**
105 * @param $context
106 * @param $mailPart
107 */
108 public static function mailWalkCallback($context, $mailPart) {
109
110 $disp = $mailPart->contentDisposition;
111 if ($disp) {
112 if ($disp->disposition == 'attachment') {
113 if ($mailPart instanceof ezcMailText) {
114 if ($mailPart->subType == 'calendar') {
115 // For now we just check for existence.
116 self::$foundIt = TRUE;
117 }
118 }
119 }
120 }
121 }
122
123 }