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