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