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