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