Webtest fix
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OfflineEventRegistrationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 public 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('None 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->waitForAjaxContent();
101 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
102
103 // fill the end date for campaign
104 $this->webtestFillDate("end_date", "+1 year");
105
106 // select campaign status
107 $this->select("status_id", "value=2");
108
109 // click save
110 $this->click("_qf_Campaign_upload-bottom");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
112
113 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
114 "Status message didn't show up after saving campaign!"
115 );
116
117 $this->waitForElementPresent("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
118 $id = (int) $this->getText("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
119
120 $this->offlineParticipantAddTest($campaignTitle, $id);
121 }
122
123 /**
124 * @param $campaignTitle
125 * @param int $id
126 */
127 public function offlineParticipantAddTest($campaignTitle, $id) {
128 // connect campaign with event
129 $this->openCiviPage("event/manage", "reset=1");
130 $eventId = $this->registerUrl();
131
132 $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom");
133 $this->waitForElementPresent('title');
134 $eventName = $this->getAttribute("//*[@id='title']@value");
135 // select campaign
136 $this->click("campaign_id");
137 $this->select("campaign_id", "value=$id");
138 $this->waitForElementPresent('_qf_EventInfo_upload_done-bottom');
139 $this->clickLink("_qf_EventInfo_upload_done-bottom");
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);
152
153 // Select event. Based on label for now.
154 $this->select2("event_id", $eventName);
155
156 // Select role
157 $this->waitForAjaxContent();
158 $this->multiselect2("role_id", array('Volunteer'));
159
160 // Choose Registration Date.
161 // Using helper webtestFillDate function.
162 $this->webtestFillDate('register_date', 'now');
163 $today = date('F jS, Y', strtotime('now'));
164 // May 5th, 2010
165
166 // Select participant status
167 $this->select("status_id", "value=1");
168
169 // Setting registration source
170 $this->type("source", "Event StandaloneAddTest Webtest");
171
172 // Since we're here, let's check of screen help is being displayed properly
173 $this->assertTrue($this->isTextPresent("Source for this registration (if applicable)."));
174
175 // Select an event fee
176 $this->waitForElementPresent('priceset');
177 $this->click("xpath=//*[@id='priceset']//input[1][@class='crm-form-radio']");
178
179 // Select 'Record Payment'
180 $this->click("record_contribution");
181
182 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
183 $this->type("total_amount", "800");
184
185 // Select payment method = Check and enter chk number
186 $this->select("payment_instrument_id", "value=4");
187 $this->waitForElementPresent("check_number");
188 $this->type("check_number", "1044");
189
190 // go for the chicken combo (obviously)
191 // $this->click("CIVICRM_QFID_chicken_Chicken");
192
193 // Clicking save.
194 $this->click("_qf_Participant_upload-bottom");
195 $this->waitForPageToLoad($this->getTimeoutMsec());
196
197 // Is status message correct?
198 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
199
200 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
201 //click through to the participant view screen
202 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
203 $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom");
204
205 // verify participant record
206 $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle));
207
208 $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom");
209 $this->addSelection("enableComponents-t", "label=CiviCampaign");
210 $this->click("//option[@value='CiviCampaign']");
211 $this->click("remove");
212 $this->click("_qf_Component_next-bottom");
213 $this->waitForPageToLoad($this->getTimeoutMsec());
214 $this->assertTrue($this->isTextPresent("Changes Saved"));
215
216 $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh");
217
218 $this->type('sort_name', $firstName);
219 $this->click("_qf_Search_refresh");
220 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']");
221 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[11]/span/a[text()='Edit']");
222 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
223 $this->assertTrue($this->isTextPresent("$campaignTitle"));
224 }
225
226 /**
227 * @return mixed
228 */
229 public function registerUrl() {
230 $this->openCiviPage("event/manage", "reset=1");
231 $eventId = explode('-', $this->getAttribute("//div[@id='event_status_id']//div[2]/table/tbody/tr@id"));
232 return $eventId[1];
233 }
234
235 }