Merge pull request #3614 from eileenmcnaughton/CRM-14951
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OfflineEventRegistrationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Campaign_OfflineEventRegistrationTest
31 */
32 class WebTest_Campaign_OfflineEventRegistrationTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
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");
58 $this->waitForElementPresent('link=Remove');
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");
71 $this->waitForElementPresent('link=Remove');
72
73 // Enable CiviCampaign module if necessary
74 $this->enableComponents("CiviCampaign");
75
76 // add the required permission
77 $this->changePermissions("edit-2-administer-civicampaign");
78
79 // Log in as normal user
80 $this->webtestLogin();
81
82 $this->openCiviPage("campaign", "reset=1", "link=Add Campaign");
83
84 if ($this->isTextPresent('No campaigns found.')) {
85 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
86 $this->assertTrue($this->isTextPresent('There are currently no active Campaigns.'));
87 }
88 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
89
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
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]");
120
121 $this->offlineParticipantAddTest($campaignTitle, $id);
122 }
123
124 /**
125 * @param $campaignTitle
126 * @param $id
127 */
128 function offlineParticipantAddTest($campaignTitle, $id) {
129 // connect campaign with event
130 $this->openCiviPage("event/manage", "reset=1");
131 $eventId = $this->registerUrl();
132
133 $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom");
134 $this->waitForElementPresent('title');
135 $eventName = $this->getAttribute("//*[@id='title']@value");
136 // select campaign
137 $this->click("campaign_id");
138 $this->select("campaign_id", "value=$id");
139 $this->waitForElementPresent('_qf_EventInfo_upload_done-bottom');
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
150 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
151
152 // Type contact last name in contact auto-complete, wait for dropdown and click first result
153 $this->webtestFillAutocomplete($firstName, 'contact_id');
154
155 // Select event. Based on label for now.
156 $this->select2("event_id", $eventName);
157
158 // Select role
159 $this->multiselect2("role_id", array('Volunteer'));
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');
178 $this->click("xpath=//*[@id='priceset']//input[1][@class='crm-form-radio']");
179
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)
192 // $this->click("CIVICRM_QFID_chicken_Chicken");
193
194 // Clicking save.
195 $this->click("_qf_Participant_upload-bottom");
196 $this->waitForPageToLoad($this->getTimeoutMsec());
197
198 // Is status message correct?
199 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
200
201 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
202 //click through to the participant view screen
203 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
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
209 $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom");
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
217 $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh");
218
219 $this->type('sort_name', $firstName);
220 $this->click("_qf_Search_refresh");
221 $this->waitForElementPresent("xpath=//div[@id='participantSearch']");
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
227 /**
228 * @return mixed
229 */
230 function registerUrl() {
231 $this->openCiviPage("event/manage", "reset=1");
232 $eventId = explode('-', $this->getAttribute("//div[@id='event_status_id']//div[2]/table/tbody/tr@id"));
233 return $eventId[1];
234 }
235
236 }
237