Merge pull request #71 from dpradeep/merge-20140930
[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
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 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
107 //Add field to profile
108 $this->waitForElementPresent("field_name[0]");
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 sleep(1);
118
119 // delete the profile
120 $this->openCiviPage('admin/uf/group', 'reset=1');
121 $this->_testdeleteProfile($profileTitle);
122 }
123
124 function testProfileAddContactstoGroup() {
125 $this->webtestLogin();
126
127 $permissions = array("edit-1-profile-listings-and-forms");
128 $this->changePermissions($permissions);
129 // take group name and create group
130 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
131 $this->WebtestAddGroup($groupName);
132
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
144 $this->click('uf_group_type_Profile');
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');
153
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 $this->waitForElementPresent("field_name_0");
164 foreach ($fields as $field => $type) {
165 $this->click('field_name_0');
166 $this->select('field_name_0', "value=$type");
167 $this->click("//option[@value='$type']");
168 $this->click('field_name_1');
169 $this->select('field_name_1', "value=$field");
170 $this->clickLink('_qf_Field_next_new-top', 'field_name_0', FALSE);
171 $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']");
172 }
173
174 // create mode
175 $gid = $this->urlArg('gid');
176 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
177 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
178 $lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7);
179 $this->type('first_name', $firstName1);
180 $this->type('last_name', $lastName1);
181 $this->type('email-Primary', "$firstName1.$lastName1@example.com");
182 $this->clickLink('_qf_Edit_next', NULL);
183
184 //anonymous contact
185 $this->webtestLogout();
186 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
187 $firstName2 = "John12_" . substr(sha1(rand()), 0, 7);
188 $lastName2 = "Smiths34_x" . substr(sha1(rand()), 0, 7);
189 $this->type('first_name', $firstName2);
190 $this->type('last_name', $lastName2);
191 $this->type('email-Primary', "$firstName2.$lastName2@example.com");
192 $this->clickLink('_qf_Edit_next', NULL);
193
194 $this->webtestLogin();
195 //check the existence of the two contacts in the group
196 $this->openCiviPage('group', 'reset=1');
197 $this->type('title', $groupName);
198 $this->click('_qf_Search_refresh');
199 $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");
200 $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");
201 $contactEmails = array(
202 1 => "$lastName1, $firstName1",
203 2 => "$lastName2, $firstName2"
204 );
205 foreach ($contactEmails as $row => $name) {
206 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]"));
207 }
208
209 //add the api keys in the recaptcha settings
210 $this->openCiviPage('admin/setting/misc', 'reset=1');
211 $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju');
212 $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp');
213 $this->clickLink('_qf_Miscellaneous_next-bottom');
214
215 //enable recaptcha in the profile
216 $this->openCiviPage('admin/uf/group', 'reset=1');
217 $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text()= '$profileTitle']/../following-sibling::td[6]/span/a[2]");
218 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
219 //reCaptcha settings
220 $this->click('add_captcha');
221 $this->clickLink('_qf_Group_next-bottom');
222
223 //check if recaptcha loads for anonymous profile
224 $this->webtestLogout();
225 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
226 $this->waitForElementPresent('recaptcha_widget_div');
227 $this->assertTrue($this->isElementPresent('recaptcha_area'));
228
229 // delete the profile
230 $this->webtestLogin();
231 $this->openCiviPage('admin/uf/group', 'reset=1');
232 $this->_testdeleteProfile($profileTitle);
233 }
234
235 /**
236 * @param $profileTitle
237 */
238 function _testdeleteProfile($profileTitle) {
239 //$this->waitForPageToLoad($this->getTimeoutMsec());
240 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul//li/a[text()='Delete']");
241 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul//li/a[text()='Delete']");
242
243 $this->waitForElementPresent('_qf_Group_next-bottom');
244 $this->click('_qf_Group_next-bottom');
245 $this->waitForElementPresent('newCiviCRMProfile-bottom');
246 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
247 }
248
249 /**
250 * CRM-12439
251 * Test to check profile description field
252 * which has a rich text editor (CKEditor)
253 */
254 function testCheckDescAndCreatedIdFields() {
255 // Log in using webtestLogin() method
256 $this->webtestLogin();
257
258 // open Add Profile page
259 $this->openCiviPage("admin/uf/group/add", "action=add&reset=1");
260
261 $this->waitForElementPresent('_qf_Group_next-bottom');
262 $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7);
263 $this->type('title', $profileTitle);
264
265 // check if description field is present
266 $this->waitForElementPresent('description');
267
268 $profileDescription = "Test Profile description" . substr(sha1(rand()), 0, 7);
269 $this->type('description', $profileDescription);
270 $this->check('uf_group_type_Search Profile');
271
272 // click save button
273 $this->clickLink('_qf_Group_next-bottom');
274
275 // Wait for "saved" status msg
276 $this->waitForText('crm-notification-container', 'Profile Added');
277
278 $this->waitForElementPresent("field_name_0");
279
280 // select field(s) to be added in profile
281 $this->select("field_name_0", "value=Contact");
282 $this->select("field_name_1", "value=email");
283 $this->select("field_name_2", "value=2");
284
285 // click on Save buttonProfile Field Saved
286 $this->clickLink('_qf_Field_next-bottom', "xpath=//a/span[text()='Add Field']", FALSE);
287
288 // Wait for "saved" status msg
289 $this->waitForText('crm-notification-container', "Profile Field Saved");
290
291 $this->waitForElementPresent("xpath=//div[@id='field_page']/table/tbody/tr[1]/td[9]/span/a[text()='Edit']");
292 // extract profile Id
293 $id = explode("gid=", $this->getAttribute("xpath=//div[@id='field_page']/table/tbody/tr/td[9]/span/a[text()='Edit']/@href"));
294 $id = $id[1];
295
296 // click on Edit Settings
297 $this->clickLink("xpath=//a/span[text()='Edit Settings']", '_qf_Group_next-bottom', FALSE);
298
299 // check for description field
300 $this->waitForElementPresent('description');
301 // check value of description field is retrieved correctly
302 $this->assertEquals($this->getValue('description'), $profileDescription);
303
304 // click on save button
305 $this->clickLink('_qf_Group_next-bottom', "xpath=//a/span[text()='Edit Settings']", FALSE);
306
307 // Wait for "saved" status msg
308 $this->waitForText('crm-notification-container', 'Profile Saved');
309
310 $this->openCiviPage("admin/uf/group", "reset=1");
311 $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/a[@id='newCiviCRMProfile-bottom']");
312 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
313 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]");
314
315 // check description is displayed on profile listing page
316 $this->assertEquals(
317 $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"),
318 $profileDescription);
319
320 // fetch created by
321 $createdBy = $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a");
322
323 // click on created by
324 $this->click("xpath=id('UFGroup-$id')/td[2]/a");
325
326 // Is contact present?
327 $this->assertTrue($this->isTextPresent("$createdBy"), "Contact did not find!");
328
329 $this->openCiviPage('admin/uf/group', 'reset=1');
330 // delete created profile
331 $this->_testdeleteProfile($profileTitle);
332 }
333 }