Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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 TO |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | ||
6a488035 TO |
29 | //Tests for the ability to add a CMS user from a contact's record |
30 | //See http://issues.civicrm.org/jira/browse/CRM-8723 | |
e9479dcf EM |
31 | /** |
32 | * Class WebTest_Contact_CreateCmsUserFromContactTest | |
33 | */ | |
6a488035 TO |
34 | class WebTest_Contact_CreateCmsUserFromContactTest extends CiviSeleniumTestCase { |
35 | ||
36 | protected function setUp() { | |
37 | parent::setUp(); | |
38 | } | |
39 | ||
6a488035 TO |
40 | //Test that option to create a cms user is present on a contact who does not |
41 | //have a cms account already( in this case, a new contact ) | |
42 | function testCreateContactLinkPresent() { | |
6a488035 TO |
43 | |
44 | //login | |
42daf119 | 45 | $this->webtestLogin('admin'); |
6a488035 TO |
46 | |
47 | //create a New Contact | |
48 | $firstName = substr(sha1(rand()), 0, 7) . "John"; | |
42daf119 CW |
49 | $lastName = substr(sha1(rand()), 0, 7) . "Smith"; |
50 | $email = $this->webtestAddContact($firstName, $lastName, TRUE); | |
6a488035 TO |
51 | |
52 | //Assert that the user actually does have a CMS Id displayed | |
53 | $this->assertTrue(!$this->isTextPresent("User ID")); | |
54 | ||
55 | //Assert that the contact user record link says create user record | |
56 | $this->assertElementContainsText("css=#actions li.crm-contact-user-record", "Create User Record", "Create User Record link not in action menu of new contact"); | |
57 | } | |
58 | ||
59 | //Test that the action link is missing for users who already have a contact | |
60 | //record. The contact record for drupal user 1 is used | |
61 | function testCreateContactLinkMissing() { | |
6a488035 TO |
62 | |
63 | //login | |
42daf119 | 64 | $this->webtestLogin('admin'); |
6a488035 TO |
65 | |
66 | // go to My Account page | |
67 | $this->open($this->sboxPath . "user"); | |
68 | ||
69 | // click "View Contact Record" link | |
70 | $this->waitForElementPresent("xpath=//div[@class='profile']/span/a[text()='View Contact Record']"); | |
71 | $this->click("xpath=//div[@class='profile']/span/a[text()='View Contact Record']"); | |
72 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
73 | ||
74 | //Assert that the user actually does have a CMS Id displayed | |
75 | $this->assertTrue($this->isTextPresent("User ID")); | |
76 | ||
77 | //Assert that the text of the user record link does not say Create User Record | |
78 | $this->assertElementNotContainsText("css=#actions li.crm-contact-user-record", "Create User Record", "Create User Record link not in action menu of new contact"); | |
79 | } | |
80 | ||
81 | //Test the ajax "check username availibity" link when adding cms user | |
82 | function testCheckUsernameAvailability() { | |
42daf119 | 83 | $this->webtestLogin('admin'); |
6a488035 TO |
84 | |
85 | $email = $this->_createUserAndGotoForm(); | |
86 | $password = "abc123"; | |
87 | ||
88 | //use the username of the admin user to test if the username is taken | |
89 | $username = $this->settings->adminUsername; | |
90 | ||
91 | $this->_fillCMSUserForm($username, $password, $password); | |
92 | $this->click("checkavailability"); | |
93 | $this->waitForCondition("selenium.browserbot.getCurrentWindow().jQuery('#msgbox').text() != 'Checking...'"); | |
94 | $this->assertElementContainsText("msgbox", "This username is taken", "Taken username is indicated as being available"); | |
95 | ||
96 | //fill the form with a good username | |
97 | $username = sha1(rand()); | |
98 | $this->_fillCMSUserForm($username, $password, $password); | |
99 | $this->click("checkavailability"); | |
100 | $this->waitForCondition("selenium.browserbot.getCurrentWindow().jQuery('#msgbox').text() != 'Checking...'"); | |
101 | $this->assertElementContainsText("msgbox", "This username is currently available", "Available username is indicated as being taken"); | |
102 | } | |
103 | ||
6a488035 TO |
104 | //Test form submission when the username is taken |
105 | function testTakenUsernameSubmission() { | |
6a488035 TO |
106 | |
107 | //login | |
42daf119 | 108 | $this->webtestLogin('admin'); |
6a488035 TO |
109 | |
110 | //create a New Contact | |
111 | list($cid, $firstName, $lastName, $email) = $this->_createUserAndGotoForm(); | |
112 | $password = 'abc123'; | |
113 | ||
6a488035 TO |
114 | //submit the form with the bad username |
115 | $username = $this->settings->adminUsername; | |
116 | $this->_fillCMSUserForm($username, $password, $password); | |
117 | $this->click("_qf_Useradd_next-bottom"); | |
118 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
119 | ||
120 | //the civicrm messages should indicate the username is taken | |
6a488035 | 121 | |
91a8b457 | 122 | $this->assertElementContainsText("xpath=//span[@class = 'crm-error']", "already taken", "CiviCRM Message does not indicate the username is in user"); |
6a488035 TO |
123 | //check the uf match table that no contact has been created |
124 | $results = $this->webtest_civicrm_api("UFMatch", "get", array('contact_id' => $cid)); | |
125 | $this->assertTrue($results['count'] == 0); | |
126 | } | |
127 | ||
128 | //Test form sumbission when user passwords dont match | |
129 | function testMismatchPasswordSubmission() { | |
6a488035 TO |
130 | |
131 | //login | |
42daf119 | 132 | $this->webtestLogin('admin'); |
6a488035 TO |
133 | |
134 | //create a New Contact | |
135 | list($cid, $firstName, $lastName, $email) = $this->_createUserAndGotoForm(); | |
136 | $password = 'abc123'; | |
137 | ||
6a488035 TO |
138 | //submit with mismatch passwords |
139 | $username = $this->settings->adminUsername; | |
140 | $this->_fillCMSUserForm($username, $password, $password . "mismatch"); | |
141 | $this->click("_qf_Useradd_next-bottom"); | |
142 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
143 | ||
144 | //check that that there is a password mismatch text | |
91a8b457 | 145 | $this->assertElementContainsText("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td/span[@class='crm-error']", "Password mismatch", "No form error given on password missmatch"); |
6a488035 TO |
146 | |
147 | //check that no user was created; | |
148 | $results = $this->webtest_civicrm_api("UFMatch", "get", array('contact_id' => $cid)); | |
149 | $this->assertTrue($results['count'] == 0); | |
150 | } | |
151 | ||
152 | function testMissingDataSubmission() { | |
6a488035 TO |
153 | |
154 | //login | |
42daf119 | 155 | $this->webtestLogin('admin'); |
6a488035 TO |
156 | |
157 | //create a New Contact | |
158 | list($cid, $firstName, $lastName, $email) = $this->_createUserAndGotoForm(); | |
159 | $password = 'abc123'; | |
160 | ||
6a488035 TO |
161 | //submit with mismatch passwords |
162 | $username = $this->settings->adminUsername; | |
163 | $this->click("_qf_Useradd_next-bottom"); | |
164 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
165 | ||
166 | //the civicrm messages section should not indicate that a user has been created | |
91a8b457 | 167 | $this->assertElementNotContainsText("xpath=//span[@class='crm-error']", "User has been added", "CiviCRM messages say that a user was created when username left blank"); |
6a488035 TO |
168 | |
169 | //the civicrm message should say username is required | |
91a8b457 | 170 | $this->assertElementContainsText("xpath=//span[@class='crm-error']", "Username is required", "The CiviCRM messae does not indicate that the username is required"); |
6a488035 TO |
171 | |
172 | //the civicrm message should say password is required | |
91a8b457 | 173 | $this->assertElementContainsText("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td/span[@class='crm-error']", "Password is required", "The CiviCRM messae does not indicate that the password is required"); |
6a488035 | 174 | |
6a488035 TO |
175 | //check that no user was created; |
176 | $results = $this->webtest_civicrm_api("UFMatch", "get", array('contact_id' => $cid)); | |
177 | $this->assertTrue($results['count'] == 0); | |
178 | } | |
179 | ||
180 | //Test a valid (username unique and passwords match) submission | |
181 | function testValidSubmission() { | |
6a488035 TO |
182 | |
183 | //login | |
42daf119 | 184 | $this->webtestLogin('admin'); |
6a488035 TO |
185 | |
186 | //create a New Contact | |
187 | list($cid, $firstName, $lastName, $email) = $this->_createUserAndGotoForm(); | |
188 | $password = 'abc123'; | |
189 | ||
6a488035 TO |
190 | //submit with matching passwords |
191 | $this->_fillCMSUserForm($firstName, $password, $password); | |
192 | $this->click("_qf_Useradd_next-bottom"); | |
193 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
194 | ||
195 | //drupal messages should say user created | |
196 | $this->assertTrue($this->isTextPresent("Created a new user account"), "Drupal does not report success creating user in the message"); | |
197 | ||
198 | //The new user id should be on the page | |
199 | $this->assertTrue($this->isTextPresent("User ID")); | |
200 | ||
201 | //Assert that a user was actually created AND that they are tied to the record | |
202 | $results = $this->webtest_civicrm_api("UFMatch", "get", array('contact_id' => $cid)); | |
203 | $this->assertTrue($results['count'] == 1); | |
204 | } | |
205 | ||
4cbe18b8 EM |
206 | /** |
207 | * @param $username | |
208 | * @param $password | |
209 | * @param $confirm_password | |
210 | */ | |
6a488035 TO |
211 | function _fillCMSUserForm($username, $password, $confirm_password) { |
212 | $this->type("cms_name", $username); | |
213 | $this->type("cms_pass", $password); | |
214 | $this->type("cms_confirm_pass", $confirm_password); | |
215 | } | |
216 | ||
4cbe18b8 EM |
217 | /** |
218 | * @return array | |
219 | */ | |
6a488035 TO |
220 | function _createUserAndGoToForm() { |
221 | $firstName = substr(sha1(rand()), 0, 7) . "John"; | |
42daf119 CW |
222 | $lastName = substr(sha1(rand()), 0, 7) . "Smith"; |
223 | $email = $this->webtestAddContact($firstName, $lastName, TRUE); | |
6a488035 TO |
224 | |
225 | // Get the contact id of the new contact | |
a471a3b6 | 226 | $cid = $this->urlArg('cid'); |
6a488035 TO |
227 | |
228 | //got to the new cms user form | |
d8bd5fb9 | 229 | $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid={$cid}"); |
6a488035 TO |
230 | |
231 | return array($cid, $firstName, $lastName, $email); | |
232 | } | |
233 | } | |
234 |