Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Member_BatchUpdateViaProfileTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_BatchUpdateViaProfileTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testMemberAdd() { |
6a488035 TO |
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); | |
92915c55 TO |
49 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7); |
50 | $Name1 = $lastName . ', ' . $firstName1; | |
6a488035 | 51 | $this->webtestAddContact($firstName1, $lastName, "$firstName1.$lastName@example.com"); |
6a488035 TO |
52 | |
53 | // Add membership for this individual | |
54 | $this->_addMembership($memTypeParams); | |
55 | // Is status message correct? | |
6c5f7368 | 56 | $this->waitForText('crm-notification-container', "membership for $firstName1 $lastName has been added"); |
6a488035 TO |
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 | ); | |
928c2d43 | 68 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
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"); | |
6a488035 TO |
74 | |
75 | // Add membership for this individual | |
76 | $this->_addMembership($memTypeParams); | |
77 | // Is status message correct? | |
928c2d43 | 78 | |
6c5f7368 | 79 | $this->waitForText('crm-notification-container', "membership for $firstName2 $lastName has been added."); |
6a488035 TO |
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 | ); | |
928c2d43 PJ |
91 | $this->webtestVerifyTabularData($verifyData); |
92 | ||
6a488035 TO |
93 | $profileTitle = 'Profile_' . substr(sha1(rand()), 0, 4); |
94 | $customDataParams = $this->_addCustomData(); | |
95 | $this->_addProfile($profileTitle, $customDataParams); | |
96 | ||
97 | // Find Members | |
928c2d43 PJ |
98 | $this->openCiviPage("member/search", "reset=1", '_qf_Search_refresh'); |
99 | ||
6a488035 TO |
100 | $this->type('sort_name', $lastName); |
101 | $this->click('_qf_Search_refresh'); | |
6a488035 TO |
102 | |
103 | // Batch Update Via Profile | |
d84aa55c | 104 | $this->waitForElementPresent("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/input"); |
6a488035 TO |
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"); | |
6a488035 | 108 | $this->waitForElementPresent('_qf_PickProfile_back-bottom'); |
d84aa55c | 109 | $this->waitForElementPresent('uf_group_id'); |
6a488035 TO |
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'); | |
6a488035 TO |
123 | |
124 | // View Membership | |
d84aa55c RK |
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']"); | |
6a488035 TO |
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 | ); | |
928c2d43 | 135 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
136 | |
137 | $this->click('_qf_MembershipView_cancel-bottom'); | |
6a488035 TO |
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 | ||
4cbe18b8 | 152 | /** |
100fef9d | 153 | * @param array $memTypeParams |
4cbe18b8 | 154 | */ |
00be9182 | 155 | public function _addMembership($memTypeParams) { |
6a488035 TO |
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']); | |
efb29358 CW |
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 | |
6a488035 TO |
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"); | |
6a488035 TO |
183 | |
184 | // page was loaded | |
185 | $this->waitForTextPresent($sourceText); | |
186 | } | |
187 | ||
4cbe18b8 EM |
188 | /** |
189 | * @param $profileTitle | |
100fef9d | 190 | * @param array $customDataParams |
4cbe18b8 | 191 | */ |
00be9182 | 192 | public function _addProfile($profileTitle, $customDataParams) { |
42daf119 | 193 | |
928c2d43 | 194 | $this->openCiviPage("admin/uf/group", "reset=1"); |
6a488035 | 195 | |
6a488035 | 196 | $this->click('link=Add Profile'); |
6a488035 TO |
197 | // Add membership custom data field to profile |
198 | $this->waitForElementPresent('_qf_Group_cancel-bottom'); | |
199 | $this->type('title', $profileTitle); | |
0ecb5006 | 200 | $this->click('uf_group_type_Profile'); |
39a2888d | 201 | $this->clickLink('_qf_Group_next-bottom'); |
6a488035 | 202 | |
6c5f7368 | 203 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
39a2888d CW |
204 | $gid = $this->urlArg('gid'); |
205 | ||
92915c55 TO |
206 | $this->openCiviPage('admin/uf/group/field/add', array( |
207 | 'action' => 'add', | |
208 | 'reset' => 1, | |
79d7553f | 209 | 'gid' => $gid, |
92915c55 | 210 | ), 'field_name[0]'); |
6a488035 TO |
211 | |
212 | $this->select('field_name[0]', "value=Membership"); | |
213 | $this->select('field_name[1]', "label={$customDataParams[0]} :: {$customDataParams[1]}"); | |
214 | $this->click('field_name[1]'); | |
215 | $this->click('label'); | |
216 | ||
217 | // Clicking save and new | |
218 | $this->click('_qf_Field_next_new-bottom'); | |
6c5f7368 | 219 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[0]}' has been saved to '{$profileTitle}'."); |
6a488035 TO |
220 | |
221 | // Add membership status field to profile - CRM-8618 | |
222 | $this->select('field_name[0]', "value=Membership"); | |
223 | $this->select('field_name[1]', "label=Membership Status"); | |
224 | $this->click('field_name[1]'); | |
225 | $this->click('label'); | |
226 | // Clicking save | |
227 | $this->click('_qf_Field_next-bottom'); | |
6c5f7368 | 228 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Membership Status' has been saved to '{$profileTitle}'."); |
6a488035 TO |
229 | } |
230 | ||
4cbe18b8 EM |
231 | /** |
232 | * @return array | |
233 | */ | |
00be9182 | 234 | public function _addCustomData() { |
6a488035 | 235 | $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4); |
42daf119 | 236 | |
305515fb | 237 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
76e86fd8 | 238 | |
6a488035 TO |
239 | //add new custom data |
240 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
241 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
242 | ||
243 | //fill custom group title | |
244 | $this->click("title"); | |
245 | $this->type("title", $customGroupTitle); | |
246 | ||
247 | //custom group extends | |
248 | $this->click("extends[0]"); | |
249 | $this->select("extends[0]", "value=Membership"); | |
250 | $this->click("//option[@value='Membership']"); | |
251 | $this->click('_qf_Group_next-bottom'); | |
252 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
253 | ||
254 | //Is custom group created? | |
6c5f7368 | 255 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
6a488035 TO |
256 | |
257 | $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4); | |
258 | $this->type('label', $textFieldLabel); | |
259 | ||
260 | //enter pre help msg | |
261 | $this->type('help_pre', "this is field pre help"); | |
262 | ||
263 | //enter post help msg | |
264 | $this->type('help_post', "this is field post help"); | |
265 | ||
266 | //Is searchable? | |
267 | $this->click('is_searchable'); | |
268 | ||
269 | //clicking save | |
d84aa55c | 270 | $this->click('_qf_Field_done-bottom'); |
6a488035 TO |
271 | |
272 | //Is custom field created | |
0ecb5006 | 273 | $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' has been saved."); |
6a488035 TO |
274 | |
275 | return array($textFieldLabel, $customGroupTitle); | |
276 | } | |
96025800 | 277 | |
42daf119 | 278 | } |