Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-23-18-25-12
[civicrm-core.git] / tests / phpunit / WebTest / Event / ChangeParticipantStatus.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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_Event_ChangeParticipantStatus
31 */
32 class WebTest_Event_ChangeParticipantStatus extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testParticipationAdd() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
43 // We're using Quick Add block on the main page for this.
44 $firstName1 = substr(sha1(rand()), 0, 7);
45 $this->webtestAddContact($firstName1, 'Anderson', TRUE);
46 $sortName1 = "Anderson, $firstName1";
47 $this->addParticipant($firstName1);
48
49 $firstName2 = substr(sha1(rand()), 0, 7);
50 $this->webtestAddContact($firstName2, 'Anderson', TRUE);
51 $sortName2 = "Anderson, $firstName2";
52 $this->addParticipant($firstName2);
53
54 // Search the participants
55 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
56
57 $eventName = 'Rain';
58 $this->click("event_name");
59 $this->type("event_name", $eventName);
60 $this->typeKeys("event_name", $eventName);
61 $this->waitForElementPresent("css=div.ac_results-inner li");
62 $this->click("css=div.ac_results-inner li");
63 $this->assertContains($eventName, $this->getValue("event_name"), "autocomplete expected $eventName but didn’t find it in " . $this->getValue("event_name"));
64 $this->click('_qf_Search_refresh');
65
66 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']");
67 $id1 = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[1]/input@id");
68 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[1]/");
69 $this->click($id1);
70
71 $id2 = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[1]/input@id");
72 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[1]/");
73 $this->click($id2);
74
75 // Change participant status for selected participants
76 $this->select('task', "label=Change Participant Status");
77 $this->click('Go');
78 $this->waitForElementPresent('_qf_ParticipantStatus_next');
79
80 $this->select('status_change', "label=Attended");
81 $this->click('_qf_ParticipantStatus_next');
82 $this->waitForElementPresent('Go');
83 $this->assertTrue($this->isTextPresent('The updates have been saved.'),
84 "Status message didn't show up after saving!"
85 );
86
87 // Verify the changed status
88 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
89 $this->type('sort_name', $firstName1);
90 $this->click('_qf_Search_refresh');
91 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']");
92 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[11]/span/a[text()='View']");
93 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
94 $this->webtestVerifyTabularData(array('Status' => 'Attended'));
95
96 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
97 $this->type('sort_name', $firstName2);
98 $this->click('_qf_Search_refresh');
99 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']");
100 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[11]/span/a[text()='View']");
101 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
102 $this->webtestVerifyTabularData(array('Status' => 'Attended'));
103 }
104
105 /**
106 * @param $firstName
107 */
108 function addParticipant($firstName) {
109 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", '_qf_Participant_upload-bottom');
110
111 // Type contact last name in contact auto-complete, wait for dropdown and click first result
112 $this->webtestFillAutocomplete($firstName);
113
114 // Select event. Based on label for now.
115 $this->select('event_id', "label=regexp:Rain-forest Cup Youth Soccer Tournament.");
116
117 // Select role
118 $this->click('role_id[2]');
119
120 // Choose Registration Date.
121 // Using helper webtestFillDate function.
122 $this->webtestFillDate('register_date', 'now');
123 $today = date('F jS, Y', strtotime('now'));
124
125 // Select participant status
126 $this->select('status_id', 'value=1');
127
128 // Setting registration source
129 $this->type('source', 'Event StandaloneAddTest Webtest');
130
131 // Since we're here, let's check of screen help is being displayed properly
132 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
133
134 // Select an event fee
135 $this->waitForElementPresent('priceset');
136
137 $this->click("xpath=//input[@class='form-radio']");
138 // Select 'Record Payment'
139 $this->click('record_contribution');
140
141 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
142 $this->type('total_amount', '800');
143
144 // Select payment method = Check and enter chk number
145 $this->select('payment_instrument_id', 'value=4');
146 $this->waitForElementPresent('check_number');
147 $this->type('check_number', '1044');
148
149 // Clicking save.
150 $this->click('_qf_Participant_upload-bottom');
151 $this->waitForPageToLoad($this->getTimeoutMsec());
152
153 // Is status message correct?
154 $this->assertTrue($this->isTextPresent("Event registration for $firstName Anderson has been added"),
155 "Status message didn't show up after saving!"
156 );
157
158 $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
159 //click through to the participant view screen
160 $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
161 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
162
163 $this->webtestVerifyTabularData(
164 array(
165 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
166 'Participant Role' => 'Attendee',
167 'Status' => 'Registered',
168 'Event Source' => 'Event StandaloneAddTest Webtest',
169 'Event Fees' => '$ 800.00',
170 )
171 );
172 }
173 }
174