CRM-14043 - cid=0 contribution form giving contribution to logged in user
[civicrm-core.git] / tests / phpunit / WebTest / Activity / IcalTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
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
a83651da 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;
6a488035 36
a83651da 37 protected function setUp() {
38 parent::setUp();
39 }
6a488035 40
a83651da 41 function testStandaloneActivityAdd() {
42 $this->webtestLogin();
6a488035 43
a83651da 44 $this->openCivipage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics");
6a488035 45
a83651da 46 // Notify assignees should be checked by default, so we just need to click the ical setting which is off by default.
47 $this->check("name=activity_assignee_notification_ics");
48 $this->click("_qf_Display_next");
49 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035 50
a83651da 51 // Start spooling emails
52 $mailer = new CiviMailUtils($this, TRUE);
53 self::$foundIt = FALSE;
6a488035 54
a83651da 55 $firstName1 = substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
6a488035 57
a83651da 58 $this->openCivipage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
6a488035 59
a83651da 60 $this->select("activity_type_id", "value=1");
6a488035 61
a83651da 62 $this->click("token-input-assignee_contact_id");
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
66 sleep(1);
67 $this->type("token-input-assignee_contact_id", "$firstName1");
68 $this->typeKeys("token-input-assignee_contact_id", "$firstName1");
6a488035 69
a83651da 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");
6a488035 74
a83651da 75 $subject = "Testing Ical attachment for activity assignee";
76 $this->type("subject", $subject);
6a488035 77
a83651da 78 $location = 'Some location needs to be put in this field.';
79 $this->type("location", $location);
6a488035 80
a83651da 81 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
82 $this->select("status_id", "value=1");
6a488035 83
a83651da 84 $this->click("_qf_Activity_upload");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035 86
a83651da 87 $this->waitForText('crm-notification-container', $subject);
6a488035 88
a83651da 89 // check the resulting email
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 95
a83651da 96 $mailer->stop();
6a488035 97
a83651da 98 $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.'));
99 }
6a488035 100
a83651da 101 public static function mailWalkCallback($context, $mailPart) {
76e86fd8 102
a83651da 103 $disp = $mailPart->contentDisposition;
104 if ($disp) {
105 if ($disp->disposition == 'attachment') {
106 if ($mailPart instanceof ezcMailText) {
107 if ($mailPart->subType == 'calendar') {
108 // For now we just check for existence.
109 self::$foundIt = TRUE;
a83651da 110 }
6a488035 111 }
a83651da 112 }
6a488035 113 }
a83651da 114 }
6a488035
TO
115}
116