3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Campaign_SurveyUsageScenarioTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testSurveyUsageScenario() {
36 $this->webtestLogin();
39 $title = substr(sha1(rand()), 0, 7);
40 $groupName = $this->WebtestAddGroup();
43 $firstName1 = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
46 // add contact to group
48 $this->click("css=li#tab_group a");
49 $this->waitForElementPresent("group_id");
52 $this->select("group_id", "label=$groupName");
53 $this->click("_qf_GroupContact_next");
54 $this->waitForPageToLoad($this->getTimeoutMsec());
56 $firstName2 = substr(sha1(rand()), 0, 7);
57 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
59 // add contact to group
61 $this->click("css=li#tab_group a");
62 $this->waitForElementPresent("group_id");
65 $this->select("group_id", "label=$groupName");
66 $this->click("_qf_GroupContact_next");
67 $this->waitForPageToLoad($this->getTimeoutMsec());
69 $this->enableComponents(array('CiviCampaign'));
71 // add the required Drupal permission
72 $permissions = array('edit-2-administer-civicampaign');
73 $this->changePermissions($permissions);
75 // Go directly to the URL of the screen that you will be testing
76 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
78 // Let's start filling the form with values.
79 $this->type("title", "Campaign $title");
81 // select the campaign type
82 $this->select("campaign_type_id", "value=2");
84 // fill in the description
85 $this->type("description", "This is a test campaign");
87 // include groups for the campaign
88 $this->addSelection("includeGroups-f", "label=$groupName");
89 $this->click("//option[@value=4]");
92 // fill the end date for campaign
93 $this->webtestFillDate("end_date", "+1 year");
95 // select campaign status
96 $this->select("status_id", "value=2");
99 $this->click("_qf_Campaign_upload-bottom");
100 $this->waitForPageToLoad($this->getTimeoutMsec());
102 //$this->assertElementContainsText("crm-notification-container", "$title");
104 // create a custom data set for activities -> survey
105 $this->openCiviPage('admin/custom/group', "action=add&reset=1", "_qf_Group_next-bottom");
106 // fill in a unique title for the custom group
107 $this->type("title", "Group $title");
109 // select the group this custom data set extends
110 $this->select("extends[0]", "value=Activity");
111 $this->waitForElementPresent("//select[@id='extends_1']");
112 $this->select("//select[@id='extends_1']", "label=Survey");
114 // save the custom group
115 $this->click("_qf_Group_next-bottom");
116 $this->waitForPageToLoad();
118 // add a custom field to the custom group
119 $this->type("label", "Field $title");
121 $this->select("data_type[1]", "value=Radio");
123 $this->waitForElementPresent("option_label_1");
125 // create a set of options
126 $this->type("option_label_1", "Option $title 1");
127 $this->type("option_value_1", "1");
129 $this->type("option_label_2", "Option $title 2");
130 $this->type("option_value_2", "2");
132 // save the custom field
133 $this->click("_qf_Field_next-bottom");
135 $this->waitForElementPresent("newCustomField");
136 $this->assertElementContainsText("crm-notification-container", "$title");
138 // create a profile for campaign
139 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1", "_qf_Group_next-bottom");
141 // fill in a unique title for the profile
142 $this->type("title", "Profile $title");
145 $this->click("_qf_Group_next-bottom");
147 $this->waitForElementPresent("_qf_Field_next-bottom");
148 $this->assertElementContainsText("crm-notification-container", "$title");
150 // add a profile field for activity
151 $this->select("field_name[0]", "value=Activity");
152 $this->waitForElementPresent("field_name[1]");
153 $this->select("field_name[1]", "label=Field $title :: Group $title");
155 $this->click("_qf_Field_next-bottom");
156 $this->waitForPageToLoad($this->getTimeoutMsec());
157 $this->assertElementContainsText("crm-notification-container", "$title");
160 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
162 // fill in a unique title for the survey
163 $this->type("title", "Survey $title");
165 // select the created campaign
166 $this->select("campaign_id", "label=Campaign $title");
168 // select the activity type
169 $this->select("activity_type_id", "label=Survey");
171 // fill in reserve survey respondents
172 $this->type("default_number_of_contacts", 50);
174 // fill in interview survey respondents
175 $this->type("max_number_of_contacts", 100);
178 $this->type("release_frequency", 2);
180 $this->click("_qf_Main_upload-bottom");
181 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
183 //Select the profile for the survey
184 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
186 // select the question created for the survey
187 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=Profile $title");
188 $this->click("_qf_Questions_upload_next-bottom");
190 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
191 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
192 $this->type("//input[@id='option_label_1']", "Label $title 1");
193 $this->type("//input[@id='option_value_1']", "1");
195 $this->type("//input[@id='option_label_2']", "Label $title 2");
196 $this->type("//input[@id='option_value_2']", "2");
197 $this->click('_qf_Results_upload_done-bottom');
198 $this->waitForElementPresent("//div[@id='search_form_survey']");
199 $this->assertElementContainsText("crm-notification-container", "Results");
201 // Reserve Respondents
202 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
204 // search for the respondents
205 $this->select("campaign_survey_id", "label=Survey $title");
207 $this->click("_qf_Search_refresh");
209 $this->waitForElementPresent("Go");
210 $this->click("CIVICRM_QFID_ts_all_4");
213 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
214 $this->click("_qf_Reserve_done_reserve-bottom");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
216 $this->assertElementContainsText("crm-notification-container", "2");
218 // Interview Respondents
219 $this->openCiviPage("survey/search", "reset=1&op=interview", "_qf_Search_refresh");
221 // search for the respondents
222 $this->select("campaign_survey_id", "label=Survey $title");
224 $this->click("_qf_Search_refresh");
226 $this->waitForElementPresent("Go");
227 $this->click("CIVICRM_QFID_ts_all_4");
230 $this->waitForElementPresent("_qf_Interview_cancel_interview");
232 $this->click("CIVICRM_QFID_1_2");
233 $this->select("css=#voterRecords .odd .result select", "value=Label $title 1");
234 $this->click("css=#voterRecords .odd td a");
236 $this->click("CIVICRM_QFID_2_8");
237 $this->select("css=#voterRecords .even .result select", "value=Label $title 2");
238 $this->click("css=#voterRecords .even td a");
240 $this->click("_qf_Interview_cancel_interview");
241 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
246 $url = $this->getLocation();
247 $id = explode('cid=', $url);
248 $sortName3 = "James, $firstName3";
250 // add contact to group
252 $this->click("css=li#tab_group a");
253 $this->waitForElementPresent("group_id");
256 $this->select("group_id", "label=$groupName");
257 $this->click("_qf_GroupContact_next");
258 $this->waitForPageToLoad($this->getTimeoutMsec());
260 // Reserve Respondents
261 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
263 // search for the respondents
264 $this->select("campaign_survey_id", "label=Survey $title");
266 $this->click("_qf_Search_refresh");
268 $this->waitForElementPresent("Go");
269 $this->click("CIVICRM_QFID_ts_all_4");
272 $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom");
273 $this->click("_qf_Reserve_done_reserve-bottom");
274 $this->waitForPageToLoad($this->getTimeoutMsec());
275 $this->assertElementContainsText("crm-notification-container", "3");
277 // Release Respondents
278 $this->openCiviPage("survey/search", "reset=1&op=release", "_qf_Search_refresh");
280 // search for the respondents
281 $this->select("campaign_survey_id", "label=Survey $title");
283 $this->click("_qf_Search_refresh");
285 $this->waitForElementPresent("Go");
286 $this->click("xpath=id('mark_x_$id[1]')");
288 $this->waitForElementPresent("Go");
290 $this->waitForPageToLoad($this->getTimeoutMsec());
292 $this->waitForElementPresent("_qf_Release_done-bottom");
293 $this->click("_qf_Release_done-bottom");
294 $this->waitForPageToLoad($this->getTimeoutMsec());
295 // wait for Access Keys div to appear at bottom of page - since this page may take a while
296 $this->waitForElementPresent('access');
297 $this->assertElementContainsText("crm-notification-container", "released");
299 // check whether contact is available for reserving again
300 $this->openCiviPage("survey/search", "reset=1&op=reserve", "_qf_Search_refresh");
302 // search for the respondents
303 $this->select("campaign_survey_id", "label=Survey $title");
305 $this->click("_qf_Search_refresh");
306 $this->waitForPageToLoad($this->getTimeoutMsec());
307 $this->assertTrue($this->isTextPresent("1 Result"), "Result didn't show up after saving!");
310 function testSurveyReportTest() {
311 $this->webtestLogin();
314 $title = substr(sha1(rand()), 0, 7);
315 $groupName = $this->WebtestAddGroup();
318 // We're using Quick Add block on the main page for this.
319 $firstName1 = substr(sha1(rand()), 0, 7);
320 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
321 $url1 = explode('cid=', $this->getLocation());
324 // add contact to group
326 $this->click("css=li#tab_group a");
327 $this->waitForElementPresent('group_id');
330 $this->select("group_id", "label=$groupName");
331 $this->click("_qf_GroupContact_next");
332 $this->waitForPageToLoad($this->getTimeoutMsec());
334 $firstName2 = substr(sha1(rand()), 0, 7);
335 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
336 $url2 = explode('cid=', $this->getLocation());
339 // add contact to group
341 $this->click("css=li#tab_group a");
342 $this->waitForElementPresent('group_id');
345 $this->select("group_id", "label=$groupName");
346 $this->click("_qf_GroupContact_next");
347 $this->waitForPageToLoad($this->getTimeoutMsec());
349 // Create custom group and add custom data fields
350 $this->openCiviPage("admin/custom/group", "reset=1");
352 $this->click("link=Add Set of Custom Fields");
353 $this->waitForElementPresent('_qf_Group_cancel-bottom');
355 $customGroup = "Custom Group $title";
356 $this->type('title', "$customGroup");
357 $this->select('extends[0]', "value=Contact");
358 $this->click('_qf_Group_next-bottom');
359 $this->waitForElementPresent('_qf_Field_cancel-bottom');
360 $this->assertTrue($this->isTextPresent("Your custom field set '$customGroup' has been added. You can add custom fields now."));
363 $field1 = "Checkbox $title";
364 $this->type('label', $field1);
365 $this->select('data_type[1]', "value=CheckBox");
366 $this->waitForElementPresent('option_label_2');
368 // add multiple choice options
369 $label1 = "Check $title One";
371 $this->type('option_label_1', $label1);
372 $this->type('option_value_1', $value1);
374 $label2 = "Check $title Two";
376 $this->type('option_label_2', $label2);
377 $this->type('option_value_2', $value2);
379 $this->click("link=another choice");
381 $label3 = "Check $title Three";
383 $this->type('option_label_3', $label3);
384 $this->type('option_value_3', $value3);
386 $this->click('_qf_Field_next-bottom');
387 $this->waitForPageToLoad($this->getTimeoutMsec());
388 $this->assertTrue($this->isTextPresent("Your custom field '$field1' has been saved."));
390 // Create a profile for survey
391 $this->openCiviPage("admin/uf/group", "reset=1");
393 $this->click("link=Add Profile");
394 $this->waitForElementPresent('_qf_Group_cancel-bottom');
396 $surveyProfile = "Survey Profile $title";
397 $this->type('title', $surveyProfile);
398 $this->click('_qf_Group_next-bottom');
399 $this->waitForElementPresent('_qf_Field_cancel-bottom');
400 $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$surveyProfile' has been added. You can add fields to this profile now. "));
402 // Add fields to the profile
404 $this->select('field_name[0]', "value=Contact");
405 $this->select('field_name[1]', "value=phone");
406 $this->click('field_name[1]');
407 $this->select('visibility', "value=Public Pages and Listings");
408 $this->check('is_searchable');
409 $this->check('in_selector');
410 $this->click('_qf_Field_next_new-bottom');
411 $this->waitForPageToLoad($this->getTimeoutMsec());
412 $this->waitForElementPresent('_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());
424 // Enable CiviCampaign module if necessary
425 $this->openCiviPage("admin/setting/component", "reset=1");
427 $this->waitForElementPresent('_qf_Component_next-bottom');
428 $enabledComponents = $this->getSelectOptions('enableComponents-t');
429 if (!in_array("CiviCampaign", $enabledComponents)) {
430 $this->addSelection('enableComponents-f', "label=CiviCampaign");
431 $this->click("//option[@value='CiviCampaign']");
433 $this->click('_qf_Component_next-bottom');
434 $this->waitForPageToLoad($this->getTimeoutMsec());
435 $this->assertTrue($this->isTextPresent('Changes Saved.'));
438 // add the required Drupal permission
439 $permissions = array('edit-2-administer-civicampaign');
440 $this->changePermissions($permissions);
443 $this->openCiviPage("survey/add", "reset=1", "_qf_Main_upload-bottom");
445 // fill in a unique title for the survey
446 $surveyTitle = "Survey $title";
447 $this->type('title', $surveyTitle);
449 // select the created campaign
450 //$this->select("campaign_id", "label=Campaign $title");
452 // select the activity type
453 $this->select("activity_type_id", "label=Survey");
455 // fill in reserve survey respondents
456 $this->type("default_number_of_contacts", 50);
458 // fill in interview survey respondents
459 $this->type("max_number_of_contacts", 100);
462 $this->type("release_frequency", 2);
464 $this->click("_qf_Main_upload-bottom");
465 $this->waitForElementPresent("_qf_Questions_upload_next-bottom");
467 //Select the profile for the survey
468 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual");
470 // select the question created for the survey
471 $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[2]/td[2]/div/div/span/select", "label=$surveyProfile");
472 $this->click("_qf_Questions_upload_next-bottom");
474 // create a set of options for Survey Responses _qf_Results_upload_done-bottom
475 $this->waitForElementPresent('_qf_Results_upload_done-bottom');
476 $optionLabel1 = "Label $title 1";
477 $this->type("//input[@id='option_label_1']", "$optionLabel1");
478 $this->type("//input[@id='option_value_1']", "1");
480 $optionLabel2 = "Label $title 2";
481 $this->type("//input[@id='option_label_2']", "$optionLabel2");
482 $this->type("//input[@id='option_value_2']", "2");
483 $this->type("//input[@id='report_title']", "Survey $title");
484 $this->click('_qf_Results_upload_done-bottom');
485 $this->waitForElementPresent("//div[@id='search_form_survey']");
486 $this->assertTrue($this->isTextPresent("'Results' have been saved."),
487 "Status message didn't show up after saving survey!"
490 // Reserve Respondents
491 $this->openCiviPage("survey/search", "reset=1&op=reserve", '_qf_Search_refresh');
493 // search for the respondents
495 $this->select('campaign_survey_id', "label=$surveyTitle");
497 // need to wait for Groups field to reload dynamically
501 $this->click('campaignGroupsSelect1');
502 $this->select('campaignGroupsSelect1', "label=$groupName");
503 $this->click('_qf_Search_refresh');
505 $this->waitForElementPresent('_qf_Search_next_print');
506 $this->click("CIVICRM_QFID_ts_all_4");
508 $this->waitForElementPresent('_qf_Reserve_done_reserve-bottom');
510 $this->click('_qf_Reserve_done_reserve-bottom');
511 $this->waitForPageToLoad($this->getTimeoutMsec());
512 // wait for Access Keys div to appear at bottom of page - since this page may take a while
513 $this->waitForElementPresent('access');
514 $this->assertTrue($this->isTextPresent("Reservation has been added for 2 Contact(s)."));
516 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
518 // Select columns to be displayed
519 $this->check('fields[survey_id]');
520 $this->check('fields[survey_response]');
521 $this->select('survey_id_value', "label=$surveyTitle");
522 $this->select('status_id_value', "label=Reserved");
523 $this->click('_qf_SurveyDetails_submit');
524 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
525 $this->assertTrue($this->isTextPresent("Is equal to Reserved"));
527 // commenting out the print assertion as print dialog which appears breaks the webtest
528 // as it is OS-related and cannot be handled through webtest
530 // $this->click('_qf_SurveyDetails_submit_print');
531 // $this->waitForPageToLoad($this->getTimeoutMsec());
533 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
534 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
535 // $this->assertTrue($this->isTextPresent("$value1 | $value2 | $value3"));
537 // Interview Respondents
538 $this->openCiviPage("survey/search", "reset=1&op=interview", '_qf_Search_refresh');
540 // search for the respondents
542 $this->select('campaign_survey_id', "label=$surveyTitle");
544 // need to wait for Groups field to reload dynamically
548 $this->click('campaignGroupsSelect1');
549 $this->select('campaignGroupsSelect1', "label=$groupName");
550 $this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
551 $this->click('_qf_Search_refresh');
553 $this->waitForElementPresent('_qf_Search_next_print');
554 $this->click("xpath=//table[@class='selector']/tbody//tr[@id='rowid{$id1}']/td[1]");
555 $this->click("mark_x_{$id1}");
557 $this->waitForElementPresent('_qf_Interview_cancel_interview');
559 $this->type("field_{$id1}_phone-Primary-1", 9876543210);
560 $this->click("xpath=//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[2]/../label[text()='$label1']");
561 $this->click("xpath=//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[6]/../label[text()='$label2']");
562 $this->select("field_{$id1}_result", $optionLabel1);
563 $this->click("interview_voter_button_{$id1}");
566 $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit');
568 // Select columns to be displayed
569 $this->check('fields[survey_id]');
570 $this->check('fields[survey_response]');
571 $this->select('survey_id_value', "label=$surveyTitle");
572 $this->select('status_id_value', "label=Interviewed");
573 $this->click('_qf_SurveyDetails_submit');
574 $this->waitForElementPresent('_qf_SurveyDetails_submit_print');
575 $this->assertTrue($this->isTextPresent("Is equal to Interviewed"));
577 // commenting out the print assertion as print dialog which appears breaks the webtest
578 // as it is OS-related and cannot be handled through webtest
580 // $this->click('_qf_SurveyDetails_submit_print');
581 // $this->waitForPageToLoad($this->getTimeoutMsec());
583 // $this->assertTrue($this->isTextPresent("Survey Title = $surveyTitle"));
584 // $this->assertTrue($this->isTextPresent("Q1 = $field1"));
585 // $this->assertTrue($this->isTextPresent("$value1"));
587 // use GOTV (campaign/gotv) to mark the respondents as voted
588 $this->openCiviPage("campaign/gotv", "reset=1");
590 // search for the respondents
592 $this->select('campaign_survey_id', "label=$surveyTitle");
593 // need to wait for Groups field to reload dynamically
597 $this->click('campaignGroupsSelect1');
598 $this->select('campaignGroupsSelect1', "label=$groupName");
599 $this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li");
600 $this->click("xpath=//div[@id='search_form_gotv']/div[2]/table/tbody/tr[6]/td/a[text()='Search']");
602 $this->waitForElementPresent("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]");
603 $this->check("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]/input");
605 // Check title of the activities created
606 $this->openCiviPage("activity/search", "reset=1", '_qf_Search_refresh');
607 $this->select('activity_survey_id', "label=$surveyTitle");
608 $this->click('_qf_Search_refresh');
609 $this->waitForPageToLoad($this->getTimeoutMsec());
611 $this->verifyText("xpath=//table[@class='selector']/tbody//tr/td[5]/a[text()='Smith, $firstName1']/../../td[3]",
612 preg_quote("$surveyTitle - Respondent Interview")
614 $this->verifyText("xpath=//table[@class='selector']/tbody//tr/td[5]/a[text()='John, $firstName2']/../../td[3]",
615 preg_quote("$surveyTitle - Respondent Reservation")