Merge branch 'master' of https://github.com/rollox/civicrm-core into CRM-18317
[civicrm-core.git] / tests / phpunit / WebTest / Event / ChangeParticipantStatus.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 public 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-forest Cup Youth Soccer Tournament';
58 $this->select2("event_id", $eventName);
59 $this->click('_qf_Search_refresh');
60
61 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']");
62 $id1 = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[1]/input@id");
63 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[1]/");
64 $this->click($id1);
65
66 $id2 = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[1]/input@id");
67 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[1]/");
68 $this->click($id2);
69
70 // Change participant status for selected participants
71 $this->select('task', "label=Participant status - change (emails sent)");
72 $this->waitForElementPresent('_qf_ParticipantStatus_next');
73
74 $this->select('status_change', "label=Attended");
75 $this->clickLink('_qf_ParticipantStatus_next');
76 $this->assertTrue($this->isTextPresent('The updates have been saved.'),
77 "Status message didn't show up after saving!"
78 );
79
80 // Verify the changed status
81 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
82 $this->type('sort_name', $firstName1);
83 $this->click('_qf_Search_refresh');
84 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']");
85 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName1']/../../td[11]/span/a[text()='View']");
86 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
87 $this->webtestVerifyTabularData(array('Status' => 'Attended'));
88
89 $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh');
90 $this->type('sort_name', $firstName2);
91 $this->click('_qf_Search_refresh');
92 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']");
93 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[text()='$sortName2']/../../td[11]/span/a[text()='View']");
94 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
95 $this->webtestVerifyTabularData(array('Status' => 'Attended'));
96 }
97
98 /**
99 * @param string $firstName
100 */
101 public function addParticipant($firstName) {
102 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", '_qf_Participant_upload-bottom');
103
104 // Type contact last name in contact auto-complete, wait for dropdown and click first result
105 $this->webtestFillAutocomplete($firstName);
106
107 // Select event. Based on label for now.
108 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
109
110 // Select role
111 $this->multiselect2('role_id', array('Volunteer'));
112
113 // Choose Registration Date.
114 // Using helper webtestFillDate function.
115 $this->webtestFillDate('register_date', 'now');
116 $today = date('F jS, Y', strtotime('now'));
117
118 // Select participant status
119 $this->select('status_id', 'value=1');
120
121 // Setting registration source
122 $this->type('source', 'Event StandaloneAddTest Webtest');
123
124 // Since we're here, let's check of screen help is being displayed properly
125 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
126
127 // Select an event fee
128 $this->waitForElementPresent('priceset');
129
130 $this->click("xpath=//input[@class='crm-form-radio']");
131 // Select 'Record Payment'
132 $this->click('record_contribution');
133
134 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
135 $this->type('total_amount', '800');
136
137 // Select payment method = Check and enter chk number
138 $this->select('payment_instrument_id', 'value=4');
139 $this->waitForElementPresent('check_number');
140 $this->type('check_number', '1044');
141
142 // Clicking save.
143 $this->click('_qf_Participant_upload-bottom');
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145
146 // Is status message correct?
147 $this->assertTrue($this->isTextPresent("Event registration for $firstName Anderson has been added"),
148 "Status message didn't show up after saving!"
149 );
150
151 $this->waitForElementPresent("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
152 //click through to the participant view screen
153 $this->click("xpath=//*[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
154 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
155
156 $this->webtestVerifyTabularData(
157 array(
158 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
159 'Participant Role' => 'Attendee',
160 'Status' => 'Registered',
161 'Event Source' => 'Event StandaloneAddTest Webtest',
162 )
163 );
164 $this->verifyText("xpath=//td[text()='Selections']/following-sibling::td//div", preg_quote('Event Total: $ 800.00'));
165 }
166
167 }