Merge pull request #3792 from jitendrapurohit/CRM-12782AdditionalFix
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OfflineEventRegistrationTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
25*/
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Campaign_OfflineEventRegistrationTest
31 */
6a488035
TO
32class WebTest_Campaign_OfflineEventRegistrationTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCreateCampaign() {
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 // We're using Quick Add block on the main page for this.
47 $firstName1 = substr(sha1(rand()), 0, 7);
48 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
49
50 // add contact to group
51 // visit group tab
52 $this->click("css=li#tab_group a");
53 $this->waitForElementPresent("group_id");
54
55 // add to group
56 $this->select("group_id", "label=$groupName");
57 $this->click("_qf_GroupContact_next");
701f18c0 58 $this->waitForElementPresent('link=Remove');
6a488035
TO
59
60 $firstName2 = substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
62
63 // add contact to group
64 // visit group tab
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
67
68 // add to group
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
701f18c0 71 $this->waitForElementPresent('link=Remove');
6a488035
TO
72
73 // Enable CiviCampaign module if necessary
b9715b8a 74 $this->enableComponents("CiviCampaign");
6a488035 75
42daf119
CW
76 // add the required permission
77 $this->changePermissions("edit-2-administer-civicampaign");
6a488035 78
42daf119 79 // Log in as normal user
6a488035
TO
80 $this->webtestLogin();
81
42daf119 82 $this->openCiviPage("campaign", "reset=1", "link=Add Campaign");
42daf119 83
071a6d2e 84 if ($this->isTextPresent('No campaigns found.')) {
42daf119 85 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
6a488035
TO
86 $this->assertTrue($this->isTextPresent('There are currently no active Campaigns.'));
87 }
42daf119 88 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 89
6a488035
TO
90 $campaignTitle = "Campaign $title";
91 $this->type("title", $campaignTitle);
92
93 // select the campaign type
94 $this->select("campaign_type_id", "value=2");
95
96 // fill in the description
97 $this->type("description", "This is a test campaign");
98
99 // include groups for the campaign
100 $this->addSelection("includeGroups-f", "label=$groupName");
101 $this->click("//option[@value=4]");
102 $this->click("add");
103
104 // fill the end date for campaign
105 $this->webtestFillDate("end_date", "+1 year");
106
107 // select campaign status
108 $this->select("status_id", "value=2");
109
110 // click save
111 $this->click("_qf_Campaign_upload-bottom");
112 $this->waitForPageToLoad($this->getTimeoutMsec());
113
114 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
115 "Status message didn't show up after saving campaign!"
116 );
117
1d4d99e9 118 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
119 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
6a488035
TO
120
121 $this->offlineParticipantAddTest($campaignTitle, $id);
122 }
123
4cbe18b8
EM
124 /**
125 * @param $campaignTitle
126 * @param $id
127 */
6a488035
TO
128 function offlineParticipantAddTest($campaignTitle, $id) {
129 // connect campaign with event
071a6d2e 130 $this->openCiviPage("event/manage", "reset=1");
6a488035
TO
131 $eventId = $this->registerUrl();
132
42daf119 133 $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom");
701f18c0
AS
134 $this->waitForElementPresent('title');
135 $eventName = $this->getAttribute("//*[@id='title']@value");
6a488035
TO
136 // select campaign
137 $this->click("campaign_id");
138 $this->select("campaign_id", "value=$id");
701f18c0 139 $this->waitForElementPresent('_qf_EventInfo_upload_done-bottom');
6a488035
TO
140 $this->click("_qf_EventInfo_upload_done-bottom");
141 $this->waitForPageToLoad($this->getTimeoutMsec());
142
143 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
144 // We're using Quick Add block on the main page for this.
145 $firstName = substr(sha1(rand()), 0, 7);
146 $this->webtestAddContact($firstName, "Anderson", TRUE);
147 $contactName = "Anderson, $firstName";
148 $displayName = "$firstName Anderson";
149
42daf119 150 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
6a488035 151
6a488035 152 // Type contact last name in contact auto-complete, wait for dropdown and click first result
701f18c0 153 $this->webtestFillAutocomplete($firstName, 'contact_id');
6a488035
TO
154
155 // Select event. Based on label for now.
701f18c0 156 $this->select2("event_id", $eventName);
6a488035
TO
157
158 // Select role
1d4d99e9 159 $this->multiselect2("role_id", array('Volunteer'));
6a488035
TO
160
161 // Choose Registration Date.
162 // Using helper webtestFillDate function.
163 $this->webtestFillDate('register_date', 'now');
164 $today = date('F jS, Y', strtotime('now'));
165 // May 5th, 2010
166
167 // Select participant status
168 $this->select("status_id", "value=1");
169
170 // Setting registration source
171 $this->type("source", "Event StandaloneAddTest Webtest");
172
173 // Since we're here, let's check of screen help is being displayed properly
174 $this->assertTrue($this->isTextPresent("Source for this registration (if applicable)."));
175
176 // Select an event fee
177 $this->waitForElementPresent('priceset');
701f18c0 178 $this->click("xpath=//*[@id='priceset']//input[1][@class='crm-form-radio']");
76e86fd8 179
6a488035
TO
180 // Select 'Record Payment'
181 $this->click("record_contribution");
182
183 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
184 $this->type("total_amount", "800");
185
186 // Select payment method = Check and enter chk number
187 $this->select("payment_instrument_id", "value=4");
188 $this->waitForElementPresent("check_number");
189 $this->type("check_number", "1044");
190
191 // go for the chicken combo (obviously)
701f18c0 192 // $this->click("CIVICRM_QFID_chicken_Chicken");
6a488035
TO
193
194 // Clicking save.
195 $this->click("_qf_Participant_upload-bottom");
196 $this->waitForPageToLoad($this->getTimeoutMsec());
197
198 // Is status message correct?
1d4d99e9 199 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
6a488035 200
701f18c0 201 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035 202 //click through to the participant view screen
701f18c0 203 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
204 $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom");
205
206 // verify participant record
207 $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle));
208
42daf119 209 $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom");
6a488035
TO
210 $this->addSelection("enableComponents-t", "label=CiviCampaign");
211 $this->click("//option[@value='CiviCampaign']");
212 $this->click("remove");
213 $this->click("_qf_Component_next-bottom");
214 $this->waitForPageToLoad($this->getTimeoutMsec());
215 $this->assertTrue($this->isTextPresent("Changes Saved."));
216
42daf119 217 $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh");
6a488035
TO
218
219 $this->type('sort_name', $firstName);
220 $this->click("_qf_Search_refresh");
701f18c0 221 $this->waitForElementPresent("xpath=//div[@id='participantSearch']");
6a488035
TO
222 $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
223 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
224 $this->assertTrue($this->isTextPresent("$campaignTitle"));
225 }
226
e9479dcf
EM
227 /**
228 * @return mixed
229 */
6a488035 230 function registerUrl() {
071a6d2e 231 $this->openCiviPage("event/manage", "reset=1");
701f18c0 232 $eventId = explode('-', $this->getAttribute("//div[@id='event_status_id']//div[2]/table/tbody/tr@id"));
6a488035
TO
233 return $eventId[1];
234 }
701f18c0 235
6a488035
TO
236}
237