Merge pull request #1301 from monishdeb/CRM-13029
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddNewProfile() {
6a488035
TO
35 $this->webtestLogin();
36
42daf119 37 // Add new profile.
38bf8139 38 $this->openCiviPage('admin/uf/group', 'reset=1');
6a488035
TO
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
6c5f7368 102 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
6a488035
TO
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
38bf8139 116 $this->openCiviPage('admin/uf/group', 'reset=1');
6a488035
TO
117 $this->_testdeleteProfile($profileTitle);
118 }
119
f1e08554
RN
120 function testProfileAddContactstoGroup() {
121 $this->webtestLogin();
97d5a31f 122
f1e08554
RN
123 // take group name and create group
124 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
125 $this->WebtestAddGroup($groupName);
97d5a31f 126
f1e08554
RN
127 // Add new profile.
128 $this->openCiviPage('admin/uf/group', 'reset=1');
129
130 $this->click('newCiviCRMProfile-top');
131
132 $this->waitForElementPresent('_qf_Group_next-bottom');
133
134 //Name of profile
135 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
136 $this->type('title', $profileTitle);
137
138 //Profile Advance Settings
139 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
140
141 //Select the newly created group for adding new contacts into it.
142 $this->select('add_contact_to_group', "label=$groupName");
143
144 //click on save
145 $this->clickLink('_qf_Group_next');
97d5a31f 146
f1e08554
RN
147 //check for profile create
148 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
149
150 //Add fields to profile
151 $fields = array(
152 'first_name' => 'Individual',
153 'last_name' => 'Individual',
154 'email' => 'Contact'
155 );
156 foreach ($fields as $field => $type) {
157 $this->click('field_name_0');
158 $this->select('field_name_0', "value=$type");
159 $this->click("//option[@value='$type']");
160 $this->click('field_name_1');
161 $this->select('field_name_1', "value=$field");
97d5a31f 162 $this->clickLink('_qf_Field_next_new-top');
f1e08554
RN
163 }
164
165 // create mode
166 $gid = $this->urlArg('gid');
167 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
168 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
169 $lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7);
170 $this->type('first_name', $firstName1);
171 $this->type('last_name', $lastName1);
172 $this->type('email-Primary', "$firstName1.$lastName1@example.com");
173 $this->clickLink('_qf_Edit_next', NULL);
97d5a31f 174
f1e08554
RN
175 //anonymous contact
176 $this->webtestLogout();
177 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
178 $firstName2 = "John12_" . substr(sha1(rand()), 0, 7);
179 $lastName2 = "Smiths34_x" . substr(sha1(rand()), 0, 7);
180 $this->type('first_name', $firstName2);
181 $this->type('last_name', $lastName2);
182 $this->type('email-Primary', "$firstName2.$lastName2@example.com");
183 $this->clickLink('_qf_Edit_next', NULL);
97d5a31f 184
f1e08554
RN
185 $this->webtestLogin();
186 //check the existence of the two contacts in the group
187 $this->openCiviPage('group', 'reset=1');
188 $this->type('title', $groupName);
189 $this->click('_qf_Search_refresh');
190 $this->waitForVisible('crm-group-selector_processing');
191 $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(text(), '$groupName')]/following-sibling::td[@class='crm-group-group_links']/span/a");
192 $this->clickLink("xpath=//table[@id='crm-group-selector']/tbody/tr/td[1][text()= '$groupName']/following-sibling::td[@class='crm-group-group_links']/span/a");
97d5a31f 193 $contactEmails = array(
194 1 => "$lastName1, $firstName1",
f1e08554
RN
195 2 => "$lastName2, $firstName2"
196 );
197 foreach ($contactEmails as $row => $name) {
198 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]"));
199 }
200
201 //add the api keys in the recaptcha settings
202 $this->openCiviPage('admin/setting/misc', 'reset=1');
203 $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju');
204 $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp');
205 $this->clickLink('_qf_Miscellaneous_next-bottom');
206
207 //enable recaptcha in the profile
208 $this->openCiviPage('admin/uf/group', 'reset=1');
209 $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text()= '$profileTitle']/../following-sibling::td[4]/span/a[2]");
210 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
211 //reCaptcha settings
212 $this->click('add_captcha');
213 $this->clickLink('_qf_Group_next-bottom');
214
215 //check if recaptcha loads for anonymous profile
216 $this->webtestLogout();
217 $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL);
218 $this->waitForElementPresent('recaptcha_widget_div');
219 $this->assertTrue($this->isElementPresent('recaptcha_area'));
220
221 // delete the profile
222 $this->webtestLogin();
223 $this->openCiviPage('admin/uf/group', 'reset=1');
224 $this->_testdeleteProfile($profileTitle);
225 }
97d5a31f 226
6a488035
TO
227 function _testdeleteProfile($profileTitle) {
228 //$this->waitForPageToLoad($this->getTimeoutMsec());
229 $this->waitForElementPresent("//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
230 $this->click("//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
231
232 $this->waitForElementPresent('_qf_Group_next-bottom');
233 $this->click('_qf_Group_next-bottom');
234 $this->waitForElementPresent('newCiviCRMProfile-bottom');
6c5f7368 235 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
6a488035 236 }
42daf119 237}