Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | ||
27 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Member_BatchUpdateViaProfileTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testMemberAdd() { | |
6a488035 TO |
36 | // Log in using webtestLogin() method |
37 | $this->webtestLogin(); | |
38 | ||
39 | // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership) | |
40 | $memTypeParams = $this->webtestAddMembershipType(); | |
41 | ||
42 | $endDate = date('F jS, Y', strtotime("+1 year +1 month -1 day")); | |
43 | ||
44 | // Add new individual using Quick Add block on the main page | |
45 | $firstName1 = "John_" . substr(sha1(rand()), 0, 7); | |
46 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7); | |
47 | $Name1 = $lastName . ', ' . $firstName1; | |
48 | $this->webtestAddContact($firstName1, $lastName, "$firstName1.$lastName@example.com"); | |
49 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
50 | ||
51 | // Add membership for this individual | |
52 | $this->_addMembership($memTypeParams); | |
53 | // Is status message correct? | |
928c2d43 PJ |
54 | $this->assertElementContainsText('crm-notification-container', "membership for $firstName1 $lastName has been added.", |
55 | "Status message didn't show up after saving!"); | |
6a488035 TO |
56 | |
57 | // click through to the membership view screen | |
58 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
59 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
60 | ||
61 | // Verify End date | |
62 | $verifyData = array( | |
63 | 'Membership Type' => $memTypeParams['membership_type'], | |
64 | 'Status' => 'New', | |
65 | 'End date' => $endDate, | |
66 | ); | |
928c2d43 | 67 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
68 | |
69 | // Add new individual using Quick Add block on the main page | |
70 | $firstName2 = "John_" . substr(sha1(rand()), 0, 7); | |
71 | $Name2 = $lastName . ', ' . $firstName2; | |
72 | $this->webtestAddContact($firstName2, $lastName, "$firstName2.$lastName@example.com"); | |
73 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
74 | ||
75 | // Add membership for this individual | |
76 | $this->_addMembership($memTypeParams); | |
77 | // Is status message correct? | |
928c2d43 PJ |
78 | |
79 | $this->assertElementContainsText('crm-notification-container', "membership for $firstName2 $lastName has been added.", | |
80 | "Status message didn't show up after saving!"); | |
6a488035 TO |
81 | |
82 | // click through to the membership view screen | |
83 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
84 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
85 | ||
86 | // Verify End date | |
87 | $verifyData = array( | |
88 | 'Membership Type' => $memTypeParams['membership_type'], | |
89 | 'Status' => 'New', | |
90 | 'End date' => $endDate, | |
91 | ); | |
928c2d43 PJ |
92 | $this->webtestVerifyTabularData($verifyData); |
93 | ||
6a488035 TO |
94 | $profileTitle = 'Profile_' . substr(sha1(rand()), 0, 4); |
95 | $customDataParams = $this->_addCustomData(); | |
96 | $this->_addProfile($profileTitle, $customDataParams); | |
97 | ||
98 | // Find Members | |
928c2d43 PJ |
99 | $this->openCiviPage("member/search", "reset=1", '_qf_Search_refresh'); |
100 | ||
6a488035 TO |
101 | $this->type('sort_name', $lastName); |
102 | $this->click('_qf_Search_refresh'); | |
103 | $this->waitForElementPresent('_qf_Search_next_print'); | |
104 | ||
105 | // Batch Update Via Profile | |
106 | $this->click("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/input"); | |
107 | //$this->click('CIVICRM_QFID_ts_all_10'); | |
108 | $this->select('task', "label=Batch Update Members Via Profile"); | |
109 | $this->click('Go'); | |
110 | $this->waitForElementPresent('_qf_PickProfile_back-bottom'); | |
111 | ||
112 | $this->select('uf_group_id', "label={$profileTitle}"); | |
113 | $this->click('_qf_PickProfile_next-bottom'); | |
114 | ||
115 | $this->waitForElementPresent('_qf_Batch_back-bottom'); | |
116 | $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[3]/input", "This is test custom data text1"); | |
117 | $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[4]/select", "label=Current"); | |
118 | ||
119 | $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[3]/input", "This is test custom data text2"); | |
120 | $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[4]/select", "label=Grace"); | |
121 | ||
122 | $this->click('_qf_Batch_next-bottom'); | |
123 | $this->waitForElementPresent('_qf_Result_done'); | |
124 | $this->click('_qf_Result_done'); | |
125 | $this->waitForElementPresent('_qf_Search_next_print'); | |
126 | ||
127 | // View Membership | |
128 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name1}']/../../td[11]/span/a[text()='View']"); | |
129 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); | |
130 | ||
131 | // Verify End date | |
132 | $verifyData = array( | |
133 | 'Membership Type' => $memTypeParams['membership_type'], | |
134 | 'Status' => 'Current', | |
135 | 'End date' => $endDate, | |
136 | ); | |
928c2d43 | 137 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
138 | |
139 | $this->click('_qf_MembershipView_cancel-bottom'); | |
140 | $this->waitForElementPresent('_qf_Search_next_print'); | |
141 | ||
142 | // View Membership | |
143 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name2}']/../../td[11]/span/a[text()='View']"); | |
144 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); | |
145 | ||
146 | // Verify End date | |
147 | $verifyData = array( | |
148 | 'Membership Type' => $memTypeParams['membership_type'], | |
149 | 'Status' => 'Grace', | |
150 | 'End date' => $endDate, | |
151 | ); | |
928c2d43 | 152 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
153 | } |
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']); | |
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"); | |
183 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
184 | ||
185 | // page was loaded | |
186 | $this->waitForTextPresent($sourceText); | |
187 | } | |
188 | ||
189 | function _addProfile($profileTitle, $customDataParams) { | |
42daf119 | 190 | |
928c2d43 | 191 | $this->openCiviPage("admin/uf/group", "reset=1"); |
6a488035 | 192 | |
6a488035 | 193 | $this->click('link=Add Profile'); |
6a488035 TO |
194 | // Add membership custom data field to profile |
195 | $this->waitForElementPresent('_qf_Group_cancel-bottom'); | |
196 | $this->type('title', $profileTitle); | |
197 | $this->click('_qf_Group_next-bottom'); | |
198 | ||
199 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
928c2d43 | 200 | $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
6a488035 TO |
201 | |
202 | $this->select('field_name[0]', "value=Membership"); | |
203 | $this->select('field_name[1]', "label={$customDataParams[0]} :: {$customDataParams[1]}"); | |
204 | $this->click('field_name[1]'); | |
205 | $this->click('label'); | |
206 | ||
207 | // Clicking save and new | |
208 | $this->click('_qf_Field_next_new-bottom'); | |
209 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
928c2d43 | 210 | $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[0]}' has been saved to '{$profileTitle}'."); |
6a488035 TO |
211 | |
212 | // Add membership status field to profile - CRM-8618 | |
213 | $this->select('field_name[0]', "value=Membership"); | |
214 | $this->select('field_name[1]', "label=Membership Status"); | |
215 | $this->click('field_name[1]'); | |
216 | $this->click('label'); | |
217 | // Clicking save | |
218 | $this->click('_qf_Field_next-bottom'); | |
219 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
928c2d43 | 220 | $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile Field 'Membership Status' has been saved to '{$profileTitle}'."); |
6a488035 TO |
221 | } |
222 | ||
223 | function _addCustomData() { | |
224 | $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4); | |
42daf119 | 225 | |
305515fb PJ |
226 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
227 | ||
6a488035 TO |
228 | //add new custom data |
229 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
230 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
231 | ||
232 | //fill custom group title | |
233 | $this->click("title"); | |
234 | $this->type("title", $customGroupTitle); | |
235 | ||
236 | //custom group extends | |
237 | $this->click("extends[0]"); | |
238 | $this->select("extends[0]", "value=Membership"); | |
239 | $this->click("//option[@value='Membership']"); | |
240 | $this->click('_qf_Group_next-bottom'); | |
241 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
242 | ||
243 | //Is custom group created? | |
928c2d43 | 244 | $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
6a488035 TO |
245 | |
246 | $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4); | |
247 | $this->type('label', $textFieldLabel); | |
248 | ||
249 | //enter pre help msg | |
250 | $this->type('help_pre', "this is field pre help"); | |
251 | ||
252 | //enter post help msg | |
253 | $this->type('help_post', "this is field post help"); | |
254 | ||
255 | //Is searchable? | |
256 | $this->click('is_searchable'); | |
257 | ||
258 | //clicking save | |
259 | $this->click('_qf_Field_next'); | |
260 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
261 | ||
262 | //Is custom field created | |
928c2d43 | 263 | $this->assertElementContainsText('crm-notification-container', "Your custom field '$textFieldLabel' has been saved."); |
6a488035 TO |
264 | |
265 | return array($textFieldLabel, $customGroupTitle); | |
266 | } | |
42daf119 | 267 | } |