3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_SurveyUsageScenarioTest
32 class WebTest_Campaign_SurveyUsageScenarioTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testSurveyUsageScenario() {
39 $this->webtestLogin('admin');
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
46 $firstName1 = substr(sha1(rand()), 0, 7);
47 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
49 // add contact to group
51 $this->click("css=li#tab_group a");
52 $this->waitForElementPresent("css=#group_id option");
55 $this->select("group_id", "label=$groupName");
56 $this->click("_qf_GroupContact_next");
57 $this->waitForElementPresent('link=Remove');
59 $firstName2 = substr(sha1(rand()), 0, 7);
60 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
62 // add contact to group
64 $this->click("css=li#tab_group a");
65 $this->waitForElementPresent("css=#group_id option");
68 $this->select("group_id", "label=$groupName");
69 $this->click("_qf_GroupContact_next");
70 $this->waitForElementPresent('link=Remove');
72 // Enable CiviCampaign module if necessary
73 $this->enableComponents(array('CiviCampaign'));
75 // add the required permission
76 $this->changePermissions(array('edit-2-administer-civicampaign'));
78 // Log in as normal user
79 $this->webtestLogin();
81 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
82 $this->waitForElementPresent('title');
83 $this->type("title", "Campaign $title");
85 // select the campaign type
86 $this->waitForElementPresent('campaign_type_id');
87 $this->select("campaign_type_id", "value=2");
89 // fill in the description
90 $this->type("description", "This is a test campaign");
92 // include groups for the campaign
93 $this->addSelection("includeGroups", "label=$groupName");
94 $this->click("//option[@value=4]");
96 // fill the end date for campaign
97 $this->webtestFillDate("end_date", "+1 year");
99 // select campaign status
100 $this->select("status_id", "value=2");
103 $this->click("_qf_Campaign_upload-bottom");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
106 $this->waitForText('crm-notification-container', "$title");
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");
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");
118 // save the custom group
119 $this->click("_qf_Group_next-bottom");
120 $this->waitForPageToLoad($this->getTimeoutMsec());
122 // add a custom field to the custom group
123 $this->waitForElementPresent('newCustomField');
124 $this->click('newCustomField');
125 $this->waitForElementPresent('label');
126 $this->type("label", "Field $title");
128 $this->select("data_type[1]", "value=Radio");
130 $this->waitForElementPresent("option_label_1");
132 // create a set of options
133 $this->type("option_label_1", "Option $title 1");
134 $this->type("option_value_1", "1");
136 $this->type("option_label_2", "Option $title 2");
137 $this->type("option_value_2", "2");
139 // save the custom field
140 $this->click("_qf_Field_done-bottom");
142 $this->waitForElementPresent("newCustomField");
143 $this->waitForText('crm-notification-container', "$title");
145 // create a profile for campaign
146 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1", "_qf_Group_next-bottom");
148 // fill in a unique title for the profile
149 $this->type("title", "Profile $title");
152 $this->click("_qf_Group_next-bottom");
154 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div/div[2]/a/span");
155 $this->click("xpath=//div[@id='crm-main-content-wrapper']/div/div[2]/a/span");
157 // add a profile field for activity
158 $this->waitForElementPresent('field_name[0]');
159 $this->select("field_name[0]", "value=Activity");
160 $this->waitForElementPresent("field_name[1]");
161 $this->select("field_name[1]", "label=Field $title :: Group $title");
163 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]");
164 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]");
165 $this->waitForText('crm-notification-container', "$title");
168 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
170 // fill in a unique title for the survey
171 $this->type("title", "Survey $title");
173 // select the created campaign
174 $this->select("campaign_id", "label=Campaign $title");
176 // select the activity type
177 $this->select("activity_type_id", "label=Survey");
179 // fill in reserve survey respondents
180 $this->type("default_number_of_contacts", 50);
182 // fill in interview survey respondents
183 $this->type("max_number_of_contacts", 100);
186 $this->type("release_frequency", 2);
188 $this->click("_qf_Main_upload-bottom");
189 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
191 // Select the profile for the survey
192 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
194 // select the question created for the survey
196 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=Profile $title");
197 $this->click("_qf_Questions_upload_next-bottom");
199 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
200 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
201 $this->type("//input[@id='option_label_1']", "Label $title 1");
202 $this->type("//input[@id='option_value_1']", "1");
204 $this->type("//input[@id='option_label_2']", "Label $title 2");
205 $this->type("//input[@id='option_value_2']", "2");
206 $this->click('_qf_Results_upload_done-bottom');
207 $this->waitForElementPresent("//div[@id='search_form_survey']");
208 $this->waitForText('crm-notification-container', "Results");
210 // Reserve Respondents
211 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
213 // search for the respondents
214 $this->select("campaign_survey_id", "label=Survey $title");
216 $this->click("_qf_Search_refresh");
217 $this->waitForElementPresent('toggleSelect');
218 $this->click('toggleSelect');
219 $this->select('task', "Reserve Respondents");
221 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
222 $this->click("_qf_Reserve_done_reserve-bottom");
223 $this->waitForPageToLoad($this->getTimeoutMsec());
224 $this->waitForText('crm-notification-container', "2 Contact\(s\) have been reserved");
226 // Interview Respondents
227 $this->openCiviPage("survey/search", "reset=1&op=interview", "_qf_Search_refresh");
228 // search for the respondents
229 $this->waitForElementPresent('campaign_survey_id');
230 $this->select("campaign_survey_id", "label=Survey $title");
231 $this->click("_qf_Search_refresh");
233 $this->waitForElementPresent('toggleSelect');
234 $this->click('toggleSelect');
235 $this->select('task', "Record Survey Responses");
236 $this->waitForElementPresent("_qf_Interview_cancel_interview");
238 $this->click("CIVICRM_QFID_1_2");
239 $this->select("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[1]/td[8]/select","value=Label $title 1");
240 $this->click("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[1]/td[9]/a");
242 $this->click("CIVICRM_QFID_2_8");
244 $this->select("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[2]/td[8]/select","value=Label $title 2");
245 $this->click("xpath=//table[@class='display crm-copy-fields dataTable no-footer']/tbody/tr[2]/td[9]/a");
246 $this->click("_qf_Interview_cancel_interview");
247 $this->waitForPageToLoad($this->getTimeoutMsec());
249 // add a contact to the group to test release respondents
250 $firstName3 = substr(sha1(rand()), 0, 7);
251 $this->webtestAddContact($firstName3, "James", "$firstName3.james@example.org");
252 $id = $this->urlArg('cid');
253 $sortName3 = "James, $firstName3";
255 // add contact to group
257 $this->click("css=li#tab_group a");
258 $this->waitForElementPresent("css=#group_id option");
261 $this->select("group_id", "label=$groupName");
262 $this->click("_qf_GroupContact_next");
263 $this->waitForElementPresent('link=Remove');
265 // Reserve Respondents
266 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
268 // search for the respondents
269 $this->select("campaign_survey_id", "label=Survey $title");
271 $this->click("_qf_Search_refresh");
272 $this->waitForElementPresent('toggleSelect');
273 $this->click('toggleSelect');
274 $this->waitForElementPresent('task');
275 $this->select('task', "Reserve Respondents");
276 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
277 $this->click("_qf_Reserve_done_reserve-bottom");
278 $this->waitForText('crm-notification-container', "1 Contact\(s\) have been reserved");
280 // Release Respondents
281 $this->openCiviPage("survey/search", "reset=1&op=release", "_qf_Search_refresh");
283 // search for the respondents
284 $this->select("campaign_survey_id", "label=Survey $title");
286 $this->click("_qf_Search_refresh");
287 $this->waitForElementPresent('toggleSelect');
288 $this->click('toggleSelect');
289 $this->waitForElementPresent('task');
290 $this->select("task", "label=Release Respondents");
291 $this->waitForElementPresent('_qf_Release_done-bottom');
292 $this->click("_qf_Release_done-bottom");
293 $this->waitForText('crm-notification-container', "released");
295 // check whether contact is available for reserving again
296 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
298 // search for the respondents
299 $this->select("campaign_survey_id", "label=Survey $title");
301 $this->waitForElementPresent('_qf_Search_refresh');
302 $this->click("_qf_Search_refresh");
303 $this->waitForPageToLoad($this->getTimeoutMsec());
304 $this->waitForText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]",'1 Result');
307 function testSurveyReportTest() {
308 $this->webtestLogin('admin');
310 // Enable CiviCampaign module if necessary
311 $this->enableComponents(array('CiviCampaign'));
313 // add the required permission
314 $this->changePermissions('edit-2-administer-civicampaign');
316 $this->webtestLogin();
319 $title = substr(sha1(rand()), 0, 7);
320 $groupName = $this->WebtestAddGroup();
323 $firstName1 = substr(sha1(rand()), 0, 7);
324 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
325 $id1 = $this->urlArg('cid');
327 // add contact to group
329 $this->click("css=li#tab_group a");
330 $this->waitForElementPresent('css=#group_id option');
333 $this->select("group_id", "label=$groupName");
334 $this->click("_qf_GroupContact_next");
335 $this->waitForElementPresent('link=Remove');
337 $firstName2 = substr(sha1(rand()), 0, 7);
338 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
339 $id2 = $this->urlArg('cid');
341 // add contact to group
343 $this->click("css=li#tab_group a");
344 $this->waitForElementPresent('css=#group_id option');
347 $this->select("group_id", "label=$groupName");
348 $this->click("_qf_GroupContact_next");
349 $this->waitForElementPresent('link=Remove');
351 // Create custom group and add custom data fields
352 $this->openCiviPage("admin/custom/group", "reset=1");
354 $this->click("link=Add Set of Custom Fields");
355 $this->waitForElementPresent('_qf_Group_cancel-bottom');
357 $customGroup = "Custom Group $title";
358 $this->type('title', "$customGroup");
359 $this->select('extends[0]', "value=Contact");
360 $this->click('_qf_Group_next-bottom');
361 $this->waitForElementPresent('_qf_Field_cancel-bottom');
362 $this->waitForText('crm-notification-container', $customGroup);
365 $field1 = "Checkbox $title";
366 $this->type('label', $field1);
367 $this->select('data_type[1]', "value=CheckBox");
368 $this->waitForElementPresent('option_label_2');
370 // add multiple choice options
371 $label1 = "Check $title One";
373 $this->type('option_label_1', $label1);
374 $this->type('option_value_1', $value1);
376 $label2 = "Check $title Two";
378 $this->type('option_label_2', $label2);
379 $this->type('option_value_2', $value2);
381 $this->click("link=another choice");
383 $label3 = "Check $title Three";
385 $this->type('option_label_3', $label3);
386 $this->type('option_value_3', $value3);
388 $this->click('_qf_Field_next-bottom');
389 $this->waitForPageToLoad($this->getTimeoutMsec());
390 $this->waitForText('crm-notification-container', $field1);
392 // Create a profile for survey
393 $this->openCiviPage("admin/uf/group", "reset=1");
395 $this->click("link=Add Profile");
396 $this->waitForElementPresent('_qf_Group_cancel-bottom');
398 $surveyProfile = "Survey Profile $title";
399 $this->type('title', $surveyProfile);
400 $this->click('_qf_Group_next-bottom');
401 $this->waitForElementPresent('_qf_Field_cancel-bottom');
402 $this->waitForText('crm-notification-container', $surveyProfile);
404 // Add fields to the profile
406 $this->select('field_name[0]', "value=Contact");
407 $this->select('field_name[1]', "value=phone");
408 $this->click('field_name[1]');
409 $this->select('visibility', "value=Public Pages and Listings");
410 $this->check('is_searchable');
411 $this->check('in_selector');
412 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_cancel-bottom');
414 // Custom Data Fields
415 $this->select('field_name[0]', "value=Contact");
416 $this->select('field_name[1]', "label=$field1 :: $customGroup");
417 $this->click('field_name[1]');
418 $this->select('visibility', "value=Public Pages and Listings");
419 $this->check('is_searchable');
420 $this->check('in_selector');
421 $this->click('_qf_Field_next-bottom');
422 $this->waitForPageToLoad($this->getTimeoutMsec());
425 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
427 // fill in a unique title for the survey
428 $surveyTitle = "Survey $title";
429 $this->type('title', $surveyTitle);
431 // select the created campaign
432 //$this->select("campaign_id", "label=Campaign $title");
434 // select the activity type
435 $this->select("activity_type_id", "label=Survey");
437 // fill in reserve survey respondents
438 $this->type("default_number_of_contacts", 50);
440 // fill in interview survey respondents
441 $this->type("max_number_of_contacts", 100);
444 $this->type("release_frequency", 2);
446 $this->click("_qf_Main_upload-bottom");
447 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
449 //Select the profile for the survey
450 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
452 // select the question created for the survey
454 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=$surveyProfile");
455 $this->click("_qf_Questions_upload_next-bottom");
457 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
458 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
459 $optionLabel1 = "Label $title 1";
460 $this->type("//input[@id='option_label_1']", "$optionLabel1");
461 $this->type("//input[@id='option_value_1']", "1");
463 $optionLabel2 = "Label $title 2";
464 $this->type("//input[@id='option_label_2']", "$optionLabel2");
465 $this->type("//input[@id='option_value_2']", "2");
466 $this->type("//input[@id='report_title']", "Survey $title");
467 $this->click('_qf_Results_upload_done-bottom');
468 $this->waitForElementPresent("//div[@id='search_form_survey']");
469 $this->assertTrue($this->isTextPresent("'Results' have been saved."),
470 "Status message didn't show up after saving survey!"
473 // Reserve Respondents
474 $this->openCiviPage("survey/search", "reset=1&op=reserve", '_qf_Search_refresh');
476 // search for the respondents
478 $this->select('campaign_survey_id', "label=$surveyTitle");
480 // need to wait for Groups field to reload dynamically
481 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
484 $this->click('group');
485 $this->select('group', "label=$groupName");
486 $this->click('_qf_Search_refresh');
488 $this->waitForElementPresent('Go');
489 $this->click("CIVICRM_QFID_ts_all_4");
490 $this->select('task', "Reserve Respondents");
492 $this->waitForElementPresent('_qf_Reserve_done_reserve-bottom');
494 $this->clickLink('_qf_Reserve_done_reserve-bottom', 'access');
495 $this->waitForText('crm-notification-container', "2 Contact\(s\) have been reserved");
497 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
499 // Select columns to be displayed
500 $this->check('fields[survey_id]');
501 $this->check('fields[survey_response]');
502 $this->select('survey_id_value', "label=$surveyTitle");
503 $this->select('status_id_value', "label=Reserved");
504 $this->click('_qf_SurveyDetails_submit');
505 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
506 $this->assertTrue($this->isTextPresent("Is equal to Reserved"));
508 // commenting out the print assertion as print dialog which appears breaks the webtest
509 // as it is OS-related and cannot be handled through webtest
511 // $this->click('_qf_SurveyDetails_submit_print');
512 // $this->waitForPageToLoad($this->getTimeoutMsec());
514 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
515 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
516 // $this->assertTrue($this->isTextPresent("$value1 | $value2 | $value3"));
518 // Interview Respondents
519 $this->openCiviPage("survey/search", "reset=1&op=interview", '_qf_Search_refresh');
521 // search for the respondents
523 $this->select('campaign_survey_id', "label=$surveyTitle");
525 // need to wait for Groups field to reload dynamically
526 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
529 $this->click('group');
530 $this->select('group', "label=$groupName");
531 //$this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
532 $this->click('_qf_Search_refresh');
534 $this->waitForElementPresent('Go');
535 //$this->click("xpath=//*[@class='selector']//tbody//tr[@id='rowid{$id1}']/td[1]");
536 $this->click("mark_x_{$id1}");
538 $this->waitForElementPresent('_qf_Interview_cancel_interview');
540 $this->type("field_{$id1}_phone-Primary-1", 9876543210);
541 $this->click("//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[7]/input[2]/../label[text()='$label1']");
542 $this->click("//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[7]/input[6]/../label[text()='$label2']");
543 $this->select("field_{$id1}_result", $optionLabel1);
544 $this->click("interview_voter_button_{$id1}");
545 // Because it tends to cause problems, all uses of sleep() must be justified in comments
546 // Sleep should never be used for wait for anything to load from the server
547 // Justification for this instance: FIXME
550 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
552 // Select columns to be displayed
553 $this->check('fields[survey_id]');
554 $this->check('fields[survey_response]');
555 $this->select('survey_id_value', "label=$surveyTitle");
556 $this->select('status_id_value', "label=Interviewed");
557 $this->click('_qf_SurveyDetails_submit');
558 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
559 $this->assertTrue($this->isTextPresent("Is equal to Interviewed"));
561 // commenting out the print assertion as print dialog which appears breaks the webtest
562 // as it is OS-related and cannot be handled through webtest
564 // $this->click('_qf_SurveyDetails_submit_print');
565 // $this->waitForPageToLoad($this->getTimeoutMsec());
567 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
568 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
569 // $this->assertTrue($this->isTextPresent("$value1"));
571 // use GOTV (campaign/gotv) to mark the respondents as voted
572 $this->openCiviPage("campaign/gotv", "reset=1");
574 // search for the respondents
576 $this->select('campaign_survey_id', "label=$surveyTitle");
577 // need to wait for Groups field to reload dynamically
578 $this->waitForElementPresent("//select[@id='group']/option[text()='$groupName']");
581 $this->click('group');
582 $this->select('group', "label=$groupName");
583 //$this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
584 //$this->click("xpath=//div[@id='search_form_gotv']/div[2]/table/tbody/tr[6]/td/a[text()='Search']");
585 $this->click("link=Search");
587 $this->waitForElementPresent("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]");
588 $this->check("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]/input");
590 // Check title of the activities created
591 $this->openCiviPage("activity/search", "reset=1", '_qf_Search_refresh');
592 $this->select('activity_survey_id', "label=$surveyTitle");
593 $this->click('_qf_Search_refresh');
594 $this->waitForPageToLoad($this->getTimeoutMsec());
596 $this->verifyText("xpath=//table/tbody//tr/td[5]/a[text()='Smith, $firstName1']/../../td[3]",
597 preg_quote("$surveyTitle - Respondent Interview")
599 $this->verifyText("xpath=//table/tbody//tr/td[5]/a[text()='John, $firstName2']/../../td[3]",
600 preg_quote("$surveyTitle - Respondent Reservation")