3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Member_BatchUpdateViaProfileTest
32 class WebTest_Member_BatchUpdateViaProfileTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testMemberAdd() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
43 $memTypeParams = $this->webtestAddMembershipType();
45 $endDate = date('F jS, Y', strtotime("+1 year +1 month -1 day"));
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");
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");
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");
64 'Membership Type' => $memTypeParams['membership_type'],
66 'End date' => $endDate,
68 $this->webtestVerifyTabularData($verifyData);
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");
75 // Add membership for this individual
76 $this->_addMembership($memTypeParams);
77 // Is status message correct?
79 $this->waitForText('crm-notification-container', "membership for $firstName2 $lastName has been added.");
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");
87 'Membership Type' => $memTypeParams['membership_type'],
89 'End date' => $endDate,
91 $this->webtestVerifyTabularData($verifyData);
93 $profileTitle = 'Profile_' . substr(sha1(rand()), 0, 4);
94 $customDataParams = $this->_addCustomData();
95 $this->_addProfile($profileTitle, $customDataParams);
98 $this->openCiviPage("member/search", "reset=1", '_qf_Search_refresh');
100 $this->type('sort_name', $lastName);
101 $this->click('_qf_Search_refresh');
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');
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");
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");
120 $this->click('_qf_Batch_next-bottom');
121 $this->waitForElementPresent('_qf_Result_done');
122 $this->click('_qf_Result_done');
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');
131 'Membership Type' => $memTypeParams['membership_type'],
132 'Status' => 'Current',
133 'End date' => $endDate,
135 $this->webtestVerifyTabularData($verifyData);
137 $this->click('_qf_MembershipView_cancel-bottom');
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');
145 'Membership Type' => $memTypeParams['membership_type'],
147 'End date' => $endDate,
149 $this->webtestVerifyTabularData($verifyData);
153 * @param array $memTypeParams
155 public 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");
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
170 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
172 $sourceText = "Membership ContactAddTest Webtest";
174 $this->type("source", $sourceText);
176 // Let Join Date stay default
178 // fill in Start Date
179 $this->webtestFillDate('start_date');
182 $this->click("_qf_Membership_upload");
185 $this->waitForTextPresent($sourceText);
189 * @param $profileTitle
190 * @param array $customDataParams
192 public function _addProfile($profileTitle, $customDataParams) {
194 $this->openCiviPage("admin/uf/group", "reset=1");
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');
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');
206 $this->openCiviPage('admin/uf/group/field/add', array(
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');
217 // Clicking save and new
218 $this->click('_qf_Field_next_new-bottom');
219 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[0]}' has been saved to '{$profileTitle}'.");
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');
227 $this->click('_qf_Field_next-bottom');
228 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Membership Status' has been saved to '{$profileTitle}'.");
234 public function _addCustomData() {
235 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4);
237 $this->openCiviPage('admin/custom/group', 'reset=1');
239 //add new custom data
240 $this->click("//a[@id='newCustomDataGroup']/span");
241 $this->waitForPageToLoad($this->getTimeoutMsec());
243 //fill custom group title
244 $this->click("title");
245 $this->type("title", $customGroupTitle);
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');
254 //Is custom group created?
255 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
257 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
258 $this->type('label', $textFieldLabel);
261 $this->type('help_pre', "this is field pre help");
263 //enter post help msg
264 $this->type('help_post', "this is field post help");
267 $this->click('is_searchable');
270 $this->click('_qf_Field_done-bottom');
272 //Is custom field created
273 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' has been saved.");
275 return array($textFieldLabel, $customGroupTitle);