INFRA-132 - Trailing commas for multiline arrays
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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
00be9182 38 public 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
39a2888d
CW
102 $this->clickLink('_qf_Group_next');
103
104 $gid = $this->urlArg('gid');
6a488035 105
6a488035 106 //Add field to profile
bf333c47 107 $this->waitForElementPresent("field_name[0]");
6a488035
TO
108 $this->click('field_name[0]');
109 $this->select('field_name[0]', 'value=Contact');
110 $this->click("//option[@value='Contact']");
111 $this->click('is_required');
112 $this->type('help_post', 'This is help for profile field');
113
114 //click on save
115 $this->click('_qf_Field_next');
39a2888d 116 sleep(1);
6a488035
TO
117
118 // delete the profile
38bf8139 119 $this->openCiviPage('admin/uf/group', 'reset=1');
6a488035
TO
120 $this->_testdeleteProfile($profileTitle);
121 }
122
00be9182 123 public function testProfileAddContactstoGroup() {
f1e08554 124 $this->webtestLogin();
97d5a31f 125
5ddf4885 126 $permissions = array("edit-1-profile-listings-and-forms");
127 $this->changePermissions($permissions);
f1e08554
RN
128 // take group name and create group
129 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
130 $this->WebtestAddGroup($groupName);
97d5a31f 131
6c6e6187 132 // Add new profile.
f1e08554
RN
133 $this->openCiviPage('admin/uf/group', 'reset=1');
134
135 $this->click('newCiviCRMProfile-top');
136
137 $this->waitForElementPresent('_qf_Group_next-bottom');
138
139 //Name of profile
140 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
141 $this->type('title', $profileTitle);
142
5ddf4885 143 $this->click('uf_group_type_Profile');
f1e08554
RN
144 //Profile Advance Settings
145 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
146
147 //Select the newly created group for adding new contacts into it.
148 $this->select('add_contact_to_group', "label=$groupName");
149
150 //click on save
151 $this->clickLink('_qf_Group_next');
97d5a31f 152
f1e08554
RN
153 //check for profile create
154 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
155
156 //Add fields to profile
157 $fields = array(
158 'first_name' => 'Individual',
159 'last_name' => 'Individual',
21dfd5f5 160 'email' => 'Contact',
f1e08554 161 );
bf333c47 162 $this->waitForElementPresent("field_name_0");
f1e08554
RN
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");
bf333c47
JP
169 $this->clickLink('_qf_Field_next_new-top', 'field_name_0', FALSE);
170 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
f1e08554
RN
171 }
172
173 // create mode
174 $gid = $this->urlArg('gid');
175 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
176 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
177 $lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7);
178 $this->type('first_name', $firstName1);
179 $this->type('last_name', $lastName1);
180 $this->type('email-Primary', "$firstName1.$lastName1@example.com");
181 $this->clickLink('_qf_Edit_next', NULL);
97d5a31f 182
f1e08554
RN
183 //anonymous contact
184 $this->webtestLogout();
185 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
186 $firstName2 = "John12_" . substr(sha1(rand()), 0, 7);
187 $lastName2 = "Smiths34_x" . substr(sha1(rand()), 0, 7);
188 $this->type('first_name', $firstName2);
189 $this->type('last_name', $lastName2);
190 $this->type('email-Primary', "$firstName2.$lastName2@example.com");
191 $this->clickLink('_qf_Edit_next', NULL);
97d5a31f 192
f1e08554
RN
193 $this->webtestLogin();
194 //check the existence of the two contacts in the group
195 $this->openCiviPage('group', 'reset=1');
196 $this->type('title', $groupName);
197 $this->click('_qf_Search_refresh');
bf333c47
JP
198 $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[text() = '$groupName']/parent::td/following-sibling::td[@class=' crm-group-group_links']/span/a");
199 $this->clickLink("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[1]/span[text() = '$groupName']/parent::td/following-sibling::td[@class=' crm-group-group_links']/span/a");
97d5a31f 200 $contactEmails = array(
201 1 => "$lastName1, $firstName1",
21dfd5f5 202 2 => "$lastName2, $firstName2",
f1e08554
RN
203 );
204 foreach ($contactEmails as $row => $name) {
205 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]"));
206 }
207
208 //add the api keys in the recaptcha settings
209 $this->openCiviPage('admin/setting/misc', 'reset=1');
210 $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju');
211 $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp');
212 $this->clickLink('_qf_Miscellaneous_next-bottom');
213
214 //enable recaptcha in the profile
215 $this->openCiviPage('admin/uf/group', 'reset=1');
8617883d 216 $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
217 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
218 //reCaptcha settings
219 $this->click('add_captcha');
220 $this->clickLink('_qf_Group_next-bottom');
221
222 //check if recaptcha loads for anonymous profile
223 $this->webtestLogout();
224 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
225 $this->waitForElementPresent('recaptcha_widget_div');
226 $this->assertTrue($this->isElementPresent('recaptcha_area'));
227
228 // delete the profile
229 $this->webtestLogin();
230 $this->openCiviPage('admin/uf/group', 'reset=1');
231 $this->_testdeleteProfile($profileTitle);
232 }
97d5a31f 233
4cbe18b8
EM
234 /**
235 * @param $profileTitle
236 */
00be9182 237 public function _testdeleteProfile($profileTitle) {
6a488035 238 //$this->waitForPageToLoad($this->getTimeoutMsec());
5c80555f
WA
239 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/div[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul//li/a[text()='Delete']");
240 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/div[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul//li/a[text()='Delete']");
6a488035
TO
241
242 $this->waitForElementPresent('_qf_Group_next-bottom');
243 $this->click('_qf_Group_next-bottom');
244 $this->waitForElementPresent('newCiviCRMProfile-bottom');
6c5f7368 245 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
6a488035 246 }
bcbde5ca
AW
247
248 /**
249 * CRM-12439
250 * Test to check profile description field
251 * which has a rich text editor (CKEditor)
252 */
00be9182 253 public function testCheckDescAndCreatedIdFields() {
bcbde5ca
AW
254 // Log in using webtestLogin() method
255 $this->webtestLogin();
256
257 // open Add Profile page
258 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1");
4cbe18b8 259
bcbde5ca
AW
260 $this->waitForElementPresent('_qf_Group_next-bottom');
261 $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7);
262 $this->type('title', $profileTitle);
4cbe18b8 263
bcbde5ca
AW
264 // check if description field is present
265 $this->waitForElementPresent('description');
266
267 $profileDescription = "Test Profile description" . substr(sha1(rand()), 0, 7);
268 $this->type('description', $profileDescription);
269 $this->check('uf_group_type_Search Profile');
270
271 // click save button
272 $this->clickLink('_qf_Group_next-bottom');
273
274 // Wait for "saved" status msg
275 $this->waitForText('crm-notification-container', 'Profile Added');
4cbe18b8 276
bf333c47 277 $this->waitForElementPresent("field_name_0");
bcbde5ca
AW
278
279 // select field(s) to be added in profile
280 $this->select("field_name_0", "value=Contact");
281 $this->select("field_name_1", "value=email");
282 $this->select("field_name_2", "value=2");
283
284 // click on Save buttonProfile Field Saved
bf333c47 285 $this->clickLink('_qf_Field_next-bottom', "xpath=//a/span[text()='Add Field']", FALSE);
bcbde5ca
AW
286
287 // Wait for "saved" status msg
288 $this->waitForText('crm-notification-container', "Profile Field Saved");
289
bf333c47 290 $this->waitForElementPresent("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span/a[text()='Edit']");
bcbde5ca 291 // extract profile Id
bf333c47 292 $id = explode("gid=", $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr/td[9]/span/a[text()='Edit']/@href"));
bcbde5ca
AW
293 $id = $id[1];
294
295 // click on Edit Settings
bf333c47 296 $this->clickLink("xpath=//a/span[text()='Edit Settings']", '_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
bf333c47 304 $this->clickLink('_qf_Group_next-bottom', "xpath=//a/span[text()='Edit Settings']", FALSE);
bcbde5ca
AW
305
306 // Wait for "saved" status msg
307 $this->waitForText('crm-notification-container', 'Profile Saved');
4cbe18b8 308
39a2888d 309 $this->openCiviPage("admin/uf/group", "reset=1");
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}