Cleanup phpdoc comments
[civicrm-core.git] / tests / phpunit / WebTest / Member / BatchUpdateViaProfileTest.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_Member_BatchUpdateViaProfileTest
31 */
32 class WebTest_Member_BatchUpdateViaProfileTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testMemberAdd() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
43 $memTypeParams = $this->webtestAddMembershipType();
44
45 $endDate = date('F jS, Y', strtotime("+1 year +1 month -1 day"));
46
47 // Add new individual using Quick Add block on the main page
48 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
49 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);
50 $Name1 = $lastName . ', ' . $firstName1;
51 $this->webtestAddContact($firstName1, $lastName, "$firstName1.$lastName@example.com");
52
53 // Add membership for this individual
54 $this->_addMembership($memTypeParams);
55 // Is status message correct?
56 $this->waitForText('crm-notification-container', "membership for $firstName1 $lastName has been added");
57
58 // click through to the membership view screen
59 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
60 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
61
62 // Verify End date
63 $verifyData = array(
64 'Membership Type' => $memTypeParams['membership_type'],
65 'Status' => 'New',
66 'End date' => $endDate,
67 );
68 $this->webtestVerifyTabularData($verifyData);
69
70 // Add new individual using Quick Add block on the main page
71 $firstName2 = "John_" . substr(sha1(rand()), 0, 7);
72 $Name2 = $lastName . ', ' . $firstName2;
73 $this->webtestAddContact($firstName2, $lastName, "$firstName2.$lastName@example.com");
74
75 // Add membership for this individual
76 $this->_addMembership($memTypeParams);
77 // Is status message correct?
78
79 $this->waitForText('crm-notification-container', "membership for $firstName2 $lastName has been added.");
80
81 // click through to the membership view screen
82 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
83 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
84
85 // Verify End date
86 $verifyData = array(
87 'Membership Type' => $memTypeParams['membership_type'],
88 'Status' => 'New',
89 'End date' => $endDate,
90 );
91 $this->webtestVerifyTabularData($verifyData);
92
93 $profileTitle = 'Profile_' . substr(sha1(rand()), 0, 4);
94 $customDataParams = $this->_addCustomData();
95 $this->_addProfile($profileTitle, $customDataParams);
96
97 // Find Members
98 $this->openCiviPage("member/search", "reset=1", '_qf_Search_refresh');
99
100 $this->type('sort_name', $lastName);
101 $this->click('_qf_Search_refresh');
102
103 // Batch Update Via Profile
104 $this->waitForElementPresent("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/input");
105 $this->click("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/input");
106 //$this->click('CIVICRM_QFID_ts_all_10');
107 $this->select('task', "label=Batch Update Members Via Profile");
108 $this->waitForElementPresent('_qf_PickProfile_back-bottom');
109 $this->waitForElementPresent('uf_group_id');
110 $this->select('uf_group_id', "label={$profileTitle}");
111 $this->click('_qf_PickProfile_next-bottom');
112
113 $this->waitForElementPresent('_qf_Batch_back-bottom');
114 $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[3]/input", "This is test custom data text1");
115 $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[4]/select", "label=Current");
116
117 $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[3]/input", "This is test custom data text2");
118 $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[4]/select", "label=Grace");
119
120 $this->click('_qf_Batch_next-bottom');
121 $this->waitForElementPresent('_qf_Result_done');
122 $this->click('_qf_Result_done');
123
124 // View Membership
125 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name1}']/../../td[11]/span[1]/a[1][text()='View']");
126 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name1}']/../../td[11]/span[1]/a[1][text()='View']");
127 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
128
129 // Verify End date
130 $verifyData = array(
131 'Membership Type' => $memTypeParams['membership_type'],
132 'Status' => 'Current',
133 'End date' => $endDate,
134 );
135 $this->webtestVerifyTabularData($verifyData);
136
137 $this->click('_qf_MembershipView_cancel-bottom');
138
139 // View Membership
140 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name2}']/../../td[11]/span/a[text()='View']");
141 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
142
143 // Verify End date
144 $verifyData = array(
145 'Membership Type' => $memTypeParams['membership_type'],
146 'Status' => 'Grace',
147 'End date' => $endDate,
148 );
149 $this->webtestVerifyTabularData($verifyData);
150 }
151
152 /**
153 * @param array $memTypeParams
154 */
155 function _addMembership($memTypeParams) {
156 // click through to the membership view screen
157 $this->click("css=li#tab_member a");
158 $this->waitForElementPresent("link=Add Membership");
159 $this->click("link=Add Membership");
160 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
161
162 // fill in Membership Organization and Type
163 $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
164 // Wait for membership type select to reload
165 $this->waitForTextPresent($memTypeParams['membership_type']);
166 // Because it tends to cause problems, all uses of sleep() must be justified in comments
167 // Sleep should never be used for wait for anything to load from the server
168 // Justification for this instance: FIXME
169 sleep(3);
170 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
171
172 $sourceText = "Membership ContactAddTest Webtest";
173 // fill in Source
174 $this->type("source", $sourceText);
175
176 // Let Join Date stay default
177
178 // fill in Start Date
179 $this->webtestFillDate('start_date');
180
181 // Clicking save.
182 $this->click("_qf_Membership_upload");
183
184 // page was loaded
185 $this->waitForTextPresent($sourceText);
186 }
187
188 /**
189 * @param $profileTitle
190 * @param array $customDataParams
191 */
192 function _addProfile($profileTitle, $customDataParams) {
193
194 $this->openCiviPage("admin/uf/group", "reset=1");
195
196 $this->click('link=Add Profile');
197 // Add membership custom data field to profile
198 $this->waitForElementPresent('_qf_Group_cancel-bottom');
199 $this->type('title', $profileTitle);
200 $this->click('uf_group_type_Profile');
201 $this->clickLink('_qf_Group_next-bottom');
202
203 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
204 $gid = $this->urlArg('gid');
205
206 $this->openCiviPage('admin/uf/group/field/add', array('action' => 'add', 'reset' => 1, 'gid' => $gid), 'field_name[0]');
207
208 $this->select('field_name[0]', "value=Membership");
209 $this->select('field_name[1]', "label={$customDataParams[0]} :: {$customDataParams[1]}");
210 $this->click('field_name[1]');
211 $this->click('label');
212
213 // Clicking save and new
214 $this->click('_qf_Field_next_new-bottom');
215 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[0]}' has been saved to '{$profileTitle}'.");
216
217 // Add membership status field to profile - CRM-8618
218 $this->select('field_name[0]', "value=Membership");
219 $this->select('field_name[1]', "label=Membership Status");
220 $this->click('field_name[1]');
221 $this->click('label');
222 // Clicking save
223 $this->click('_qf_Field_next-bottom');
224 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Membership Status' has been saved to '{$profileTitle}'.");
225 }
226
227 /**
228 * @return array
229 */
230 function _addCustomData() {
231 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4);
232
233 $this->openCiviPage('admin/custom/group', 'reset=1');
234
235 //add new custom data
236 $this->click("//a[@id='newCustomDataGroup']/span");
237 $this->waitForPageToLoad($this->getTimeoutMsec());
238
239 //fill custom group title
240 $this->click("title");
241 $this->type("title", $customGroupTitle);
242
243 //custom group extends
244 $this->click("extends[0]");
245 $this->select("extends[0]", "value=Membership");
246 $this->click("//option[@value='Membership']");
247 $this->click('_qf_Group_next-bottom');
248 $this->waitForElementPresent('_qf_Field_cancel-bottom');
249
250 //Is custom group created?
251 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
252
253 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
254 $this->type('label', $textFieldLabel);
255
256 //enter pre help msg
257 $this->type('help_pre', "this is field pre help");
258
259 //enter post help msg
260 $this->type('help_post', "this is field post help");
261
262 //Is searchable?
263 $this->click('is_searchable');
264
265 //clicking save
266 $this->click('_qf_Field_done-bottom');
267
268 //Is custom field created
269 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' has been saved.");
270
271 return array($textFieldLabel, $customGroupTitle);
272 }
273 }