Merge pull request #11241 from mattwire/CRM-21392_find_groups_viewcomponents
[civicrm-core.git] / tests / phpunit / WebTest / Activity / StandaloneAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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_StandaloneAddTest
31 */
6a488035
TO
32class WebTest_Activity_StandaloneAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testStandaloneActivityAdd() {
6a488035
TO
39 $this->webtestLogin();
40
41 // Adding Anderson, Anthony and Summerson, Samuel for testStandaloneActivityAdd test
42 // We're using Quick Add block on the main page for this.
43 $firstName1 = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
45 $firstName2 = substr(sha1(rand()), 0, 7);
46 $this->webtestAddContact("$firstName2", "Summerson", $firstName2 . "@summerson.com");
47
bb21371e 48 $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
6a488035 49
6a488035
TO
50 // Select one of the options in Activity Type selector. Use option value, not label - since labels can be translated and test would fail
51 $this->select("activity_type_id", "value=1");
52
53 // We're filling in ajaxiefied "With Contact" field:
54 // We can not use id as selector for these input widgets. Use css selector, starting with the table row containing this field (which will have a unique class)
55 // Typing contact's name into the field (using typeKeys(), not type()!)...
cba9346d 56 $this->click("xpath=//div[@id='s2id_target_contact_id']/ul/li/input");
57 $this->keyDown("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", " ");
58 $this->type("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName1);
59 $this->typeKeys("xpath=//div[@id='s2id_target_contact_id']/ul/li/input", $firstName1);
6a488035
TO
60
61 // ...waiting for drop down with results to show up...
cba9346d 62 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
6a488035
TO
63
64 // ...need to use mouseDownAt on first result (which is a li element), click does not work
cba9346d 65 $this->clickAt("xpath=//div[@class='select2-result-label']");
6a488035
TO
66
67 // ...again, waiting for the box with contact name to show up (span with delete token class indicates that it's present)...
6c6e6187 68 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", "$firstName1");
6a488035
TO
69
70 //..and verifying if the page contains properly formatted display name for chosen contact.
cba9346d 71 $this->assertElementContainsText("xpath=//div[@id='s2id_target_contact_id']", "Anderson, $firstName1", 'Contact not found in line ' . __LINE__);
6a488035
TO
72
73 // Now we're doing the same for "Assigned To" field.
74 // Typing contact's name into the field (using typeKeys(), not type()!)...
cba9346d 75 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
76 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
77 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName2);
78 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName2);
6a488035
TO
79
80 // ...waiting for drop down with results to show up...
cba9346d 81 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
6a488035
TO
82
83 //..need to use mouseDownAt on first result (which is a li element), click does not work
cba9346d 84 $this->clickAt("xpath=//div[@class='select2-result-label']");
6a488035
TO
85
86 // ...again, waiting for the box with contact name to show up...
6c6e6187 87 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$firstName2");
6a488035
TO
88
89 // ...and verifying if the page contains properly formatted display name for chosen contact.
cba9346d 90 $this->assertElementContainsText("xpath=//div[@id='s2id_assignee_contact_id']", "Summerson, $firstName2", 'Contact not found in line ' . __LINE__);
6a488035
TO
91
92 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
93 $subject = "This is subject of test activity being added through standalone screen.";
94 // For simple input fields we can use field id as selector
95 $this->type("subject", $subject);
96
97 $location = 'Some location needs to be put in this field.';
98 $this->type("location", $location);
99
100 // Choosing the Date.
101 // Please note that we don't want to put in fixed date, since
102 // we want this test to work in the future and not fail because
103 // of date being set in the past. Therefore, using helper webtestFillDate function.
104 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
105
106 // Setting duration.
107 $this->type("duration", "30");
108
109 // Putting in details.
110 $this->type("details", "Really brief details information.");
111
112 // Making sure that status is set to Scheduled (using value, not label).
113 $this->select("status_id", "value=1");
114
115 // Setting priority.
116 $this->select("priority_id", "value=1");
117
118 // Adding attachment
6a488035
TO
119 //FIX ME: need to fix file uploading
120 //$this->waitForElementPresent("attachFile_1");
121 //$filePath = $this->webtestAttachFile( "attachFile_1" );
122
123 // Scheduling follow-up.
124 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
125 $this->select("followup_activity_type_id", "value=1");
126 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
127 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
128
129 // Clicking save.
35c48e1a 130 $this->clickLink('_qf_Activity_upload');
6a488035
TO
131
132 // Is status message correct?
35c48e1a 133 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.");
6a488035 134
bb21371e 135 $this->openCiviPage("activity/search", "reset=1", "_qf_Search_refresh");
6a488035
TO
136
137 $this->type("sort_name", $firstName1);
138 $this->click("_qf_Search_refresh");
6a488035 139
74210507
RK
140 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[6]/a[text()='Summerson, $firstName2']/../../td[9]/span/a[text()='View']");
141 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[6]/a[text()='Summerson, $firstName2']/../../td[9]/span/a[text()='View']");
142 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
6a488035 143
1d4d99e9 144 $this->VerifyTabularData(
6a488035
TO
145 array(
146 'Subject' => $subject,
147 'Location' => $location,
cba9346d 148 'Activity Status' => 'Scheduled',
6a488035
TO
149 'Duration' => '30',
150 // Tough luck filling in WYSIWYG editor, so skipping verification for now.
151 //'Details' => 'Really brief details information.',
152 'Priority' => 'Urgent',
153 //'Current Attachment(s)' => basename($filePath)
154 ),
155 "/label"
156 );
157
1d4d99e9 158 $this->VerifyTabularData(
6a488035
TO
159 array(
160 'With Contact' => "Anderson, {$firstName1}",
3bd48a28 161 'Assigned to' => "Summerson, {$firstName2}",
cba9346d 162 ),
163 "/label"
6a488035 164 );
e7b3275b 165
166 //CRM-17395 -- Test Activity Report for Target Contact Filter
167 $this->openCiviPage('report/instance/3', 'reset=1', '_qf_Activity_submit');
168 $this->click("//a[contains(text(),'Filters')]");
169 $this->waitForElementPresent('contact_target_value');
170 $this->select('activity_date_time_relative', '- any -');
171 $this->type('contact_target_value', $firstName1);
172 $this->clickLink('_qf_Activity_submit');
173 $this->assertElementContainsText("//table[@class='report-layout display']/tbody/tr//td[@class='crm-report-civicrm_contact_contact_target']/a", "Anderson, {$firstName1}");
6a488035 174 }
6a488035 175
00be9182 176 public function testAjaxCustomGroupLoad() {
c4e6d4e8
PJ
177 $this->webtestLogin();
178 $triggerElement = array('name' => 'activity_type_id', 'type' => 'select');
179 $customSets = array(
180 array('entity' => 'Activity', 'subEntity' => 'Interview', 'triggerElement' => $triggerElement),
21dfd5f5 181 array('entity' => 'Activity', 'subEntity' => 'Meeting', 'triggerElement' => $triggerElement),
c4e6d4e8
PJ
182 );
183
184 $pageUrl = array('url' => 'activity', 'args' => 'reset=1&action=add&context=standalone');
185 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
186 }
1d4d99e9 187
4cbe18b8
EM
188 /**
189 * @param $expected
190 * @param null $xpathPrefix
191 */
00be9182 192 public function VerifyTabularData($expected, $xpathPrefix = NULL) {
1d4d99e9 193 foreach ($expected as $label => $value) {
6c6e6187 194 $this->waitForElementPresent("xpath=//table/tbody/tr/td{$xpathPrefix}[text()='{$label}']/../following-sibling::td/span");
ba4a1892 195 $this->verifyText("xpath=//table/tbody/tr/td{$xpathPrefix}[text()='{$label}']/../following-sibling::td/span", preg_quote($value));
1d4d99e9 196 }
197 }
96025800 198
a0e606b3
DG
199 /**
200 * CRM-17656 - Test Activity using Custom Data
201 */
202 public function testActivityCustomData() {
203 $this->webtestLogin();
204
205 // Create new Custom Field Set
206 $this->openCiviPage('admin/custom/group', 'reset=1');
207 $this->click("css=#newCustomDataGroup > span");
208 $this->waitForElementPresent('_qf_Group_next-bottom');
209 $customFieldSet = 'ActivityFieldset' . rand();
210 $this->type("id=title", $customFieldSet);
211 $this->select("id=extends_0", "label=Activities");
212 $this->addSelection("extends_1", "- Any -");
213 $this->click("id=collapse_display");
214 $this->clickLink("id=_qf_Group_next-bottom");
215 $this->waitForText('crm-notification-container', "Your custom field set '$customFieldSet' has been added.");
216 $this->waitForElementPresent('_qf_Field_done-bottom');
217
218 // Add field to fieldset
219 $customField = 'TestCustomField' . rand();
220 $this->type("id=label", $customField);
221 $this->select("id=data_type_0", "value=0");
222 $this->click("is_required");
223 $this->click("id=_qf_Field_done-bottom");
224 $this->waitForText('crm-notification-container', "Custom field '$customField' has been saved.");
225 $textFieldId = explode('&id=', $this->getAttribute("xpath=//table[@id='options']/tbody//tr/td[1]/div[text()='$customField']/../../td[8]/span/a[1][text()='Edit Field']/@href"));
226 $textFieldId = $textFieldId[1];
227
228 $fname = substr(sha1(rand()), 0, 7);
229 $this->webtestAddContact("$fname", "Anderson", $fname . "@anderson.com");
230
231 $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
232 $this->select("activity_type_id", "value=1");
233 $this->select2('target_contact_id', $fname, TRUE);
234 $subject = "This is subject of test activity being added through standalone screen.";
235 $this->type("subject", $subject);
236 $textField = 'This is test custom data';
237 $this->type("custom_{$textFieldId}_-1", $textField);
238 // Clicking save.
239 $this->clickLink('_qf_Activity_upload');
240 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.");
241
242 $this->openCiviPage("activity/search", "reset=1", "_qf_Search_refresh");
243 $this->type("sort_name", $fname);
244 $this->click("_qf_Search_refresh");
245
246 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[5]/a[text()='Anderson, {$fname}']/../../td[9]/span/a[text()='View']");
247 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[5]/a[text()='Anderson, {$fname}']/../../td[9]/span/a[text()='View']");
248 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
249
250 $this->VerifyTabularData(
251 array(
252 'Subject' => $subject,
253 'Activity Status' => 'Scheduled',
254 ),
255 "/label"
256 );
257 $this->verifyText("xpath=//td[text()='{$customField}']/following-sibling::td", preg_quote($textField), 'In line ' . __LINE__);
258
259 $this->clickAjaxLink("xpath=//button//span[contains(text(),'Edit')]", "xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[contains(text(),'Save')]");
260
261 $editedTextField = 'This is test custom data - Edited';
262 $this->type("custom_{$textFieldId}_1", $editedTextField);
263 $this->clickAjaxLink("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[contains(text(),'Save')]", "xpath=//button//span[contains(text(),'Edit')]");
264 $this->verifyText("xpath=//td[text()='{$customField}']/following-sibling::td", preg_quote($editedTextField), 'In line ' . __LINE__);
265 }
266
232624b1 267}