Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | ||
27 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | require_once 'CiviTest/CiviMailUtils.php'; | |
30 | require_once 'ezc/Base/src/ezc_bootstrap.php'; | |
31 | require_once 'ezc/autoload/mail_autoload.php'; | |
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 | ||
39 | protected function setUp() { | |
40 | parent::setUp(); | |
41 | } | |
42 | ||
43 | function testStandaloneActivityAdd() { | |
6a488035 TO |
44 | $this->webtestLogin(); |
45 | ||
bb21371e | 46 | $this->openCivipage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics"); |
6a488035 TO |
47 | |
48 | // Notify assignees should be checked by default, so we just need to click the ical setting which is off by default. | |
bb21371e | 49 | $this->check("name=activity_assignee_notification_ics"); |
6a488035 TO |
50 | $this->click("_qf_Display_next"); |
51 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
52 | ||
53 | // Start spooling emails | |
42daf119 | 54 | $mailer = new CiviMailUtils($this, true); |
6a488035 TO |
55 | self::$foundIt = false; |
56 | ||
57 | $firstName1 = substr(sha1(rand()), 0, 7); | |
58 | $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com"); | |
59 | ||
bb21371e | 60 | $this->openCivipage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload"); |
6a488035 TO |
61 | |
62 | $this->select("activity_type_id", "value=1"); | |
63 | ||
42daf119 | 64 | $this->click("token-input-assignee_contact_id"); |
efb29358 CW |
65 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
66 | // Sleep should never be used for wait for anything to load from the server | |
67 | // Justification for this instance: tokeninput has a slight delay | |
42daf119 CW |
68 | sleep(1); |
69 | $this->type("token-input-assignee_contact_id", "$firstName1"); | |
70 | $this->typeKeys("token-input-assignee_contact_id", "$firstName1"); | |
6a488035 TO |
71 | |
72 | $this->waitForElementPresent("css=div.token-input-dropdown-facebook"); | |
73 | $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook"); | |
74 | $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook"); | |
75 | $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook"); | |
76 | ||
77 | $subject = "Testing Ical attachment for activity assignee"; | |
78 | $this->type("subject", $subject); | |
79 | ||
80 | $location = 'Some location needs to be put in this field.'; | |
81 | $this->type("location", $location); | |
82 | ||
83 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
84 | $this->select("status_id", "value=1"); | |
85 | ||
86 | $this->click("_qf_Activity_upload"); | |
87 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
88 | ||
bb21371e | 89 | $this->assertElementContainsText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!"); |
6a488035 TO |
90 | |
91 | // check the resulting email | |
92 | $mail = $mailer->getMostRecentEmail( 'ezc' ); | |
93 | $this->assertNotNull( $mail, ts('Assignee email not generated or problem locating it.') ); | |
94 | $this->assertEquals( $mail->subject, "$subject" ); | |
95 | $context = new ezcMailPartWalkContext( array( get_class($this), 'mailWalkCallback' ) ); | |
96 | $mail->walkParts( $context, $mail ); | |
97 | ||
98 | $mailer->stop(); | |
99 | ||
100 | $this->assertTrue( self::$foundIt, ts('Generated email does not contain an ical attachment.') ); | |
101 | } | |
102 | ||
103 | public static function mailWalkCallback( $context, $mailPart ) { | |
104 | // echo "Class: " . get_class($mailPart) . "\n"; | |
105 | $disp = $mailPart->contentDisposition; | |
106 | if ( $disp ) { | |
107 | if ( $disp->disposition == 'attachment' ) { | |
108 | if ( $mailPart instanceof ezcMailText ) { | |
109 | if ( $mailPart->subType == 'calendar' ) { | |
110 | // For now we just check for existence. | |
111 | self::$foundIt = true; | |
112 | ||
113 | // echo $mailPart->generateBody() . "\n"; | |
114 | } | |
115 | } | |
116 | } | |
117 | } | |
118 | } | |
119 | } | |
120 |