Merge pull request #4375 from totten/master-mysqli-compat
[civicrm-core.git] / tests / phpunit / WebTest / Activity / ContactContextAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Activity_ContactContextAddTest
31 */
32 class WebTest_Activity_ContactContextAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testContactContextActivityAdd() {
39 $this->webtestLogin();
40
41 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
42 // We're using Quick Add block on the main page for this.
43 $firstName1 = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
45 $firstName2 = substr(sha1(rand()), 0, 7);
46 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
47
48 $this->click("css=li#tab_activity a");
49
50 // waiting for the activity dropdown to show up
51 $this->waitForElementPresent("other_activity");
52
53 // Select the activity type from the activity dropdown
54 $this->select("other_activity", "label=Meeting");
55
56 // button at the end of this page to show up, to make sure it's fully loaded.
57 $this->waitForElementPresent("_qf_Activity_upload");
58
59 // ...and verifying if the page contains properly formatted display name for chosen contact.
60 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", 'Anderson, ' . $firstName2);
61
62 // Now we're filling the "Assigned To" field.
63 // Typing contact's name into the field (using typeKeys(), not type()!)...
64 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
65 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
66 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
67 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
68
69 // ...waiting for drop down with results to show up...
70 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
71
72 // ...need to use mouseDownAt on first result (which is a li element), click does not work
73 $this->clickAt("xpath=//div[@class='select2-result-label']");
74
75 // ...again, waiting for the box with contact name to show up...
76 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']","$firstName1");
77
78 // ...and verifying if the page contains properly formatted display name for chosen contact.
79 $this->assertElementContainsText("xpath=//div[@id='s2id_assignee_contact_id']", "Summerson, $firstName1", 'Contact not found in line ' . __LINE__);
80
81 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
82 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
83 // For simple input fields we can use field id as selector
84 $this->type("subject", $subject);
85 $this->type("location", "Some location needs to be put in this field.");
86
87 // Choosing the Date.
88 // Please note that we don't want to put in fixed date, since
89 // we want this test to work in the future and not fail because
90 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
91 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
92
93 // Setting duration.
94 $this->type("duration", "30");
95
96 // Putting in details.
97 $this->type("details", "Really brief details information.");
98
99 // Making sure that status is set to Scheduled (using value, not label).
100 $this->select("status_id", "value=1");
101
102 // Setting priority.
103 $this->select("priority_id", "value=1");
104
105 // Adding attachment
106 // TODO TBD
107
108 // Scheduling follow-up.
109 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
110 $this->select("followup_activity_type_id", "value=1");
111 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
112 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
113
114 // Clicking save.
115 $this->click("_qf_Activity_upload");
116
117 // Is status message correct?
118 $this->waitForText('crm-notification-container', $subject);
119
120 $this->waitForElementPresent(
121 "xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']//tbody//tr[2]/td[8]/span/a[text()='View']");
122
123 // click through to the Activity view screen
124 $this->click("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']//tbody//tr[2]/td[8]/span/a[text()='View']");
125 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
126
127 // verify Activity created
128 $this->webtestVerifyTabularData(
129 array(
130 'Subject' => $subject,
131 'Location' => 'Some location needs to be put in this field.',
132 'Activity Status' => 'Scheduled',
133 'Duration' => '30',
134 // Tough luck filling in WYSIWYG editor, so skipping verification for now.
135 //'Details' => 'Really brief details information.',
136 'Priority' => 'Urgent',
137 ),
138 "/label"
139 );
140
141 $this->webtestVerifyTabularData(
142 array(
143 'With Contact' => "Anderson, {$firstName2}",
144 'Assigned to' => "Summerson, {$firstName1}",
145 ),
146 "/label"
147 );
148 }
149
150 function testSeparateActivityForMultiTargetContacts() {
151 $this->webtestLogin();
152
153 //creating contacts
154 $firstName1 = substr(sha1(rand()), 0, 7);
155 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
156 $firstName2 = substr(sha1(rand()), 0, 7);
157 $this->webtestAddContact($firstName2, "Andersonnn", $firstName2 . "@anderson.name");
158 $firstName3 = substr(sha1(rand()), 0, 7);
159 $this->webtestAddContact($firstName3, "Anderson", $firstName3 . "@andersonnn.name");
160
161 $this->click("css=li#tab_activity a");
162
163 // waiting for the activity dropdown to show up
164 $this->waitForElementPresent("other_activity");
165
166 // Select the activity type from the activity dropdown
167 $this->select("other_activity", "label=Meeting");
168
169 // ...and verifying if the page contains properly formatted display name for chosen contact.
170 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", 'Anderson, ' . $firstName3, 'Contact not found in line ' . __LINE__);
171
172 //filling the second target Contact
173 $this->click("xpath=//div[@id='s2id_target_contact_id']/ul/li/input");
174 $this->keyDown("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", " ");
175 $this->type("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName1);
176 $this->typeKeys("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName1);
177
178 // ...waiting for drop down with results to show up...
179 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
180
181 // ...need to use mouseDownAt on first result (which is a li element), click does not work
182 $this->clickAt("xpath=//div[@class='select2-result-label']");
183
184
185 // ...and verifying if the page contains properly formatted display name for chosen contact.
186 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", "$firstName1", 'Contact not found in line ' . __LINE__);
187
188 //filling the third target contact
189 $this->click("xpath=//div[@id='s2id_target_contact_id']/ul/li/input");
190 $this->keyDown("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", " ");
191 $this->type("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName2);
192 $this->typeKeys("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName2);
193
194 // ...waiting for drop down with results to show up...
195 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
196
197 // ...need to use mouseDownAt on first result (which is a li element), click does not work
198 $this->clickAt("xpath=//div[@class='select2-result-label']");
199
200
201 // ...and verifying if the page contains properly formatted display name for chosen contact.
202 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", "$firstName2", 'Contact not found in line ' . __LINE__);
203
204 //check the checkbox to create a separate activity for the selected target contacts
205 $this->check('is_multi_activity');
206
207 $subject = "This is subject of test activity for creating a separate activity for contacts {$firstName1},{$firstName2} and {$firstName3}.";
208 $this->type("subject", $subject);
209
210 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
211 $this->select("status_id", "value=1");
212
213 // Clicking save.
214 $this->click('_qf_Activity_upload');
215
216 // Is status message correct?
217 $this->waitForText('crm-notification-container', $subject);
218
219 //activity search page
220 $this->openCiviPage('activity/search', 'reset=1');
221
222 $this->type('activity_subject', $subject);
223
224 $this->clickLink('_qf_Search_refresh');
225
226 $targetContacts = array("Summerson, ". $firstName1, "Andersonnn, ". $firstName2, "Anderson, ". $firstName3 );
227
228 //check whether separate activities are created for the target contacts
229 foreach ($targetContacts as $contact) {
230 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody//tr/td[5]/a[text()='$contact']"));
231 }
232 }
233 }
234