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