Update Copywrite year to be 2019
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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
29 /**
30 * Class WebTest_Profile_ProfileAddTest
31 */
32 class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testAddNewProfile() {
39 $this->webtestLogin();
40
41 // Add new profile.
42 $this->openCiviPage('admin/uf/group', 'reset=1');
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->clickLink('_qf_Group_next');
103
104 $gid = $this->urlArg('gid');
105
106 //Add field to profile
107 $this->waitForElementPresent("field_name[0]");
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');
116 sleep(1);
117
118 // delete the profile
119 $this->openCiviPage('admin/uf/group', 'reset=1');
120 $this->_testdeleteProfile($profileTitle);
121 }
122
123 public function testProfileAddContactstoGroup() {
124 $this->webtestLogin();
125
126 $permissions = array("edit-1-profile-listings-and-forms");
127 $this->changePermissions($permissions);
128 // take group name and create group
129 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
130 $this->WebtestAddGroup($groupName);
131
132 // Add new profile.
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
143 $this->click('uf_group_type_Profile');
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');
152
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',
160 'email' => 'Contact',
161 );
162 $this->waitForElementPresent("field_name_0");
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");
169 $this->clickLink('_qf_Field_next_new-top', 'field_name_0', FALSE);
170 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
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);
182
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);
192
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('title');
198 $this->waitForElementPresent("xpath=//div[text() = '$groupName']/parent::td/following-sibling::td[@class='crm-group-group_links']/span/a");
199 $this->clickLink("xpath=//div[text() = '$groupName']/parent::td/following-sibling::td[@class='crm-group-group_links']/span/a");
200 $contactEmails = array(
201 1 => "$lastName1, $firstName1",
202 2 => "$lastName2, $firstName2",
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');
216 $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/div[text()= '$profileTitle']/../following-sibling::td[6]/span/a[2]");
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 }
233
234 /**
235 * @param $profileTitle
236 */
237 public function _testdeleteProfile($profileTitle) {
238 //$this->waitForPageToLoad($this->getTimeoutMsec());
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']");
241
242 $this->waitForElementPresent('_qf_Group_next-bottom');
243 $this->click('_qf_Group_next-bottom');
244 $this->waitForElementPresent('newCiviCRMProfile-bottom');
245 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
246 }
247
248 /**
249 * CRM-12439
250 * Test to check profile description field
251 * which has a rich text editor (CKEditor)
252 */
253 public function testCheckDescAndCreatedIdFields() {
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");
259
260 $this->waitForElementPresent('_qf_Group_next-bottom');
261 $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7);
262 $this->type('title', $profileTitle);
263
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');
276
277 $this->waitForElementPresent("field_name_0");
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
285 $this->clickLink("xpath=//button/span[text()='Save']", "xpath=//a/span/i[@class='crm-i fa-plus-circle']", FALSE);
286
287 // Wait for "saved" status msg
288 $this->waitForText('crm-notification-container', "Profile Field Saved");
289
290 $this->waitForElementPresent("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span/a[text()='Edit']");
291 // extract profile Id
292 $id = explode("gid=", $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr/td[9]/span/a[text()='Edit']/@href"));
293 $id = $id[1];
294
295 // click on Edit Settings
296 $this->clickLink("xpath=//a/span/i[@class='crm-i fa-wrench']", '_qf_Group_next-bottom', FALSE);
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
304 $this->clickLink('_qf_Group_next-bottom', "xpath=//a/span/i[@class='crm-i fa-wrench']", FALSE);
305
306 // Wait for "saved" status msg
307 $this->waitForText('crm-notification-container', 'Profile Saved');
308
309 $this->openCiviPage("admin/uf/group", "reset=1");
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
315 $this->assertEquals(
316 $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"),
317 $profileDescription);
318
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
322 // click on created by
323 $this->click("xpath=id('UFGroup-$id')/td[2]/a");
324
325 // Is contact present?
326 $this->assertTrue($this->isTextPresent("$createdBy"), "Contact did not find!");
327
328 $this->openCiviPage('admin/uf/group', 'reset=1');
329 // delete created profile
330 $this->_testdeleteProfile($profileTitle);
331 }
332
333 }