3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_OfflineEventRegistrationTest
32 class WebTest_Campaign_OfflineEventRegistrationTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
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");
50 // add contact to group
52 $this->click("css=li#tab_group a");
53 $this->waitForElementPresent("group_id");
56 $this->select("group_id", "label=$groupName");
57 $this->click("_qf_GroupContact_next");
58 $this->waitForElementPresent('link=Remove');
60 $firstName2 = substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
63 // add contact to group
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
71 $this->waitForElementPresent('link=Remove');
73 // Enable CiviCampaign module if necessary
74 $this->enableComponents("CiviCampaign");
76 // add the required permission
77 $this->changePermissions("edit-2-administer-civicampaign");
79 // Log in as normal user
80 $this->webtestLogin();
82 $this->openCiviPage("campaign", "reset=1", "link=Add Campaign");
84 if ($this->isTextPresent('No campaigns 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.'));
88 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
90 $campaignTitle = "Campaign $title";
91 $this->type("title", $campaignTitle);
93 // select the campaign type
94 $this->select("campaign_type_id", "value=2");
96 // fill in the description
97 $this->type("description", "This is a test campaign");
99 // include groups for the campaign
100 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
102 // fill the end date for campaign
103 $this->webtestFillDate("end_date", "+1 year");
105 // select campaign status
106 $this->select("status_id", "value=2");
109 $this->click("_qf_Campaign_upload-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
112 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
113 "Status message didn't show up after saving campaign!"
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]");
119 $this->offlineParticipantAddTest($campaignTitle, $id);
123 * @param $campaignTitle
126 function offlineParticipantAddTest($campaignTitle, $id) {
127 // connect campaign with event
128 $this->openCiviPage("event/manage", "reset=1");
129 $eventId = $this->registerUrl();
131 $this->openCiviPage('event/manage/settings', "reset=1&action=update&id=$eventId", "_qf_EventInfo_cancel-bottom");
132 $this->waitForElementPresent('title');
133 $eventName = $this->getAttribute("//*[@id='title']@value");
135 $this->click("campaign_id");
136 $this->select("campaign_id", "value=$id");
137 $this->waitForElementPresent('_qf_EventInfo_upload_done-bottom');
138 $this->clickLink("_qf_EventInfo_upload_done-bottom");
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";
147 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
149 // Type contact last name in contact auto-complete, wait for dropdown and click first result
150 $this->webtestFillAutocomplete($firstName);
152 // Select event. Based on label for now.
153 $this->select2("event_id", $eventName);
156 $this->multiselect2("role_id", array('Volunteer'));
158 // Choose Registration Date.
159 // Using helper webtestFillDate function.
160 $this->webtestFillDate('register_date', 'now');
161 $today = date('F jS, Y', strtotime('now'));
164 // Select participant status
165 $this->select("status_id", "value=1");
167 // Setting registration source
168 $this->type("source", "Event StandaloneAddTest Webtest");
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)."));
173 // Select an event fee
174 $this->waitForElementPresent('priceset');
175 $this->click("xpath=//*[@id='priceset']//input[1][@class='crm-form-radio']");
177 // Select 'Record Payment'
178 $this->click("record_contribution");
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");
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");
188 // go for the chicken combo (obviously)
189 // $this->click("CIVICRM_QFID_chicken_Chicken");
192 $this->click("_qf_Participant_upload-bottom");
193 $this->waitForPageToLoad($this->getTimeoutMsec());
195 // Is status message correct?
196 $this->waitForText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
198 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
199 //click through to the participant view screen
200 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
201 $this->waitForElementPresent("_qf_ParticipantView_cancel-bottom");
203 // verify participant record
204 $this->verifyText("xpath=id('ParticipantView')/div[2]/table[1]/tbody/tr[3]/td[2]", preg_quote($campaignTitle));
206 $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom");
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());
212 $this->assertTrue($this->isTextPresent("Changes Saved."));
214 $this->openCiviPage("event/search", "reset=1", "_qf_Search_refresh");
216 $this->type('sort_name', $firstName);
217 $this->click("_qf_Search_refresh");
218 $this->waitForElementPresent("xpath=//div[@id='participantSearch']");
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"));
227 function registerUrl() {
228 $this->openCiviPage("event/manage", "reset=1");
229 $eventId = explode('-', $this->getAttribute("//div[@id='event_status_id']//div[2]/table/tbody/tr@id"));