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