Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Campaign_OfflineEventRegistrationTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testCreateCampaign() { | |
36 | // This is the path where our testing install resides. | |
37 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
38 | // class attributes. | |
39 | $this->open($this->sboxPath); | |
40 | ||
41 | // Logging in. Remember to wait for page to load. In most cases, | |
42 | // you can rely on 30000 as the value that allows your test to pass, however, | |
43 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
44 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
45 | // page contents loaded and you can continue your test execution. | |
46 | $this->webtestLogin(); | |
47 | ||
48 | // Create new group | |
49 | $title = substr(sha1(rand()), 0, 7); | |
50 | $groupName = $this->WebtestAddGroup(); | |
51 | ||
52 | // Adding contact | |
53 | // We're using Quick Add block on the main page for this. | |
54 | $firstName1 = substr(sha1(rand()), 0, 7); | |
55 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); | |
56 | ||
57 | // add contact to group | |
58 | // visit group tab | |
59 | $this->click("css=li#tab_group a"); | |
60 | $this->waitForElementPresent("group_id"); | |
61 | ||
62 | // add to group | |
63 | $this->select("group_id", "label=$groupName"); | |
64 | $this->click("_qf_GroupContact_next"); | |
65 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
66 | ||
67 | $firstName2 = substr(sha1(rand()), 0, 7); | |
68 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org"); | |
69 | ||
70 | // add contact to group | |
71 | // visit group tab | |
72 | $this->click("css=li#tab_group a"); | |
73 | $this->waitForElementPresent("group_id"); | |
74 | ||
75 | // add to group | |
76 | $this->select("group_id", "label=$groupName"); | |
77 | $this->click("_qf_GroupContact_next"); | |
78 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
79 | ||
80 | // Enable CiviCampaign module if necessary | |
b9715b8a | 81 | $this->enableComponents("CiviCampaign"); |
6a488035 TO |
82 | |
83 | // now logout and login with admin credentials | |
84 | $this->open($this->sboxPath . "civicrm/logout?reset=1"); | |
85 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
86 | ||
87 | //make sure we do have required permissions. | |
88 | $this->webtestLogin(TRUE); | |
89 | ||
90 | // add the required Drupal permission | |
91 | $permissions = array("edit-2-administer-civicampaign"); | |
92 | $this->changePermissions($permissions); | |
93 | ||
94 | // now logout and do membership test that way | |
95 | $this->open($this->sboxPath . "civicrm/logout?reset=1"); | |
96 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
97 | ||
98 | $this->webtestLogin(); | |
99 | ||
100 | $this->open($this->sboxPath . 'civicrm/campaign?reset=1'); | |
101 | $this->waitForElementPresent("link=Add Campaign"); | |
102 | if ($this->isTextPresent('No campaigns found.')) { | |
103 | // Go directly to the URL of the screen that you will be testing (Register Participant for Event-standalone). | |
104 | $this->open($this->sboxPath . "civicrm/participant/add?reset=1&action=add&context=standalone"); | |
105 | $this->waitForElementPresent("_qf_Participant_upload-bottom"); | |
106 | $this->assertTrue($this->isTextPresent('There are currently no active Campaigns.')); | |
107 | } | |
108 | ||
109 | // Go directly to the URL of the screen that you will be testing | |
110 | $this->open($this->sboxPath . "civicrm/campaign/add?reset=1"); | |
111 | ||
112 | // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
113 | // button at the end of this page to show up, to make sure it's fully loaded. | |
114 | $this->waitForElementPresent("_qf_Campaign_upload-bottom"); | |
115 | ||
116 | // Let's start filling the form with values. | |
117 | $campaignTitle = "Campaign $title"; | |
118 | $this->type("title", $campaignTitle); | |
119 | ||
120 | // select the campaign type | |
121 | $this->select("campaign_type_id", "value=2"); | |
122 | ||
123 | // fill in the description | |
124 | $this->type("description", "This is a test campaign"); | |
125 | ||
126 | // include groups for the campaign | |
127 | $this->addSelection("includeGroups-f", "label=$groupName"); | |
128 | $this->click("//option[@value=4]"); | |
129 | $this->click("add"); | |
130 | ||
131 | // fill the end date for campaign | |
132 | $this->webtestFillDate("end_date", "+1 year"); | |
133 | ||
134 | // select campaign status | |
135 | $this->select("status_id", "value=2"); | |
136 | ||
137 | // click save | |
138 | $this->click("_qf_Campaign_upload-bottom"); | |
139 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
140 | ||
141 | $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."), | |
142 | "Status message didn't show up after saving campaign!" | |
143 | ); | |
144 | ||
145 | $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); | |
146 | $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); | |
147 | ||
148 | $this->offlineParticipantAddTest($campaignTitle, $id); | |
149 | } | |
150 | ||
151 | function offlineParticipantAddTest($campaignTitle, $id) { | |
152 | // connect campaign with event | |
153 | $this->open($this->sboxPath . "civicrm/event/manage&reset=1"); | |
154 | $eventId = $this->registerUrl(); | |
155 | ||
156 | $this->open($this->sboxPath . "civicrm/event/manage/settings?reset=1&action=update&id=$eventId"); | |
157 | $this->waitForElementPresent("_qf_EventInfo_cancel-bottom"); | |
158 | ||
159 | // select campaign | |
160 | $this->click("campaign_id"); | |
161 | $this->select("campaign_id", "value=$id"); | |
162 | $this->click("_qf_EventInfo_upload_done-bottom"); | |
163 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
164 | ||
165 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) | |
166 | // We're using Quick Add block on the main page for this. | |
167 | $firstName = substr(sha1(rand()), 0, 7); | |
168 | $this->webtestAddContact($firstName, "Anderson", TRUE); | |
169 | $contactName = "Anderson, $firstName"; | |
170 | $displayName = "$firstName Anderson"; | |
171 | ||
172 | // Go directly to the URL of the screen that you will be testing (Register Participant for Event-standalone). | |
173 | $this->open($this->sboxPath . "civicrm/participant/add?reset=1&action=add&context=standalone"); | |
174 | ||
175 | // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
176 | // button at the end of this page to show up, to make sure it's fully loaded. | |
177 | $this->waitForElementPresent("_qf_Participant_upload-bottom"); | |
178 | ||
179 | // Let's start filling the form with values. | |
180 | // Type contact last name in contact auto-complete, wait for dropdown and click first result | |
181 | $this->webtestFillAutocomplete($firstName); | |
182 | ||
183 | // Select event. Based on label for now. | |
184 | $this->select("event_id", "value=$eventId"); | |
185 | ||
186 | // Select role | |
187 | $this->click("role_id[2]"); | |
188 | ||
189 | // Choose Registration Date. | |
190 | // Using helper webtestFillDate function. | |
191 | $this->webtestFillDate('register_date', 'now'); | |
192 | $today = date('F jS, Y', strtotime('now')); | |
193 | // May 5th, 2010 | |
194 | ||
195 | // Select participant status | |
196 | $this->select("status_id", "value=1"); | |
197 | ||
198 | // Setting registration source | |
199 | $this->type("source", "Event StandaloneAddTest Webtest"); | |
200 | ||
201 | // Since we're here, let's check of screen help is being displayed properly | |
202 | $this->assertTrue($this->isTextPresent("Source for this registration (if applicable).")); | |
203 | ||
204 | // Select an event fee | |
205 | $this->waitForElementPresent('priceset'); | |
206 | $this->click("xpath=//div[@id='priceset']//input[1][@class='form-radio']"); | |
207 | ||
208 | // Select 'Record Payment' | |
209 | $this->click("record_contribution"); | |
210 | ||
211 | // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle) | |
212 | $this->type("total_amount", "800"); | |
213 | ||
214 | // Select payment method = Check and enter chk number | |
215 | $this->select("payment_instrument_id", "value=4"); | |
216 | $this->waitForElementPresent("check_number"); | |
217 | $this->type("check_number", "1044"); | |
218 | ||
219 | // go for the chicken combo (obviously) | |
220 | // $this->click("CIVICRM_QFID_chicken_Chicken"); | |
221 | ||
222 | // Clicking save. | |
223 | $this->click("_qf_Participant_upload-bottom"); | |
224 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
225 | ||
226 | // Is status message correct? | |
227 | $this->assertTrue($this->isTextPresent("Event registration for $displayName has been added"), "Status message didn't show up after saving!"); | |
228 | ||
229 | $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
230 | //click through to the participant view screen | |
231 | $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
232 | $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom"); | |
233 | ||
234 | // verify participant record | |
235 | $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle)); | |
236 | ||
237 | $this->open($this->sboxPath . 'civicrm/admin/setting/component?reset=1'); | |
238 | $this->waitForElementPresent("_qf_Component_next-bottom"); | |
239 | $this->addSelection("enableComponents-t", "label=CiviCampaign"); | |
240 | $this->click("//option[@value='CiviCampaign']"); | |
241 | $this->click("remove"); | |
242 | $this->click("_qf_Component_next-bottom"); | |
243 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
244 | $this->assertTrue($this->isTextPresent("Changes Saved.")); | |
245 | ||
246 | $this->open($this->sboxPath . 'civicrm/event/search?reset=1'); | |
247 | $this->waitForElementPresent("_qf_Search_refresh"); | |
248 | ||
249 | $this->type('sort_name', $firstName); | |
250 | $this->click("_qf_Search_refresh"); | |
251 | $this->waitForElementPresent("_qf_Search_next_print"); | |
252 | $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); | |
253 | $this->waitForElementPresent("_qf_Participant_cancel-bottom"); | |
254 | $this->assertTrue($this->isTextPresent("$campaignTitle")); | |
255 | } | |
256 | ||
257 | function registerUrl() { | |
258 | $this->open($this->sboxPath . 'civicrm/event/manage?reset=1'); | |
259 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
260 | $eventId = explode('_', $this->getAttribute("//div[@id='event_status_id']//table/tbody/tr@id")); | |
261 | return $eventId[1]; | |
262 | } | |
263 | } | |
264 |