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