Merge pull request #3344 from eileenmcnaughton/comments
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileAddTest.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 class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddNewProfile() {
35 $this->webtestLogin();
36
37 // Add new profile.
38 $this->openCiviPage('admin/uf/group', 'reset=1');
39
40 $this->click('newCiviCRMProfile-top');
41
42 $this->waitForElementPresent('_qf_Group_next-bottom');
43
44 //Name of profile
45 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
46 $this->type('title', $profileTitle);
47
48 //profile Used for
49 $this->click('uf_group_type_User Registration');
50 $this->click('uf_group_type_User Account');
51
52 //Profile Advance Settings
53 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
54
55 //Select a group if you are using this profile for search and listings.
56 $this->select('group', 'value=1');
57
58 //Select a group if you are using this profile for adding new contacts.
59 $this->select('add_contact_to_group', 'value=1');
60
61 //If you want member(s) of your organization to receive a
62 //notification email whenever this Profile
63 //form is used to enter or update contact information, enter one or more email addresses here.
64 $this->type('notify', 'This is notify email');
65
66 //If you are using this profile as a contact signup or edit
67 //form, and want to redirec the user to a static URL after
68 //they've submitted the form - enter the complete URL here.
69 $this->type('post_URL', 'This is Post Url');
70
71 // If you are using this profile as a contact signup or edit
72 // form, and want to redirect the user to a
73 //static URL if they click the Cancel button - enter the complete URL here.
74 $this->type('cancel_URL', 'This is cancle Url');
75
76 //reCaptcha settings
77 $this->click('add_captcha');
78
79 //Drupal user account registration option
80 $this->click('CIVICRM_QFID_0_8');
81
82 //What to do upon duplicate match
83 $this->click('CIVICRM_QFID_0_2');
84
85 //Proximity search options
86 $this->click('CIVICRM_QFID_0_14');
87
88 // enable maping for contact
89 $this->click('is_map');
90
91 // include a link in the listings to Edit profile fields
92 $this->click('is_edit_link');
93
94 //to view contacts' Drupal user account information
95 $this->click('is_uf_link');
96
97 //click on save
98 $this->click('_qf_Group_next');
99 $this->waitForPageToLoad($this->getTimeoutMsec());
100
101 //check for profile create
102 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
103
104 //Add field to profile
105 $this->click('field_name[0]');
106 $this->select('field_name[0]', 'value=Contact');
107 $this->click("//option[@value='Contact']");
108 $this->click('is_required');
109 $this->type('help_post', 'This is help for profile field');
110
111 //click on save
112 $this->click('_qf_Field_next');
113 $this->waitForPageToLoad($this->getTimeoutMsec());
114
115 // delete the profile
116 $this->openCiviPage('admin/uf/group', 'reset=1');
117 $this->_testdeleteProfile($profileTitle);
118 }
119
120 function testProfileAddContactstoGroup() {
121 $this->webtestLogin();
122
123 $permissions = array("edit-1-profile-listings-and-forms");
124 $this->changePermissions($permissions);
125 // take group name and create group
126 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
127 $this->WebtestAddGroup($groupName);
128
129 // Add new profile.
130 $this->openCiviPage('admin/uf/group', 'reset=1');
131
132 $this->click('newCiviCRMProfile-top');
133
134 $this->waitForElementPresent('_qf_Group_next-bottom');
135
136 //Name of profile
137 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
138 $this->type('title', $profileTitle);
139
140 $this->click('uf_group_type_Profile');
141 //Profile Advance Settings
142 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
143
144 //Select the newly created group for adding new contacts into it.
145 $this->select('add_contact_to_group', "label=$groupName");
146
147 //click on save
148 $this->clickLink('_qf_Group_next');
149
150 //check for profile create
151 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
152
153 //Add fields to profile
154 $fields = array(
155 'first_name' => 'Individual',
156 'last_name' => 'Individual',
157 'email' => 'Contact'
158 );
159 foreach ($fields as $field => $type) {
160 $this->click('field_name_0');
161 $this->select('field_name_0', "value=$type");
162 $this->click("//option[@value='$type']");
163 $this->click('field_name_1');
164 $this->select('field_name_1', "value=$field");
165 $this->clickLink('_qf_Field_next_new-top');
166 }
167
168 // create mode
169 $gid = $this->urlArg('gid');
170 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
171 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
172 $lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7);
173 $this->type('first_name', $firstName1);
174 $this->type('last_name', $lastName1);
175 $this->type('email-Primary', "$firstName1.$lastName1@example.com");
176 $this->clickLink('_qf_Edit_next', NULL);
177
178 //anonymous contact
179 $this->webtestLogout();
180 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
181 $firstName2 = "John12_" . substr(sha1(rand()), 0, 7);
182 $lastName2 = "Smiths34_x" . substr(sha1(rand()), 0, 7);
183 $this->type('first_name', $firstName2);
184 $this->type('last_name', $lastName2);
185 $this->type('email-Primary', "$firstName2.$lastName2@example.com");
186 $this->clickLink('_qf_Edit_next', NULL);
187
188 $this->webtestLogin();
189 //check the existence of the two contacts in the group
190 $this->openCiviPage('group', 'reset=1');
191 $this->type('title', $groupName);
192 $this->click('_qf_Search_refresh');
193 $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td/span[text() = '$groupName']/parent::td/following-sibling::td[@class=' crm-group-group_links']/span/a");
194 $this->clickLink("xpath=//table[@id='crm-group-selector']/tbody/tr/td[1]/span[text() = '$groupName']/parent::td/following-sibling::td[@class=' crm-group-group_links']/span/a");
195 $contactEmails = array(
196 1 => "$lastName1, $firstName1",
197 2 => "$lastName2, $firstName2"
198 );
199 foreach ($contactEmails as $row => $name) {
200 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]"));
201 }
202
203 //add the api keys in the recaptcha settings
204 $this->openCiviPage('admin/setting/misc', 'reset=1');
205 $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju');
206 $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp');
207 $this->clickLink('_qf_Miscellaneous_next-bottom');
208
209 //enable recaptcha in the profile
210 $this->openCiviPage('admin/uf/group', 'reset=1');
211 $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text()= '$profileTitle']/../following-sibling::td[6]/span/a[2]");
212 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
213 //reCaptcha settings
214 $this->click('add_captcha');
215 $this->clickLink('_qf_Group_next-bottom');
216
217 //check if recaptcha loads for anonymous profile
218 $this->webtestLogout();
219 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
220 $this->waitForElementPresent('recaptcha_widget_div');
221 $this->assertTrue($this->isElementPresent('recaptcha_area'));
222
223 // delete the profile
224 $this->webtestLogin();
225 $this->openCiviPage('admin/uf/group', 'reset=1');
226 $this->_testdeleteProfile($profileTitle);
227 }
228
229 /**
230 * @param $profileTitle
231 */
232 function _testdeleteProfile($profileTitle) {
233 //$this->waitForPageToLoad($this->getTimeoutMsec());
234 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
235 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
236
237 $this->waitForElementPresent('_qf_Group_next-bottom');
238 $this->click('_qf_Group_next-bottom');
239 $this->waitForElementPresent('newCiviCRMProfile-bottom');
240 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
241 }
242
243 /**
244 * CRM-12439
245 * Test to check profile description field
246 * which has a rich text editor (CKEditor)
247 */
248 function testCheckDescAndCreatedIdFields() {
249 // Log in using webtestLogin() method
250 $this->webtestLogin();
251
252 // open Add Profile page
253 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1");
254
255 $this->waitForElementPresent('_qf_Group_next-bottom');
256 $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7);
257 $this->type('title', $profileTitle);
258
259 // check if description field is present
260 $this->waitForElementPresent('description');
261
262 $profileDescription = "Test Profile description" . substr(sha1(rand()), 0, 7);
263 $this->type('description', $profileDescription);
264 $this->check('uf_group_type_Search Profile');
265
266 // click save button
267 $this->clickLink('_qf_Group_next-bottom');
268
269 // Wait for "saved" status msg
270 $this->waitForText('crm-notification-container', 'Profile Added');
271
272 $this->waitForElementPresent('_qf_Field_next-bottom');
273
274 // select field(s) to be added in profile
275 $this->select("field_name_0", "value=Contact");
276 $this->select("field_name_1", "value=email");
277 $this->select("field_name_2", "value=2");
278
279 // click on Save buttonProfile Field Saved
280 $this->clickLink('_qf_Field_next-bottom');
281
282 // Wait for "saved" status msg
283 $this->waitForText('crm-notification-container', "Profile Field Saved");
284
285
286 $this->waitForElementPresent("xpath=//div[@id='field_page']/div[2]/table/tbody/tr[1]/td[9]/span/a[text()='Edit']");
287 // extract profile Id
288 $id = explode("gid=", $this->getAttribute("xpath=//div[@id='field_page']/div[2]/table/tbody/tr/td[9]/span/a[text()='Edit']/@href"));
289 $id = $id[1];
290
291 // click on Edit Settings
292 $this->clickLink("xpath=//div[@id='field_page']/div[3]/a[2]", '_qf_Group_next-bottom', FALSE);
293
294 // check for description field
295 $this->waitForElementPresent('description');
296 // check value of description field is retrieved correctly
297 $this->assertEquals($this->getValue('description'), $profileDescription);
298
299 // click on save button
300 $this->clickLink('_qf_Group_next-bottom', "xpath=//div[@id='field_page']/div[3]/a[2]", FALSE);
301
302 // Wait for "saved" status msg
303 $this->waitForText('crm-notification-container', 'Profile Saved');
304
305 $this->clickLink("xpath=//div[@id='breadcrumb']/div//a[text()='Profiles']");
306 $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/a[@id='newCiviCRMProfile-bottom']");
307 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
308 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]");
309
310 // check description is displayed on profile listing page
311 $this->assertEquals(
312 $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"),
313 $profileDescription);
314
315 // fetch created by
316 $createdBy = $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
317
318 // click on created by
319 $this->click("xpath=id('UFGroup-$id')/td[2]/a");
320
321 // Is contact present?
322 $this->assertTrue($this->isTextPresent("$createdBy"), "Contact did not find!");
323
324 $this->openCiviPage('admin/uf/group', 'reset=1');
325 // delete created profile
326 $this->_testdeleteProfile($profileTitle);
327 }
328 }