Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-08-20-42-29
[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->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
101
102 // fill the end date for campaign
103 $this->webtestFillDate("end_date", "+1 year");
104
105 // select campaign status
106 $this->select("status_id", "value=2");
107
108 // click save
109 $this->click("_qf_Campaign_upload-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111
112 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
113 "Status message didn't show up after saving campaign!"
114 );
115
116 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
117 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
118
119 $this->offlineParticipantAddTest($campaignTitle, $id);
120 }
121
122 /**
123 * @param $campaignTitle
124 * @param $id
125 */
126 function offlineParticipantAddTest($campaignTitle, $id) {
127 // connect campaign with event
128 $this->openCiviPage("event/manage", "reset=1");
129 $eventId = $this->registerUrl();
130
131 $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom");
132 $this->waitForElementPresent('title');
133 $eventName = $this->getAttribute("//*[@id='title']@value");
134 // select campaign
135 $this->click("campaign_id");
136 $this->select("campaign_id", "value=$id");
137 $this->waitForElementPresent('_qf_EventInfo_upload_done-bottom');
138 $this->click("_qf_EventInfo_upload_done-bottom");
139 $this->waitForPageToLoad($this->getTimeoutMsec());
140
141 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
142 // We're using Quick Add block on the main page for this.
143 $firstName = substr(sha1(rand()), 0, 7);
144 $this->webtestAddContact($firstName, "Anderson", TRUE);
145 $contactName = "Anderson, $firstName";
146 $displayName = "$firstName Anderson";
147
148 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
149
150 // Type contact last name in contact auto-complete, wait for dropdown and click first result
151 $this->webtestFillAutocomplete($firstName, 'contact_id');
152
153 // Select event. Based on label for now.
154 $this->select2("event_id", $eventName);
155
156 // Select role
157 $this->multiselect2("role_id", array('Volunteer'));
158
159 // Choose Registration Date.
160 // Using helper webtestFillDate function.
161 $this->webtestFillDate('register_date', 'now');
162 $today = date('F jS, Y', strtotime('now'));
163 // May 5th, 2010
164
165 // Select participant status
166 $this->select("status_id", "value=1");
167
168 // Setting registration source
169 $this->type("source", "Event StandaloneAddTest Webtest");
170
171 // Since we're here, let's check of screen help is being displayed properly
172 $this->assertTrue($this->isTextPresent("Source for this registration (if applicable)."));
173
174 // Select an event fee
175 $this->waitForElementPresent('priceset');
176 $this->click("xpath=//*[@id='priceset']//input[1][@class='crm-form-radio']");
177
178 // Select 'Record Payment'
179 $this->click("record_contribution");
180
181 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
182 $this->type("total_amount", "800");
183
184 // Select payment method = Check and enter chk number
185 $this->select("payment_instrument_id", "value=4");
186 $this->waitForElementPresent("check_number");
187 $this->type("check_number", "1044");
188
189 // go for the chicken combo (obviously)
190 // $this->click("CIVICRM_QFID_chicken_Chicken");
191
192 // Clicking save.
193 $this->click("_qf_Participant_upload-bottom");
194 $this->waitForPageToLoad($this->getTimeoutMsec());
195
196 // Is status message correct?
197 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
198
199 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
200 //click through to the participant view screen
201 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
202 $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom");
203
204 // verify participant record
205 $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle));
206
207 $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom");
208 $this->addSelection("enableComponents-t", "label=CiviCampaign");
209 $this->click("//option[@value='CiviCampaign']");
210 $this->click("remove");
211 $this->click("_qf_Component_next-bottom");
212 $this->waitForPageToLoad($this->getTimeoutMsec());
213 $this->assertTrue($this->isTextPresent("Changes Saved."));
214
215 $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh");
216
217 $this->type('sort_name', $firstName);
218 $this->click("_qf_Search_refresh");
219 $this->waitForElementPresent("xpath=//div[@id='participantSearch']");
220 $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
221 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
222 $this->assertTrue($this->isTextPresent("$campaignTitle"));
223 }
224
225 /**
226 * @return mixed
227 */
228 function registerUrl() {
229 $this->openCiviPage("event/manage", "reset=1");
230 $eventId = explode('-', $this->getAttribute("//div[@id='event_status_id']//div[2]/table/tbody/tr@id"));
231 return $eventId[1];
232 }
233
234 }
235