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