Merge pull request #6515 from johanv/CRM-13725-duplicate_realtionships_check_custom_f...
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / SurveyUsageScenarioTest.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_Campaign_SurveyUsageScenarioTest
31 */
6a488035
TO
32class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testSurveyUsageScenario() {
42daf119 39 $this->webtestLogin('admin');
6a488035
TO
40
41 // Create new group
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
44
45 // Adding contact
46 $firstName1 = substr(sha1(rand()), 0, 7);
47 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
48
49 // add contact to group
50 // visit group tab
51 $this->click("css=li#tab_group a");
0caa4679 52 $this->waitForElementPresent("css=#group_id option");
6a488035
TO
53
54 // add to group
55 $this->select("group_id", "label=$groupName");
56 $this->click("_qf_GroupContact_next");
642aa483 57 $this->waitForElementPresent('link=Remove');
6a488035
TO
58
59 $firstName2 = substr(sha1(rand()), 0, 7);
60 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
61
62 // add contact to group
63 // visit group tab
64 $this->click("css=li#tab_group a");
0caa4679 65 $this->waitForElementPresent("css=#group_id option");
6a488035
TO
66
67 // add to group
68 $this->select("group_id", "label=$groupName");
69 $this->click("_qf_GroupContact_next");
642aa483 70 $this->waitForElementPresent('link=Remove');
6a488035 71
0bd37c06 72 // Enable CiviCampaign module if necessary
649c6141 73 $this->enableComponents(array('CiviCampaign'));
6a488035 74
42daf119 75 // add the required permission
0bd37c06 76 $this->changePermissions(array('edit-2-administer-civicampaign'));
6a488035 77
42daf119
CW
78 // Log in as normal user
79 $this->webtestLogin();
80
6a488035 81 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
9a24315b 82 $this->waitForElementPresent('title');
6a488035
TO
83 $this->type("title", "Campaign $title");
84
85 // select the campaign type
9a24315b 86 $this->waitForElementPresent('campaign_type_id');
6a488035
TO
87 $this->select("campaign_type_id", "value=2");
88
89 // fill in the description
90 $this->type("description", "This is a test campaign");
91
92 // include groups for the campaign
9a24315b 93 $this->addSelection("includeGroups", "label=$groupName");
6a488035 94 $this->click("//option[@value=4]");
6a488035
TO
95
96 // fill the end date for campaign
97 $this->webtestFillDate("end_date", "+1 year");
98
99 // select campaign status
100 $this->select("status_id", "value=2");
101
102 // click save
103 $this->click("_qf_Campaign_upload-bottom");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
105
6c5f7368 106 $this->waitForText('crm-notification-container', "$title");
6a488035
TO
107
108 // create a custom data set for activities -> survey
109 $this->openCiviPage('admin/custom/group', "action=add&reset=1", "_qf_Group_next-bottom");
110 // fill in a unique title for the custom group
111 $this->type("title", "Group $title");
112
113 // select the group this custom data set extends
114 $this->select("extends[0]", "value=Activity");
115 $this->waitForElementPresent("//select[@id='extends_1']");
116 $this->select("//select[@id='extends_1']", "label=Survey");
117
118 // save the custom group
119 $this->click("_qf_Group_next-bottom");
0bd37c06 120 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
121
122 // add a custom field to the custom group
9a24315b 123 $this->waitForElementPresent('label');
6a488035
TO
124 $this->type("label", "Field $title");
125
126 $this->select("data_type[1]", "value=Radio");
127
128 $this->waitForElementPresent("option_label_1");
129
130 // create a set of options
131 $this->type("option_label_1", "Option $title 1");
132 $this->type("option_value_1", "1");
133
134 $this->type("option_label_2", "Option $title 2");
135 $this->type("option_value_2", "2");
136
137 // save the custom field
9a24315b 138 $this->click("_qf_Field_done-bottom");
6a488035
TO
139
140 $this->waitForElementPresent("newCustomField");
6c5f7368 141 $this->waitForText('crm-notification-container', "$title");
6a488035
TO
142
143 // create a profile for campaign
144 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1", "_qf_Group_next-bottom");
145
146 // fill in a unique title for the profile
147 $this->type("title", "Profile $title");
148
149 // save the profile
150 $this->click("_qf_Group_next-bottom");
151
9a24315b
RK
152 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/div[2]/a/span");
153 $this->click("xpath=//div[@id='crm-main-content-wrapper']/div/div[2]/a/span");
6a488035
TO
154
155 // add a profile field for activity
9a24315b 156 $this->waitForElementPresent('field_name[0]');
6a488035
TO
157 $this->select("field_name[0]", "value=Activity");
158 $this->waitForElementPresent("field_name[1]");
159 $this->select("field_name[1]", "label=Field $title :: Group $title");
160
9a24315b
RK
161 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]");
162 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]");
6c5f7368 163 $this->waitForText('crm-notification-container', "$title");
6a488035
TO
164
165 // create a survey
166 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
167
168 // fill in a unique title for the survey
169 $this->type("title", "Survey $title");
170
171 // select the created campaign
172 $this->select("campaign_id", "label=Campaign $title");
173
174 // select the activity type
175 $this->select("activity_type_id", "label=Survey");
176
177 // fill in reserve survey respondents
178 $this->type("default_number_of_contacts", 50);
179
180 // fill in interview survey respondents
181 $this->type("max_number_of_contacts", 100);
182
183 // release frequency
184 $this->type("release_frequency", 2);
185
186 $this->click("_qf_Main_upload-bottom");
187 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
76e86fd8 188
0bd37c06 189 // Select the profile for the survey
6a488035
TO
190 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
191
76e86fd8
CW
192 // select the question created for the survey
193
6a488035
TO
194 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=Profile $title");
195 $this->click("_qf_Questions_upload_next-bottom");
196
197 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
198 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
199 $this->type("//input[@id='option_label_1']", "Label $title 1");
200 $this->type("//input[@id='option_value_1']", "1");
201
202 $this->type("//input[@id='option_label_2']", "Label $title 2");
203 $this->type("//input[@id='option_value_2']", "2");
204 $this->click('_qf_Results_upload_done-bottom');
205 $this->waitForElementPresent("//div[@id='search_form_survey']");
6c5f7368 206 $this->waitForText('crm-notification-container', "Results");
6a488035
TO
207
208 // Reserve Respondents
209 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
210
211 // search for the respondents
212 $this->select("campaign_survey_id", "label=Survey $title");
213
214 $this->click("_qf_Search_refresh");
9a24315b
RK
215 $this->waitForElementPresent('toggleSelect');
216 $this->click('toggleSelect');
642aa483 217 $this->select('task', "Reserve Respondents");
6a488035
TO
218
219 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
220 $this->click("_qf_Reserve_done_reserve-bottom");
221 $this->waitForPageToLoad($this->getTimeoutMsec());
0391e7ab 222 $this->waitForText('crm-notification-container', "2 contacts have been reserved.");
6a488035
TO
223
224 // Interview Respondents
225 $this->openCiviPage("survey/search", "reset=1&op=interview", "_qf_Search_refresh");
6a488035 226 // search for the respondents
9a24315b 227 $this->waitForElementPresent('campaign_survey_id');
6a488035 228 $this->select("campaign_survey_id", "label=Survey $title");
6a488035
TO
229 $this->click("_qf_Search_refresh");
230
9a24315b 231 $this->waitForElementPresent('toggleSelect');
952cc48f 232 $this->click("xpath=//table[@class='selector row-highlight']/thead/tr/th[1]/input[@id='toggleSelect']");
9a24315b 233 $this->select('task', "Record Survey Responses");
6a488035 234 $this->waitForElementPresent("_qf_Interview_cancel_interview");
952cc48f
WA
235 $this->select("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[1]/td[@class='result']/select", "value=Label $title 1");
236 $this->click("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[1]/td[8]/a");
6a488035 237
952cc48f
WA
238 $this->select("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[2]/td[@class='result']/select", "value=Label $title 2");
239 $this->click("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[2]/td[8]/a");
6a488035
TO
240 $this->click("_qf_Interview_cancel_interview");
241 $this->waitForPageToLoad($this->getTimeoutMsec());
242
243 // add a contact to the group to test release respondents
244 $firstName3 = substr(sha1(rand()), 0, 7);
245 $this->webtestAddContact($firstName3, "James", "$firstName3.james@example.org");
a471a3b6 246 $id = $this->urlArg('cid');
6a488035
TO
247 $sortName3 = "James, $firstName3";
248
249 // add contact to group
250 // visit group tab
251 $this->click("css=li#tab_group a");
0caa4679 252 $this->waitForElementPresent("css=#group_id option");
6a488035
TO
253
254 // add to group
255 $this->select("group_id", "label=$groupName");
256 $this->click("_qf_GroupContact_next");
642aa483 257 $this->waitForElementPresent('link=Remove');
6a488035
TO
258
259 // Reserve Respondents
260 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
261
262 // search for the respondents
263 $this->select("campaign_survey_id", "label=Survey $title");
264
265 $this->click("_qf_Search_refresh");
9a24315b
RK
266 $this->waitForElementPresent('toggleSelect');
267 $this->click('toggleSelect');
268 $this->waitForElementPresent('task');
642aa483 269 $this->select('task', "Reserve Respondents");
6a488035
TO
270 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
271 $this->click("_qf_Reserve_done_reserve-bottom");
0391e7ab 272 $this->waitForText('crm-notification-container', "1 contact has been reserved.");
6a488035
TO
273
274 // Release Respondents
275 $this->openCiviPage("survey/search", "reset=1&op=release", "_qf_Search_refresh");
276
277 // search for the respondents
278 $this->select("campaign_survey_id", "label=Survey $title");
279
280 $this->click("_qf_Search_refresh");
9a24315b
RK
281 $this->waitForElementPresent('toggleSelect');
282 $this->click('toggleSelect');
283 $this->waitForElementPresent('task');
642aa483 284 $this->select("task", "label=Release Respondents");
9a24315b
RK
285 $this->waitForElementPresent('_qf_Release_done-bottom');
286 $this->click("_qf_Release_done-bottom");
6c5f7368 287 $this->waitForText('crm-notification-container', "released");
6a488035
TO
288
289 // check whether contact is available for reserving again
290 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
291
292 // search for the respondents
293 $this->select("campaign_survey_id", "label=Survey $title");
294
9a24315b 295 $this->waitForElementPresent('_qf_Search_refresh');
c3ad8633 296 $this->clickLink("_qf_Search_refresh");
6c6e6187 297 $this->waitForText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]", '1 Result');
6a488035
TO
298 }
299
00be9182 300 public function testSurveyReportTest() {
42daf119
CW
301 $this->webtestLogin('admin');
302
303 // Enable CiviCampaign module if necessary
304 $this->enableComponents(array('CiviCampaign'));
305
306 // add the required permission
307 $this->changePermissions('edit-2-administer-civicampaign');
308
6a488035
TO
309 $this->webtestLogin();
310
311 // Create new group
312 $title = substr(sha1(rand()), 0, 7);
313 $groupName = $this->WebtestAddGroup();
314
315 // Adding contact
6a488035
TO
316 $firstName1 = substr(sha1(rand()), 0, 7);
317 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
a471a3b6 318 $id1 = $this->urlArg('cid');
6a488035
TO
319
320 // add contact to group
321 // visit group tab
322 $this->click("css=li#tab_group a");
0caa4679 323 $this->waitForElementPresent('css=#group_id option');
6a488035
TO
324
325 // add to group
326 $this->select("group_id", "label=$groupName");
327 $this->click("_qf_GroupContact_next");
642aa483 328 $this->waitForElementPresent('link=Remove');
6a488035
TO
329
330 $firstName2 = substr(sha1(rand()), 0, 7);
331 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
a471a3b6 332 $id2 = $this->urlArg('cid');
6a488035
TO
333
334 // add contact to group
335 // visit group tab
336 $this->click("css=li#tab_group a");
0caa4679 337 $this->waitForElementPresent('css=#group_id option');
6a488035
TO
338
339 // add to group
340 $this->select("group_id", "label=$groupName");
341 $this->click("_qf_GroupContact_next");
642aa483 342 $this->waitForElementPresent('link=Remove');
6a488035
TO
343
344 // Create custom group and add custom data fields
345 $this->openCiviPage("admin/custom/group", "reset=1");
346
347 $this->click("link=Add Set of Custom Fields");
348 $this->waitForElementPresent('_qf_Group_cancel-bottom');
349
350 $customGroup = "Custom Group $title";
351 $this->type('title', "$customGroup");
352 $this->select('extends[0]', "value=Contact");
75c2f9ab 353 $this->clickLink('_qf_Group_next-bottom');
6c5f7368 354 $this->waitForText('crm-notification-container', $customGroup);
6a488035
TO
355
356 // Add custom fields
fe725ccb 357 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
6a488035
TO
358 $field1 = "Checkbox $title";
359 $this->type('label', $field1);
360 $this->select('data_type[1]', "value=CheckBox");
361 $this->waitForElementPresent('option_label_2');
362
363 // add multiple choice options
364 $label1 = "Check $title One";
365 $value1 = 1;
366 $this->type('option_label_1', $label1);
367 $this->type('option_value_1', $value1);
368
369 $label2 = "Check $title Two";
370 $value2 = 2;
371 $this->type('option_label_2', $label2);
372 $this->type('option_value_2', $value2);
373
374 $this->click("link=another choice");
375
376 $label3 = "Check $title Three";
377 $value3 = 3;
378 $this->type('option_label_3', $label3);
379 $this->type('option_value_3', $value3);
380
fe725ccb
RK
381 $this->click("xpath=//*[@id='_qf_Field_done-bottom']");
382 $this->waitForElementPresent('newCustomField');
383 $this->isElementPresent("xpath=//table[@id='options']/tbody//tr/td[1]/span[text()='{$field1}']");
6a488035
TO
384
385 // Create a profile for survey
386 $this->openCiviPage("admin/uf/group", "reset=1");
387
388 $this->click("link=Add Profile");
389 $this->waitForElementPresent('_qf_Group_cancel-bottom');
390
391 $surveyProfile = "Survey Profile $title";
392 $this->type('title', $surveyProfile);
393 $this->click('_qf_Group_next-bottom');
75c2f9ab 394 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '$surveyProfile' has been added. You can add fields to this profile now.");
6a488035
TO
395
396 // Add fields to the profile
397 // Phone ( Primary )
fe725ccb 398 $this->waitForElementPresent('field_name[0]');
6a488035 399 $this->select('field_name[0]', "value=Contact");
fe725ccb 400 $this->waitForElementPresent('field_name[1]');
6a488035
TO
401 $this->select('field_name[1]', "value=phone");
402 $this->click('field_name[1]');
403 $this->select('visibility', "value=Public Pages and Listings");
404 $this->check('is_searchable');
405 $this->check('in_selector');
fe725ccb
RK
406 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
407 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]");
76e86fd8 408
6a488035 409 // Custom Data Fields
fe725ccb 410 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
75c2f9ab 411 $this->waitForElementPresent('field_name[0]');
6a488035 412 $this->select('field_name[0]', "value=Contact");
fe725ccb 413 $this->waitForElementPresent('field_name[1]');
6a488035
TO
414 $this->select('field_name[1]', "label=$field1 :: $customGroup");
415 $this->click('field_name[1]');
416 $this->select('visibility', "value=Public Pages and Listings");
417 $this->check('is_searchable');
418 $this->check('in_selector');
fe725ccb
RK
419 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]");
420 $this->waitForElementPresent("xpath=//table[@id='options']");
421 $this->isElementPresent("xpath=//table[@id='options']/tbody//tr/td[1]/span", $field1);
6a488035 422
6a488035
TO
423 // Create a survey
424 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
425
426 // fill in a unique title for the survey
427 $surveyTitle = "Survey $title";
fe725ccb 428 $this->waitForElementPresent('title');
6a488035
TO
429 $this->type('title', $surveyTitle);
430
431 // select the created campaign
432 //$this->select("campaign_id", "label=Campaign $title");
433
434 // select the activity type
fe725ccb 435 $this->waitForElementPresent('activity_type_id');
6a488035
TO
436 $this->select("activity_type_id", "label=Survey");
437
438 // fill in reserve survey respondents
439 $this->type("default_number_of_contacts", 50);
440
441 // fill in interview survey respondents
442 $this->type("max_number_of_contacts", 100);
443
444 // release frequency
445 $this->type("release_frequency", 2);
446
447 $this->click("_qf_Main_upload-bottom");
448 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
76e86fd8 449
6a488035
TO
450 //Select the profile for the survey
451 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
452
76e86fd8
CW
453 // select the question created for the survey
454
6a488035
TO
455 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=$surveyProfile");
456 $this->click("_qf_Questions_upload_next-bottom");
457
458 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
459 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
460 $optionLabel1 = "Label $title 1";
461 $this->type("//input[@id='option_label_1']", "$optionLabel1");
462 $this->type("//input[@id='option_value_1']", "1");
463
464 $optionLabel2 = "Label $title 2";
465 $this->type("//input[@id='option_label_2']", "$optionLabel2");
466 $this->type("//input[@id='option_value_2']", "2");
467 $this->type("//input[@id='report_title']", "Survey $title");
468 $this->click('_qf_Results_upload_done-bottom');
469 $this->waitForElementPresent("//div[@id='search_form_survey']");
470 $this->assertTrue($this->isTextPresent("'Results' have been saved."),
471 "Status message didn't show up after saving survey!"
472 );
473
474 // Reserve Respondents
475 $this->openCiviPage("survey/search", "reset=1&op=reserve", '_qf_Search_refresh');
476
477 // search for the respondents
478 // select survey
479 $this->select('campaign_survey_id', "label=$surveyTitle");
480
481 // need to wait for Groups field to reload dynamically
642aa483 482 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
6a488035
TO
483
484 // select group
fe725ccb 485 $this->waitForElementPresent('group');
642aa483 486 $this->click('group');
fe725ccb 487 $this->waitForElementPresent('group');
642aa483 488 $this->select('group', "label=$groupName");
6a488035
TO
489 $this->click('_qf_Search_refresh');
490
fe725ccb
RK
491 $this->waitForElementPresent('toggleSelect');
492 $this->click('toggleSelect');
642aa483 493 $this->select('task', "Reserve Respondents");
fe725ccb 494
6a488035
TO
495 $this->waitForElementPresent('_qf_Reserve_done_reserve-bottom');
496
225a8648 497 $this->clickLink('_qf_Reserve_done_reserve-bottom', 'access');
0391e7ab 498 $this->waitForText('crm-notification-container', "2 contacts have been reserved.");
6a488035
TO
499
500 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
501
502 // Select columns to be displayed
503 $this->check('fields[survey_id]');
504 $this->check('fields[survey_response]');
505 $this->select('survey_id_value', "label=$surveyTitle");
506 $this->select('status_id_value', "label=Reserved");
507 $this->click('_qf_SurveyDetails_submit');
508 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
509 $this->assertTrue($this->isTextPresent("Is equal to Reserved"));
510
511 // commenting out the print assertion as print dialog which appears breaks the webtest
76e86fd8 512 // as it is OS-related and cannot be handled through webtest
6a488035
TO
513
514 // $this->click('_qf_SurveyDetails_submit_print');
515 // $this->waitForPageToLoad($this->getTimeoutMsec());
516
517 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
518 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
519 // $this->assertTrue($this->isTextPresent("$value1 | $value2 | $value3"));
520
521 // Interview Respondents
522 $this->openCiviPage("survey/search", "reset=1&op=interview", '_qf_Search_refresh');
523
524 // search for the respondents
525 // select survey
526 $this->select('campaign_survey_id', "label=$surveyTitle");
527
528 // need to wait for Groups field to reload dynamically
642aa483 529 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
6a488035
TO
530
531 // select group
642aa483
AS
532 $this->click('group');
533 $this->select('group', "label=$groupName");
534 //$this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
6a488035
TO
535 $this->click('_qf_Search_refresh');
536
642aa483 537 //$this->click("xpath=//*[@class='selector']//tbody//tr[@id='rowid{$id1}']/td[1]");
fe725ccb
RK
538 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid{$id1}']/td/input");
539 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr[@id='rowid{$id1}']/td/input");
540 $this->waitForElementPresent('task');
541 $this->select('task', "Record Survey Responses");
6a488035
TO
542 $this->waitForElementPresent('_qf_Interview_cancel_interview');
543
48b420d7 544 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[6]/input[@type='text']");
fe725ccb 545
6a488035 546 $this->type("field_{$id1}_phone-Primary-1", 9876543210);
fe725ccb 547
75c2f9ab
RK
548 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[7]/input[2]");
549 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[7]/input[2]");
550 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[7]/input[4]");
551 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[7]/input[4]");
fe725ccb 552
6a488035 553 $this->select("field_{$id1}_result", $optionLabel1);
fe725ccb
RK
554 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[@id='row_{$id1}']/td[10]/a");
555 $this->click('_qf_Interview_cancel_interview');
efb29358
CW
556 // Because it tends to cause problems, all uses of sleep() must be justified in comments
557 // Sleep should never be used for wait for anything to load from the server
558 // Justification for this instance: FIXME
6a488035
TO
559 sleep(3);
560 // Survey Report
561 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
562
563 // Select columns to be displayed
564 $this->check('fields[survey_id]');
565 $this->check('fields[survey_response]');
566 $this->select('survey_id_value', "label=$surveyTitle");
567 $this->select('status_id_value', "label=Interviewed");
568 $this->click('_qf_SurveyDetails_submit');
569 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
570 $this->assertTrue($this->isTextPresent("Is equal to Interviewed"));
571
572 // commenting out the print assertion as print dialog which appears breaks the webtest
76e86fd8 573 // as it is OS-related and cannot be handled through webtest
6a488035
TO
574
575 // $this->click('_qf_SurveyDetails_submit_print');
576 // $this->waitForPageToLoad($this->getTimeoutMsec());
577
578 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
579 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
580 // $this->assertTrue($this->isTextPresent("$value1"));
581
582 // use GOTV (campaign/gotv) to mark the respondents as voted
583 $this->openCiviPage("campaign/gotv", "reset=1");
584
585 // search for the respondents
586 // select survey
587 $this->select('campaign_survey_id', "label=$surveyTitle");
588 // need to wait for Groups field to reload dynamically
642aa483 589 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
6a488035
TO
590
591 // select group
642aa483
AS
592 $this->click('group');
593 $this->select('group', "label=$groupName");
594 //$this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
595 //$this->click("xpath=//div[@id='search_form_gotv']/div[2]/table/tbody/tr[6]/td/a[text()='Search']");
596 $this->click("link=Search");
0bd37c06 597
fe725ccb
RK
598 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[7]/input");
599 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[7]/input");
6a488035
TO
600
601 // Check title of the activities created
602 $this->openCiviPage("activity/search", "reset=1", '_qf_Search_refresh');
fe725ccb 603 $this->waitForElementPresent('activity_survey_id');
6a488035
TO
604 $this->select('activity_survey_id', "label=$surveyTitle");
605 $this->click('_qf_Search_refresh');
606 $this->waitForPageToLoad($this->getTimeoutMsec());
607
fe725ccb
RK
608 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']");
609 $this->verifyText("xpath=//table[@class='selector row-highlight']/tbody//tr/td[5]/a[text()='Smith, $firstName1']/../../td[3]",
6a488035
TO
610 preg_quote("$surveyTitle - Respondent Interview")
611 );
fe725ccb 612 $this->verifyText("xpath=//table[@class='selector row-highlight']/tbody//tr/td[5]/a[text()='John, $firstName2']/../../td[3]",
6a488035
TO
613 preg_quote("$surveyTitle - Respondent Reservation")
614 );
615 }
96025800 616
6a488035 617}