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