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