Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-03-23-46-36
[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->waitForVisible('crm-group-selector_processing');
194 $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(., '$groupName')]/following-sibling::td[@class='crm-group-group_links']/span/a");
195 $this->clickLink("xpath=//table[@id='crm-group-selector']/tbody/tr/td[1][contains(., '$groupName')]/following-sibling::td[@class='crm-group-group_links']/span/a");
196 $contactEmails = array(
197 1 => "$lastName1, $firstName1",
198 2 => "$lastName2, $firstName2"
199 );
200 foreach ($contactEmails as $row => $name) {
201 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]"));
202 }
203
204 //add the api keys in the recaptcha settings
205 $this->openCiviPage('admin/setting/misc', 'reset=1');
206 $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju');
207 $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp');
208 $this->clickLink('_qf_Miscellaneous_next-bottom');
209
210 //enable recaptcha in the profile
211 $this->openCiviPage('admin/uf/group', 'reset=1');
212 $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text()= '$profileTitle']/../following-sibling::td[6]/span/a[2]");
213 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
214 //reCaptcha settings
215 $this->click('add_captcha');
216 $this->clickLink('_qf_Group_next-bottom');
217
218 //check if recaptcha loads for anonymous profile
219 $this->webtestLogout();
220 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
221 $this->waitForElementPresent('recaptcha_widget_div');
222 $this->assertTrue($this->isElementPresent('recaptcha_area'));
223
224 // delete the profile
225 $this->webtestLogin();
226 $this->openCiviPage('admin/uf/group', 'reset=1');
227 $this->_testdeleteProfile($profileTitle);
228 }
229
230 function _testdeleteProfile($profileTitle) {
231 //$this->waitForPageToLoad($this->getTimeoutMsec());
232 $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']");
233 $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']");
234
235 $this->waitForElementPresent('_qf_Group_next-bottom');
236 $this->click('_qf_Group_next-bottom');
237 $this->waitForElementPresent('newCiviCRMProfile-bottom');
238 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
239 }
240
241 /**
242 * CRM-12439
243 * Test to check profile description field
244 * which has a rich text editor (CKEditor)
245 */
246 function testCheckDescAndCreatedIdFields() {
247 // Log in using webtestLogin() method
248 $this->webtestLogin();
249
250 // open Add Profile page
251 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1");
252
253 $this->waitForElementPresent('_qf_Group_next-bottom');
254 $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7);
255 $this->type('title', $profileTitle);
256
257 // check if description field is present
258 $this->waitForElementPresent('description');
259
260 $profileDescription = "Test Profile description" . substr(sha1(rand()), 0, 7);
261 $this->type('description', $profileDescription);
262 $this->check('uf_group_type_Search Profile');
263
264 // click save button
265 $this->clickLink('_qf_Group_next-bottom');
266
267 // Wait for "saved" status msg
268 $this->waitForText('crm-notification-container', 'Profile Added');
269
270 $this->waitForElementPresent('_qf_Field_next-bottom');
271
272 // select field(s) to be added in profile
273 $this->select("field_name_0", "value=Contact");
274 $this->select("field_name_1", "value=email");
275 $this->select("field_name_2", "value=2");
276
277 // click on Save buttonProfile Field Saved
278 $this->clickLink('_qf_Field_next-bottom');
279
280 // Wait for "saved" status msg
281 $this->waitForText('crm-notification-container', "Profile Field Saved");
282
283 $this->waitForElementPresent("xpath=//div[@id='field_page']/div[4]/a[2]");
284 $this->waitForElementPresent("xpath=//div[@id='field_page']/div[4]/a[4]");
285
286 $this->waitForElementPresent("xpath=//div[@id='field_page']/div[3]/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[3]/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[4]/a[2]", '_qf_Group_next-bottom');
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');
301
302 // Wait for "saved" status msg
303 $this->waitForText('crm-notification-container', 'Profile Saved');
304
305 $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/a[@id='newCiviCRMProfile-bottom']");
306 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
307 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]");
308
309 // check description is displayed on profile listing page
310 $this->assertEquals(
311 $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"),
312 $profileDescription);
313
314 // fetch created by
315 $createdBy = $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
316
317 // click on created by
318 $this->click("xpath=id('UFGroup-$id')/td[2]/a");
319
320 // Is contact present?
321 $this->assertTrue($this->isTextPresent("$createdBy"), "Contact did not find!");
322
323 $this->openCiviPage('admin/uf/group', 'reset=1');
324 // delete created profile
325 $this->_testdeleteProfile($profileTitle);
326 }
327 }