Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 | ||
6a488035 TO |
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() { | |
42daf119 | 35 | $this->webtestLogin('admin'); |
6a488035 TO |
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->waitForPageToLoad($this->getTimeoutMsec()); | |
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->waitForPageToLoad($this->getTimeoutMsec()); | |
68 | ||
69 | // Enable CiviCampaign module if necessary | |
b9715b8a | 70 | $this->enableComponents("CiviCampaign"); |
6a488035 | 71 | |
42daf119 CW |
72 | // add the required permission |
73 | $this->changePermissions("edit-2-administer-civicampaign"); | |
6a488035 | 74 | |
42daf119 | 75 | // Log in as normal user |
6a488035 TO |
76 | $this->webtestLogin(); |
77 | ||
42daf119 | 78 | $this->openCiviPage("campaign", "reset=1", "link=Add Campaign"); |
42daf119 | 79 | |
071a6d2e | 80 | if ($this->isTextPresent('No campaigns found.')) { |
42daf119 | 81 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); |
6a488035 TO |
82 | $this->assertTrue($this->isTextPresent('There are currently no active Campaigns.')); |
83 | } | |
42daf119 | 84 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
6a488035 | 85 | |
6a488035 TO |
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 | |
071a6d2e | 122 | $this->openCiviPage("event/manage", "reset=1"); |
6a488035 TO |
123 | $eventId = $this->registerUrl(); |
124 | ||
42daf119 | 125 | $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom"); |
6a488035 TO |
126 | |
127 | // select campaign | |
128 | $this->click("campaign_id"); | |
129 | $this->select("campaign_id", "value=$id"); | |
130 | $this->click("_qf_EventInfo_upload_done-bottom"); | |
131 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
132 | ||
133 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) | |
134 | // We're using Quick Add block on the main page for this. | |
135 | $firstName = substr(sha1(rand()), 0, 7); | |
136 | $this->webtestAddContact($firstName, "Anderson", TRUE); | |
137 | $contactName = "Anderson, $firstName"; | |
138 | $displayName = "$firstName Anderson"; | |
139 | ||
42daf119 | 140 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); |
6a488035 | 141 | |
6a488035 TO |
142 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
143 | $this->webtestFillAutocomplete($firstName); | |
144 | ||
145 | // Select event. Based on label for now. | |
146 | $this->select("event_id", "value=$eventId"); | |
147 | ||
148 | // Select role | |
149 | $this->click("role_id[2]"); | |
150 | ||
151 | // Choose Registration Date. | |
152 | // Using helper webtestFillDate function. | |
153 | $this->webtestFillDate('register_date', 'now'); | |
154 | $today = date('F jS, Y', strtotime('now')); | |
155 | // May 5th, 2010 | |
156 | ||
157 | // Select participant status | |
158 | $this->select("status_id", "value=1"); | |
159 | ||
160 | // Setting registration source | |
161 | $this->type("source", "Event StandaloneAddTest Webtest"); | |
162 | ||
163 | // Since we're here, let's check of screen help is being displayed properly | |
164 | $this->assertTrue($this->isTextPresent("Source for this registration (if applicable).")); | |
165 | ||
166 | // Select an event fee | |
167 | $this->waitForElementPresent('priceset'); | |
168 | $this->click("xpath=//div[@id='priceset']//input[1][@class='form-radio']"); | |
76e86fd8 | 169 | |
6a488035 TO |
170 | // Select 'Record Payment' |
171 | $this->click("record_contribution"); | |
172 | ||
173 | // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle) | |
174 | $this->type("total_amount", "800"); | |
175 | ||
176 | // Select payment method = Check and enter chk number | |
177 | $this->select("payment_instrument_id", "value=4"); | |
178 | $this->waitForElementPresent("check_number"); | |
179 | $this->type("check_number", "1044"); | |
180 | ||
181 | // go for the chicken combo (obviously) | |
182 | // $this->click("CIVICRM_QFID_chicken_Chicken"); | |
183 | ||
184 | // Clicking save. | |
185 | $this->click("_qf_Participant_upload-bottom"); | |
186 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
187 | ||
188 | // Is status message correct? | |
189 | $this->assertTrue($this->isTextPresent("Event registration for $displayName has been added"), "Status message didn't show up after saving!"); | |
190 | ||
191 | $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
192 | //click through to the participant view screen | |
193 | $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); | |
194 | $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom"); | |
195 | ||
196 | // verify participant record | |
197 | $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle)); | |
198 | ||
42daf119 | 199 | $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom"); |
6a488035 TO |
200 | $this->addSelection("enableComponents-t", "label=CiviCampaign"); |
201 | $this->click("//option[@value='CiviCampaign']"); | |
202 | $this->click("remove"); | |
203 | $this->click("_qf_Component_next-bottom"); | |
204 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
205 | $this->assertTrue($this->isTextPresent("Changes Saved.")); | |
206 | ||
42daf119 | 207 | $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh"); |
6a488035 TO |
208 | |
209 | $this->type('sort_name', $firstName); | |
210 | $this->click("_qf_Search_refresh"); | |
211 | $this->waitForElementPresent("_qf_Search_next_print"); | |
212 | $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); | |
213 | $this->waitForElementPresent("_qf_Participant_cancel-bottom"); | |
214 | $this->assertTrue($this->isTextPresent("$campaignTitle")); | |
215 | } | |
216 | ||
217 | function registerUrl() { | |
071a6d2e | 218 | $this->openCiviPage("event/manage", "reset=1"); |
6a488035 TO |
219 | $eventId = explode('_', $this->getAttribute("//div[@id='event_status_id']//table/tbody/tr@id")); |
220 | return $eventId[1]; | |
221 | } | |
222 | } | |
223 |