Commit | Line | Data |
---|---|---|
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | require_once 'CiviTest/CiviMailUtils.php'; | |
6a488035 | 29 | |
4cbe18b8 EM |
30 | /** |
31 | * Class WebTest_Activity_IcalTest | |
32 | */ | |
6a488035 TO |
33 | class WebTest_Activity_IcalTest extends CiviSeleniumTestCase { |
34 | ||
a83651da | 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; | |
6a488035 | 37 | |
a83651da | 38 | protected function setUp() { |
39 | parent::setUp(); | |
40 | } | |
6a488035 | 41 | |
00be9182 | 42 | public function testStandaloneActivityAdd() { |
a83651da | 43 | $this->webtestLogin(); |
6a488035 | 44 | |
59843a57 | 45 | $this->openCiviPage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics"); |
6a488035 | 46 | |
a83651da | 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()); | |
6a488035 | 51 | |
a83651da | 52 | // Start spooling emails |
53 | $mailer = new CiviMailUtils($this, TRUE); | |
54 | self::$foundIt = FALSE; | |
6a488035 | 55 | |
a83651da | 56 | $firstName1 = substr(sha1(rand()), 0, 7); |
57 | $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com"); | |
6a488035 | 58 | |
59843a57 | 59 | $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload"); |
6a488035 | 60 | |
a83651da | 61 | $this->select("activity_type_id", "value=1"); |
6a488035 | 62 | |
cba9346d | 63 | $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input"); |
a83651da | 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); | |
cba9346d | 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); | |
6a488035 | 71 | |
cba9346d | 72 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
73 | $this->clickAt("xpath=//div[@class='select2-result-label']"); | |
6c6e6187 | 74 | $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$firstName1"); |
6a488035 | 75 | |
a83651da | 76 | $subject = "Testing Ical attachment for activity assignee"; |
77 | $this->type("subject", $subject); | |
6a488035 | 78 | |
a83651da | 79 | $location = 'Some location needs to be put in this field.'; |
80 | $this->type("location", $location); | |
6a488035 | 81 | |
a83651da | 82 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); |
83 | $this->select("status_id", "value=1"); | |
6a488035 | 84 | |
a83651da | 85 | $this->click("_qf_Activity_upload"); |
86 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6a488035 | 87 | |
a83651da | 88 | $this->waitForText('crm-notification-container', $subject); |
6a488035 | 89 | |
a83651da | 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); | |
6a488035 | 96 | |
a83651da | 97 | $mailer->stop(); |
6a488035 | 98 | |
a83651da | 99 | $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.')); |
100 | } | |
6a488035 | 101 | |
4cbe18b8 EM |
102 | /** |
103 | * @param $context | |
104 | * @param $mailPart | |
105 | */ | |
a83651da | 106 | public static function mailWalkCallback($context, $mailPart) { |
76e86fd8 | 107 | |
a83651da | 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; | |
a83651da | 115 | } |
6a488035 | 116 | } |
a83651da | 117 | } |
6a488035 | 118 | } |
a83651da | 119 | } |
96025800 | 120 | |
6a488035 | 121 | } |