Merge pull request #7313 from JKingsnorth/CRM-17625
[civicrm-core.git] / tests / phpunit / WebTest / Activity / IcalTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 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
4cbe18b8
EM
32/**
33 * Class WebTest_Activity_IcalTest
34 */
6a488035
TO
35class WebTest_Activity_IcalTest extends CiviSeleniumTestCase {
36
a83651da 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;
6a488035 39
a83651da 40 protected function setUp() {
41 parent::setUp();
42 }
6a488035 43
00be9182 44 public function testStandaloneActivityAdd() {
a83651da 45 $this->webtestLogin();
6a488035 46
59843a57 47 $this->openCiviPage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics");
6a488035 48
a83651da 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());
6a488035 53
a83651da 54 // Start spooling emails
55 $mailer = new CiviMailUtils($this, TRUE);
56 self::$foundIt = FALSE;
6a488035 57
a83651da 58 $firstName1 = substr(sha1(rand()), 0, 7);
59 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
6a488035 60
59843a57 61 $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
6a488035 62
a83651da 63 $this->select("activity_type_id", "value=1");
6a488035 64
cba9346d 65 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
a83651da 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);
cba9346d 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);
6a488035 73
cba9346d 74 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
75 $this->clickAt("xpath=//div[@class='select2-result-label']");
6c6e6187 76 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$firstName1");
6a488035 77
a83651da 78 $subject = "Testing Ical attachment for activity assignee";
79 $this->type("subject", $subject);
6a488035 80
a83651da 81 $location = 'Some location needs to be put in this field.';
82 $this->type("location", $location);
6a488035 83
a83651da 84 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
85 $this->select("status_id", "value=1");
6a488035 86
a83651da 87 $this->click("_qf_Activity_upload");
88 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035 89
a83651da 90 $this->waitForText('crm-notification-container', $subject);
6a488035 91
a83651da 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);
6a488035 98
a83651da 99 $mailer->stop();
6a488035 100
a83651da 101 $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.'));
102 }
6a488035 103
4cbe18b8
EM
104 /**
105 * @param $context
106 * @param $mailPart
107 */
a83651da 108 public static function mailWalkCallback($context, $mailPart) {
76e86fd8 109
a83651da 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;
a83651da 117 }
6a488035 118 }
a83651da 119 }
6a488035 120 }
a83651da 121 }
96025800 122
6a488035 123}