Complex classes like UserTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 4 | class UserTest extends PHPUnit_Framework_TestCase { |
||
| 5 | |||
| 6 | |||
| 7 | public function testUser() { |
||
| 8 | |||
| 9 | //execute the contructor and check for the Object type and attributes |
||
| 10 | $user = new User(); |
||
| 11 | |||
| 12 | $this->assertInstanceOf('User',$user); |
||
| 13 | $this->assertInstanceOf('Person',$user); |
||
| 14 | $this->assertInstanceOf('SugarBean',$user); |
||
| 15 | |||
| 16 | $this->assertAttributeEquals('Users', 'module_dir', $user); |
||
| 17 | $this->assertAttributeEquals('User', 'object_name', $user); |
||
| 18 | $this->assertAttributeEquals('users', 'table_name', $user); |
||
| 19 | |||
| 20 | $this->assertAttributeEquals(true, 'new_schema', $user); |
||
| 21 | $this->assertAttributeEquals(false, 'authenticated', $user); |
||
| 22 | $this->assertAttributeEquals(true, 'importable', $user); |
||
| 23 | $this->assertAttributeEquals(false, 'team_exists', $user); |
||
| 24 | |||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | public function testgetSystemUser() |
||
| 29 | { |
||
| 30 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 31 | global $db; |
||
| 32 | unset ($db->database); |
||
| 33 | $db->checkConnection(); |
||
| 34 | |||
| 35 | $user = new User(); |
||
| 36 | |||
| 37 | $result = $user->getSystemUser(); |
||
| 38 | |||
| 39 | $this->assertInstanceOf('User',$result); |
||
| 40 | $this->assertEquals(1, $result->id); |
||
| 41 | |||
| 42 | } |
||
| 43 | |||
| 44 | |||
| 45 | public function testgetDefaultSignature() |
||
| 46 | { |
||
| 47 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 48 | global $db; |
||
| 49 | unset ($db->database); |
||
| 50 | $db->checkConnection(); |
||
| 51 | |||
| 52 | $user = new User(); |
||
| 53 | |||
| 54 | $user->retrieve(1); |
||
| 55 | |||
| 56 | $result = $user->getDefaultSignature(); |
||
| 57 | $this->assertTrue(is_array($result)); |
||
| 58 | |||
| 59 | } |
||
| 60 | |||
| 61 | |||
| 62 | public function testgetSignature() |
||
| 63 | { |
||
| 64 | $user = new User(); |
||
| 65 | |||
| 66 | $user->retrieve(1); |
||
| 67 | |||
| 68 | $result = $user->getSignature(1); |
||
| 69 | $this->assertEquals(false,$result); |
||
| 70 | |||
| 71 | } |
||
| 72 | |||
| 73 | public function testgetSignaturesArray() { |
||
| 74 | |||
| 75 | $user = new User(); |
||
| 76 | |||
| 77 | $user->retrieve(1); |
||
| 78 | |||
| 79 | $result = $user->getSignaturesArray(); |
||
| 80 | $this->assertTrue(is_array($result)); |
||
| 81 | |||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | public function testgetSignatures() |
||
| 86 | { |
||
| 87 | $user = new User(); |
||
| 88 | |||
| 89 | $user->retrieve(1); |
||
| 90 | |||
| 91 | $expected = "<select onChange='setSigEditButtonVisibility();' id='signature_id' name='signature_id'>\n<OPTION selected value=''>--None--</OPTION></select>"; |
||
| 92 | $actual = $user->getSignatures(); |
||
| 93 | $this->assertSame($expected, $actual); |
||
| 94 | |||
| 95 | } |
||
| 96 | |||
| 97 | |||
| 98 | public function testgetSignatureButtons() |
||
| 99 | { |
||
| 100 | |||
| 101 | global $mod_strings; |
||
| 102 | |||
| 103 | $user = new User(); |
||
| 104 | |||
| 105 | //preset required values |
||
| 106 | $user->retrieve(1); |
||
| 107 | $mod_strings['LBL_BUTTON_EDIT'] = ""; |
||
| 108 | $mod_strings['LBL_BUTTON_CREATE'] = ""; |
||
| 109 | |||
| 110 | |||
| 111 | //test with defaultDisplay false |
||
| 112 | $expected = "<input class='button' onclick='javascript:open_email_signature_form(\"\", \"1\");' value='' type='button'> <span name=\"edit_sig\" id=\"edit_sig\" style=\"visibility:hidden;\"><input class=\"button\" onclick=\"javascript:open_email_signature_form(document.getElementById('signature_id', '').value)\" value=\"\" type=\"button\" tabindex=\"392\"> \n </span>"; |
||
| 113 | $actual = $user->getSignatureButtons(''); |
||
| 114 | $this->assertSame($expected, $actual); |
||
| 115 | |||
| 116 | |||
| 117 | //test with defaultDisplay true |
||
| 118 | $expected = "<input class='button' onclick='javascript:open_email_signature_form(\"\", \"1\");' value='' type='button'> <span name=\"edit_sig\" id=\"edit_sig\" style=\"visibility:inherit;\"><input class=\"button\" onclick=\"javascript:open_email_signature_form(document.getElementById('signature_id', '').value)\" value=\"\" type=\"button\" tabindex=\"392\"> \n </span>"; |
||
| 119 | $actual = $user->getSignatureButtons('',true); |
||
| 120 | $this->assertSame($expected, $actual); |
||
| 121 | |||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | public function testhasPersonalEmail() |
||
| 126 | { |
||
| 127 | |||
| 128 | $user = new User(); |
||
| 129 | |||
| 130 | $user->retrieve(2); |
||
| 131 | |||
| 132 | $result = $user->hasPersonalEmail(); |
||
| 133 | $this->assertEquals(false,$result); |
||
| 134 | |||
| 135 | } |
||
| 136 | |||
| 137 | |||
| 138 | public function testgetUserPrivGuid() |
||
| 139 | { |
||
| 140 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 141 | global $db; |
||
| 142 | unset ($db->database); |
||
| 143 | $db->checkConnection(); |
||
| 144 | |||
| 145 | $user = new User(); |
||
| 146 | |||
| 147 | $user->retrieve(1); |
||
| 148 | |||
| 149 | $result = $user->getUserPrivGuid(); |
||
| 150 | |||
| 151 | $this->assertTrue(isset($result)); |
||
| 152 | $this->assertEquals(36, strlen($result)); |
||
| 153 | |||
| 154 | } |
||
| 155 | |||
| 156 | public function testsetUserPrivGuid() |
||
| 157 | { |
||
| 158 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 159 | global $db; |
||
| 160 | unset ($db->database); |
||
| 161 | $db->checkConnection(); |
||
| 162 | |||
| 163 | |||
| 164 | $user = new User(); |
||
| 165 | |||
| 166 | $user->retrieve(1); |
||
| 167 | |||
| 168 | $user->setUserPrivGuid(); |
||
| 169 | |||
| 170 | $result = $user->getPreference('userPrivGuid', 'global', $user); |
||
| 171 | |||
| 172 | $this->assertTrue(isset($result)); |
||
| 173 | $this->assertEquals(36, strlen($result)); |
||
| 174 | |||
| 175 | } |
||
| 176 | |||
| 177 | public function testSetAndGetAndResetPreference( ) |
||
| 178 | { |
||
| 179 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 180 | global $db; |
||
| 181 | unset ($db->database); |
||
| 182 | $db->checkConnection(); |
||
| 183 | |||
| 184 | $user = new User(); |
||
| 185 | |||
| 186 | $user->retrieve(1); |
||
| 187 | |||
| 188 | |||
| 189 | //test setPreference method |
||
| 190 | $user->setPreference('userPrivGuid', 'someGuid', 0, 'global', $user); |
||
| 191 | |||
| 192 | |||
| 193 | //test getPreference method |
||
| 194 | $result = $user->getPreference('userPrivGuid', 'global', $user); |
||
| 195 | $this->assertTrue(isset($result)); |
||
| 196 | $this->assertEquals('someGuid', $result); |
||
| 197 | |||
| 198 | |||
| 199 | //test resetPreferences method and verify that created preference is no longer available |
||
| 200 | $user->resetPreferences(); |
||
| 201 | $result = $user->getPreference('userPrivGuid', 'global', $user); |
||
| 202 | $this->assertFalse(isset($result)); |
||
| 203 | |||
| 204 | } |
||
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | |||
| 209 | public function testsavePreferencesToDB() |
||
| 210 | { |
||
| 211 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 212 | global $db; |
||
| 213 | unset ($db->database); |
||
| 214 | $db->checkConnection(); |
||
| 215 | |||
| 216 | $user = new User(); |
||
| 217 | |||
| 218 | $user->retrieve(1); |
||
| 219 | |||
| 220 | //execute the method and test if it works and does not throws an exception. |
||
| 221 | try { |
||
| 222 | $user->savePreferencesToDB(); |
||
| 223 | $this->assertTrue(true); |
||
| 224 | } |
||
| 225 | catch (Exception $e) { |
||
| 226 | $this->fail(); |
||
| 227 | } |
||
| 228 | |||
| 229 | } |
||
| 230 | |||
| 231 | |||
| 232 | public function testreloadPreferences() |
||
| 233 | { |
||
| 234 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 235 | global $db; |
||
| 236 | unset ($db->database); |
||
| 237 | $db->checkConnection(); |
||
| 238 | |||
| 239 | $user = new User(); |
||
| 240 | |||
| 241 | $user->retrieve(1); |
||
| 242 | |||
| 243 | $result = $user->reloadPreferences(); |
||
| 244 | $this->assertEquals(true, $result); |
||
| 245 | |||
| 246 | } |
||
| 247 | |||
| 248 | |||
| 249 | public function testgetUserDateTimePreferences() |
||
| 250 | { |
||
| 251 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 252 | global $db; |
||
| 253 | unset ($db->database); |
||
| 254 | $db->checkConnection(); |
||
| 255 | |||
| 256 | $user = new User(); |
||
| 257 | |||
| 258 | $user->retrieve(1); |
||
| 259 | |||
| 260 | $result = $user->getUserDateTimePreferences(); |
||
| 261 | |||
| 262 | $this->assertTrue(is_array($result)); |
||
| 263 | $this->assertTrue(isset($result['date'])); |
||
| 264 | $this->assertTrue(isset($result['time'])); |
||
| 265 | $this->assertTrue(isset($result['userGmt'])); |
||
| 266 | $this->assertTrue(isset($result['userGmtOffset'])); |
||
| 267 | |||
| 268 | } |
||
| 269 | |||
| 270 | |||
| 271 | public function testloadPreferences( ) |
||
| 272 | { |
||
| 273 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 274 | global $db; |
||
| 275 | unset ($db->database); |
||
| 276 | $db->checkConnection(); |
||
| 277 | |||
| 278 | $user = new User(); |
||
| 279 | |||
| 280 | $user->retrieve(1); |
||
| 281 | |||
| 282 | $result = $user->loadPreferences(); |
||
| 283 | $this->assertEquals(true, $result); |
||
| 284 | |||
| 285 | } |
||
| 286 | |||
| 287 | |||
| 288 | public function testGetETagSeedAndIncrementETag(){ |
||
| 289 | |||
| 290 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 291 | global $db; |
||
| 292 | unset ($db->database); |
||
| 293 | $db->checkConnection(); |
||
| 294 | |||
| 295 | $user = new User(); |
||
| 296 | |||
| 297 | $user->retrieve(1); |
||
| 298 | |||
| 299 | //execute getETagSeed method, get Etag value |
||
| 300 | $ETagInitial = $user->getETagSeed('test'); |
||
| 301 | $this->assertGreaterThanOrEqual(0,$ETagInitial); |
||
| 302 | |||
| 303 | |||
| 304 | //execute incrementETag to increment |
||
| 305 | $user->incrementETag('test'); |
||
| 306 | |||
| 307 | |||
| 308 | //execute getETagSeed method again, get Etag final value and compare final and initial values |
||
| 309 | $ETagFinal = $user->getETagSeed('test'); |
||
| 310 | $this->assertGreaterThan($ETagInitial, $ETagFinal); |
||
| 311 | |||
| 312 | } |
||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | public function testgetLicensedUsersWhere() |
||
| 317 | { |
||
| 318 | $expected = "deleted=0 AND status='Active' AND user_name IS NOT NULL AND is_group=0 AND portal_only=0 AND LENGTH(user_name)>0"; |
||
| 319 | $actual = User::getLicensedUsersWhere(); |
||
| 320 | $this->assertSame($expected, $actual); |
||
| 321 | |||
| 322 | } |
||
| 323 | |||
| 324 | public function testget_summary_text() |
||
| 325 | { |
||
| 326 | $user = new User(); |
||
| 327 | |||
| 328 | //test without setting name |
||
| 329 | $this->assertEquals(Null,$user->get_summary_text()); |
||
| 330 | |||
| 331 | //test with name set |
||
| 332 | $user->name = "test"; |
||
| 333 | $this->assertEquals('test',$user->get_summary_text()); |
||
| 334 | |||
| 335 | } |
||
| 336 | |||
| 337 | public function testbean_implements() |
||
| 338 | { |
||
| 339 | $user = new User(); |
||
| 340 | |||
| 341 | $this->assertEquals(false, $user->bean_implements('')); //test with blank value |
||
| 342 | $this->assertEquals(false, $user->bean_implements('test')); //test with invalid value |
||
| 343 | $this->assertEquals(true, $user->bean_implements('ACL')); //test with valid value |
||
| 344 | } |
||
| 345 | |||
| 346 | |||
| 347 | public function testcheck_role_membership() |
||
| 348 | { |
||
| 349 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 350 | global $db; |
||
| 351 | unset ($db->database); |
||
| 352 | $db->checkConnection(); |
||
| 353 | |||
| 354 | $user = new User(); |
||
| 355 | |||
| 356 | $result = $user->check_role_membership("test", ''); |
||
| 357 | $this->assertEquals(false, $result); |
||
| 358 | |||
| 359 | |||
| 360 | $result = $user->check_role_membership("test", '1'); |
||
| 361 | $this->assertEquals(false, $result); |
||
| 362 | |||
| 363 | } |
||
| 364 | |||
| 365 | |||
| 366 | public function testsaveAndOthers() |
||
| 367 | { |
||
| 368 | error_reporting(E_ERROR | E_PARSE); |
||
| 369 | |||
| 370 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 371 | global $db; |
||
| 372 | unset ($db->database); |
||
| 373 | $db->checkConnection(); |
||
| 374 | |||
| 375 | |||
| 376 | $user = new User(); |
||
| 377 | |||
| 378 | $user->user_name = "test"; |
||
| 379 | |||
| 380 | $user->first_name = "firstn"; |
||
| 381 | $user->last_name = "lastn"; |
||
| 382 | |||
| 383 | $user->email1 = "[email protected]"; |
||
| 384 | $user->email2 = "[email protected]"; |
||
| 385 | |||
| 386 | $result = $user->save(); |
||
| 387 | |||
| 388 | //test for record ID to verify that record is saved |
||
| 389 | $this->assertTrue(isset($user->id)); |
||
| 390 | $this->assertEquals(36, strlen($user->id)); |
||
| 391 | |||
| 392 | |||
| 393 | //test retrieve method |
||
| 394 | $this->retrieve($user->id); |
||
| 395 | |||
| 396 | |||
| 397 | //test retrieve_by_email_address method |
||
| 398 | $this->retrieve_by_email_address($user->id); |
||
| 399 | |||
| 400 | |||
| 401 | //test newPassword And findUserPassword methods |
||
| 402 | $this->NewPasswordAndFindUserPassword($user->id); |
||
| 403 | |||
| 404 | |||
| 405 | //test authenticate_user method |
||
| 406 | $this->authenticate_user($user->id); |
||
| 407 | |||
| 408 | |||
| 409 | //test load_user method |
||
| 410 | $this->load_user($user->id); |
||
| 411 | |||
| 412 | |||
| 413 | //test change_password method |
||
| 414 | $this->change_password($user->id); |
||
| 415 | |||
| 416 | |||
| 417 | //test getPreferredEmail method |
||
| 418 | $this->getPreferredEmail($user->id); |
||
| 419 | |||
| 420 | |||
| 421 | //test getUsersNameAndEmail method |
||
| 422 | $this->getUsersNameAndEmail($user->id); |
||
| 423 | |||
| 424 | |||
| 425 | //test getEmailInfo method |
||
| 426 | $this->getEmailInfo($user->id); |
||
| 427 | |||
| 428 | |||
| 429 | //change username and delete the user to avoid picking it up by password in future |
||
| 430 | $user->user_name = "test_deleted"; |
||
| 431 | $user->save(); |
||
| 432 | $user->mark_deleted($user->id); |
||
| 433 | |||
| 434 | } |
||
| 435 | |||
| 436 | public function retrieve($id) |
||
| 437 | { |
||
| 438 | $user = new User(); |
||
| 439 | |||
| 440 | $user->retrieve($id); |
||
| 441 | |||
| 442 | $this->assertEquals("test", $user->user_name); |
||
| 443 | |||
| 444 | $this->assertEquals("firstn", $user->first_name); |
||
| 445 | $this->assertEquals("lastn", $user->last_name); |
||
| 446 | |||
| 447 | $this->assertEquals("[email protected]", $user->email1); |
||
| 448 | $this->assertEquals("[email protected]", $user->email2); |
||
| 449 | |||
| 450 | } |
||
| 451 | |||
| 452 | public function retrieve_by_email_address($id) |
||
| 453 | { |
||
| 454 | $user = new User(); |
||
| 455 | |||
| 456 | //test with invalid email |
||
| 457 | $user->retrieve_by_email_address("[email protected]"); |
||
| 458 | $this->assertEquals('', $user->id); |
||
| 459 | |||
| 460 | |||
| 461 | //test with valid email and test for record ID to verify that record is same |
||
| 462 | $user->retrieve_by_email_address("[email protected]"); |
||
| 463 | $this->assertTrue(isset($user->id)); |
||
| 464 | $this->assertEquals($id, $user->id); |
||
| 465 | |||
| 466 | } |
||
| 467 | |||
| 468 | public function NewPasswordAndFindUserPassword($id) |
||
| 469 | { |
||
| 470 | $user = new User(); |
||
| 471 | |||
| 472 | $user->retrieve($id); |
||
| 473 | |||
| 474 | //set user password and then retrieve user by created password |
||
| 475 | $user->setNewPassword("test"); |
||
| 476 | |||
| 477 | $result = User::findUserPassword("test",md5("test")); |
||
| 478 | |||
| 479 | $this->assertTrue(isset($result['id'])); |
||
| 480 | $this->assertEquals($id, $result['id']); |
||
| 481 | |||
| 482 | } |
||
| 483 | |||
| 484 | |||
| 485 | public function authenticate_user($id) |
||
| 486 | { |
||
| 487 | $user = new User(); |
||
| 488 | |||
| 489 | $user->retrieve($id); |
||
| 490 | |||
| 491 | //test with invalid password |
||
| 492 | $result = $user->authenticate_user(md5("pass")); |
||
| 493 | $this->assertEquals(false ,$result); |
||
| 494 | |||
| 495 | //test with invalid password |
||
| 496 | $result = $user->authenticate_user(md5("test")); |
||
| 497 | $this->assertEquals(true ,$result); |
||
| 498 | |||
| 499 | } |
||
| 500 | |||
| 501 | |||
| 502 | public function load_user($id) |
||
| 503 | { |
||
| 504 | $user = new User(); |
||
| 505 | |||
| 506 | $user->retrieve($id); |
||
| 507 | |||
| 508 | $result = $user->load_user("test"); |
||
| 509 | |||
| 510 | $this->assertEquals(true, $result->authenticated); |
||
| 511 | |||
| 512 | } |
||
| 513 | |||
| 514 | public function change_password($id) |
||
| 515 | { |
||
| 516 | $user = new User(); |
||
| 517 | |||
| 518 | $user->retrieve($id); |
||
| 519 | |||
| 520 | //execute the method and verifh that it returns true |
||
| 521 | $result = $user->change_password("test", "testpass"); |
||
| 522 | $this->assertEquals(true, $result); |
||
| 523 | |||
| 524 | |||
| 525 | //find the user by new password |
||
| 526 | $result = User::findUserPassword("test",md5("testpass")); |
||
| 527 | |||
| 528 | $this->assertTrue(isset($result['id'])); |
||
| 529 | $this->assertEquals($id, $result['id']); |
||
| 530 | |||
| 531 | } |
||
| 532 | |||
| 533 | public function getPreferredEmail($id) |
||
| 534 | { |
||
| 535 | $user = new User(); |
||
| 536 | |||
| 537 | $user->retrieve($id); |
||
| 538 | |||
| 539 | $expected = array("name"=>"firstn lastn", "email"=>"[email protected]" ); |
||
| 540 | |||
| 541 | $actual = $user->getPreferredEmail(); |
||
| 542 | |||
| 543 | $this->assertSame($actual,$expected); |
||
| 544 | |||
| 545 | } |
||
| 546 | |||
| 547 | public function getUsersNameAndEmail($id) |
||
| 548 | { |
||
| 549 | $user = new User(); |
||
| 550 | |||
| 551 | $user->retrieve($id); |
||
| 552 | |||
| 553 | $expected = array("name"=>"firstn lastn", "email"=>"[email protected]" ); |
||
| 554 | |||
| 555 | $actual = $user->getUsersNameAndEmail(); |
||
| 556 | |||
| 557 | $this->assertEquals($actual,$expected); |
||
| 558 | } |
||
| 559 | |||
| 560 | |||
| 561 | public function getEmailInfo($id) |
||
| 562 | { |
||
| 563 | $user = new User(); |
||
| 564 | |||
| 565 | $expected = array("name"=>"firstn lastn", "email"=>"[email protected]" ); |
||
| 566 | |||
| 567 | $actual = $user->getEmailInfo($id); |
||
| 568 | |||
| 569 | $this->assertEquals($actual,$expected); |
||
| 570 | } |
||
| 571 | |||
| 572 | |||
| 573 | public function testencrypt_password() |
||
| 574 | { |
||
| 575 | $user = new User(); |
||
| 576 | |||
| 577 | $result = $user->encrypt_password("test"); |
||
| 578 | $this->assertTrue(isset($result)); |
||
| 579 | $this->assertGreaterThan(0,strlen($result)); |
||
| 580 | |||
| 581 | } |
||
| 582 | |||
| 583 | public function testgetPasswordHash() |
||
| 584 | { |
||
| 585 | |||
| 586 | $result= User::getPasswordHash("test"); |
||
| 587 | |||
| 588 | $this->assertTrue(isset($result)); |
||
| 589 | $this->assertGreaterThan(0,strlen($result)); |
||
| 590 | |||
| 591 | $this->markTestIncomplete('Error: crypt(): No salt parameter was specified. You must use a randomly generated salt and a strong hash function to produce a secure hash.'); |
||
| 592 | |||
| 593 | } |
||
| 594 | |||
| 595 | |||
| 596 | public function testcheckPassword() |
||
| 597 | { |
||
| 598 | |||
| 599 | //test with empty password and empty hash |
||
| 600 | $result = User::checkPassword("", ''); |
||
| 601 | $this->assertEquals(false,$result); |
||
| 602 | |||
| 603 | |||
| 604 | //test with valid hash and empty password |
||
| 605 | $result = User::checkPassword("", '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la1'); |
||
| 606 | $this->assertEquals(false,$result); |
||
| 607 | |||
| 608 | |||
| 609 | //test with valid password and invalid hash |
||
| 610 | $result = User::checkPassword("test", '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la2'); |
||
| 611 | $this->assertEquals(false,$result); |
||
| 612 | |||
| 613 | |||
| 614 | //test with valid password and valid hash |
||
| 615 | $result = User::checkPassword("test", '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la1'); |
||
| 616 | $this->assertEquals(true,$result); |
||
| 617 | |||
| 618 | } |
||
| 619 | |||
| 620 | |||
| 621 | public function testcheckPasswordMD5() |
||
| 622 | { |
||
| 623 | |||
| 624 | //test with empty password and empty hash |
||
| 625 | $result = User::checkPasswordMD5(md5(""), ''); |
||
| 626 | $this->assertEquals(false,$result); |
||
| 627 | |||
| 628 | |||
| 629 | //test with valid hash and empty password |
||
| 630 | $result = User::checkPasswordMD5(md5(""), '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la1'); |
||
| 631 | $this->assertEquals(false,$result); |
||
| 632 | |||
| 633 | |||
| 634 | //test with valid password and invalid hash |
||
| 635 | $result = User::checkPasswordMD5(md5("test"), '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la2'); |
||
| 636 | $this->assertEquals(false,$result); |
||
| 637 | |||
| 638 | |||
| 639 | //test with valid password and valid hash |
||
| 640 | $result = User::checkPasswordMD5(md5("test"), '$1$Gt0.XI4.$tVVSXgE36sfsVMBNo/9la1'); |
||
| 641 | $this->assertEquals(true,$result); |
||
| 642 | |||
| 643 | } |
||
| 644 | |||
| 645 | |||
| 646 | public function testis_authenticated() |
||
| 647 | { |
||
| 648 | |||
| 649 | $user = new User(); |
||
| 650 | |||
| 651 | //test without setting name |
||
| 652 | $this->assertEquals(false, $user->is_authenticated()); |
||
| 653 | |||
| 654 | //test with name set |
||
| 655 | $user->authenticated = true; |
||
| 656 | $this->assertEquals(true,$user->is_authenticated()); |
||
| 657 | |||
| 658 | } |
||
| 659 | |||
| 660 | public function testfill_in_additional_list_fields() |
||
| 661 | { |
||
| 662 | |||
| 663 | $user = new User(); |
||
| 664 | |||
| 665 | $user->retrieve(1); |
||
| 666 | |||
| 667 | $user->fill_in_additional_list_fields(); |
||
| 668 | |||
| 669 | $this->assertEquals("Administrator",$user->full_name); |
||
| 670 | |||
| 671 | } |
||
| 672 | |||
| 673 | public function testfill_in_additional_detail_fields() |
||
| 674 | { |
||
| 675 | |||
| 676 | $user = new User(); |
||
| 677 | |||
| 678 | $user->retrieve(1); |
||
| 679 | |||
| 680 | $user->fill_in_additional_detail_fields(); |
||
| 681 | |||
| 682 | $this->assertEquals("Administrator",$user->full_name); |
||
| 683 | |||
| 684 | } |
||
| 685 | |||
| 686 | public function testretrieve_user_id() |
||
| 687 | { |
||
| 688 | $user = new User(); |
||
| 689 | |||
| 690 | $result = $user->retrieve_user_id("admin"); |
||
| 691 | $this->assertEquals(1, $result); |
||
| 692 | } |
||
| 693 | |||
| 694 | |||
| 695 | public function testverify_data() |
||
| 696 | { |
||
| 697 | |||
| 698 | global $mod_strings; |
||
| 699 | |||
| 700 | $mod_strings['ERR_EMAIL_NO_OPTS'] = ""; |
||
| 701 | |||
| 702 | $user = new User(); |
||
| 703 | |||
| 704 | $user->retrieve(1); |
||
| 705 | |||
| 706 | //test with default/true |
||
| 707 | $result = $user->verify_data(); |
||
| 708 | $this->assertEquals(true, $result); |
||
| 709 | |||
| 710 | |||
| 711 | //test with false |
||
| 712 | $result = $user->verify_data(false); |
||
| 713 | $this->assertEquals(false, $result); |
||
| 714 | |||
| 715 | } |
||
| 716 | |||
| 717 | public function testget_list_view_data() |
||
| 718 | { |
||
| 719 | global $mod_strings; |
||
| 720 | $mod_strings['LBL_CHECKMARK'] = ""; |
||
| 721 | |||
| 722 | $user = new User(); |
||
| 723 | |||
| 724 | $user->retrieve(1); |
||
| 725 | |||
| 726 | $result = $user->get_list_view_data(); |
||
| 727 | $this->assertTrue(is_array($result)); |
||
| 728 | |||
| 729 | } |
||
| 730 | |||
| 731 | public function testlist_view_parse_additional_sections() |
||
| 732 | { |
||
| 733 | |||
| 734 | $user = new User(); |
||
| 735 | |||
| 736 | $list_form = array(); |
||
| 737 | $result = $user->list_view_parse_additional_sections($list_form); |
||
| 738 | $this->assertSame($list_form, $result); |
||
| 739 | |||
| 740 | } |
||
| 741 | |||
| 742 | public function testGetAllUsersAndGetActiveUsers() |
||
| 743 | { |
||
| 744 | |||
| 745 | $all_users = User::getAllUsers(); |
||
| 746 | $this->assertTrue(is_array($all_users)); |
||
| 747 | |||
| 748 | $active_users = User::getActiveUsers(); |
||
| 749 | $this->assertTrue(is_array($active_users)); |
||
| 750 | |||
| 751 | $this->assertGreaterThanOrEqual(count($active_users), count($all_users)); |
||
| 752 | } |
||
| 753 | |||
| 754 | |||
| 755 | public function testcreate_export_query() { |
||
| 756 | |||
| 757 | $user = new User(); |
||
| 758 | |||
| 759 | //test with empty string params |
||
| 760 | $expected = "SELECT id, user_name, first_name, last_name, description, date_entered, date_modified, modified_user_id, created_by, title, department, is_admin, phone_home, phone_mobile, phone_work, phone_other, phone_fax, address_street, address_city, address_state, address_postalcode, address_country, reports_to_id, portal_only, status, receive_notifications, employee_status, messenger_id, messenger_type, is_group FROM users WHERE users.deleted = 0 AND users.is_admin=0 ORDER BY users.user_name"; |
||
| 761 | $actual = $user->create_export_query('',''); |
||
| 762 | $this->assertSame($expected,$actual); |
||
| 763 | |||
| 764 | |||
| 765 | //test with valid string params |
||
| 766 | $expected = "SELECT id, user_name, first_name, last_name, description, date_entered, date_modified, modified_user_id, created_by, title, department, is_admin, phone_home, phone_mobile, phone_work, phone_other, phone_fax, address_street, address_city, address_state, address_postalcode, address_country, reports_to_id, portal_only, status, receive_notifications, employee_status, messenger_id, messenger_type, is_group FROM users WHERE user_name=\"\" AND users.deleted = 0 AND users.is_admin=0 ORDER BY id"; |
||
| 767 | $actual = $user->create_export_query('id','user_name=""'); |
||
| 768 | $this->assertSame($expected,$actual); |
||
| 769 | |||
| 770 | } |
||
| 771 | |||
| 772 | |||
| 773 | public function testget_meetings() { |
||
| 774 | |||
| 775 | $user = new User(); |
||
| 776 | |||
| 777 | $result = $user->get_meetings(); |
||
| 778 | $this->assertTrue(is_array($result)); |
||
| 779 | |||
| 780 | } |
||
| 781 | |||
| 782 | public function testget_calls() { |
||
| 783 | |||
| 784 | $user = new User(); |
||
| 785 | |||
| 786 | //$result = $user->get_calls(); |
||
| 787 | //$this->assertTrue(is_array($result)); |
||
| 788 | |||
| 789 | $this->markTestIncomplete('Error:Only variables should be passed by reference'); |
||
| 790 | } |
||
| 791 | |||
| 792 | |||
| 793 | public function testdisplayEmailCounts() { |
||
| 794 | |||
| 795 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 796 | global $db; |
||
| 797 | unset ($db->database); |
||
| 798 | $db->checkConnection(); |
||
| 799 | |||
| 800 | |||
| 801 | $user = new User(); |
||
| 802 | |||
| 803 | $expected = '<script type="text/javascript" language="Javascript">var welcome = document.getElementById("welcome");var welcomeContent = welcome.innerHTML;welcome.innerHTML = welcomeContent + " <a href=index.php?module=Emails&action=ListViewGroup>Group Inbox: (0 New)</a>";</script>'; |
||
| 804 | |||
| 805 | //cpature the screen output and compare with exected values |
||
| 806 | |||
| 807 | ob_start(); |
||
| 808 | |||
| 809 | $user->displayEmailCounts(); |
||
| 810 | |||
| 811 | $renderedContent = ob_get_contents(); |
||
| 812 | ob_end_clean(); |
||
| 813 | |||
| 814 | $this->assertSame($expected,$renderedContent); |
||
| 815 | |||
| 816 | } |
||
| 817 | |||
| 818 | |||
| 819 | public function testgetSystemDefaultNameAndEmail() |
||
| 820 | { |
||
| 821 | |||
| 822 | $user = new User(); |
||
| 823 | |||
| 824 | $expected = array( 'email' => '[email protected]', 'name' => 'SuiteCRM'); |
||
| 825 | $actual = $user->getSystemDefaultNameAndEmail(); |
||
| 826 | $this->assertSame($expected,$actual); |
||
| 827 | |||
| 828 | } |
||
| 829 | |||
| 830 | |||
| 831 | public function testsetDefaultsInConfig() |
||
| 832 | { |
||
| 833 | $user = new User(); |
||
| 834 | |||
| 835 | $result = $user->setDefaultsInConfig(); |
||
| 836 | |||
| 837 | $this->assertTrue(is_array($result)); |
||
| 838 | $this->assertEquals('sugar', $result['email_default_client']); |
||
| 839 | $this->assertEquals('html', $result['email_default_editor']); |
||
| 840 | |||
| 841 | } |
||
| 842 | |||
| 843 | |||
| 844 | public function testgetEmailLink2() |
||
| 845 | { |
||
| 846 | $user = new User(); |
||
| 847 | |||
| 848 | $user->retrieve(1); |
||
| 849 | |||
| 850 | |||
| 851 | //test with accounts module |
||
| 852 | $account = new Account(); |
||
| 853 | $account->name = "test"; |
||
| 854 | |||
| 855 | $expected = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({\"fullComposeUrl\":\"contact_id=\u0026parent_type=Accounts\u0026parent_id=\u0026parent_name=test\u0026to_addrs_ids=\u0026to_addrs_names=\u0026to_addrs_emails=\u0026to_email_addrs=test%26nbsp%3B%26lt%3Babc%40email.com%26gt%3B\u0026return_module=Accounts\u0026return_action=DetailView\u0026return_id=\",\"composePackage\":{\"contact_id\":\"\",\"parent_type\":\"Accounts\",\"parent_id\":\"\",\"parent_name\":\"test\",\"to_addrs_ids\":\"\",\"to_addrs_names\":\"\",\"to_addrs_emails\":\"\",\"to_email_addrs\":\"test \[email protected]\u003E\",\"return_module\":\"Accounts\",\"return_action\":\"DetailView\",\"return_id\":\"\"}});' class=''>"; |
||
| 856 | $actual = $user->getEmailLink2("[email protected]", $account); |
||
| 857 | $this->assertSame($expected,$actual); |
||
| 858 | |||
| 859 | |||
| 860 | //test with contacts module |
||
| 861 | $contact = new Contact(); |
||
| 862 | $contact->name = "test"; |
||
| 863 | |||
| 864 | $expected = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({\"fullComposeUrl\":\"contact_id=\u0026parent_type=Contacts\u0026parent_id=\u0026parent_name=+\u0026to_addrs_ids=\u0026to_addrs_names=+\u0026to_addrs_emails=\u0026to_email_addrs=+%26nbsp%3B%26lt%3Babc%40email.com%26gt%3B\u0026return_module=Contacts\u0026return_action=DetailView\u0026return_id=\",\"composePackage\":{\"contact_id\":\"\",\"parent_type\":\"Contacts\",\"parent_id\":\"\",\"parent_name\":\" \",\"to_addrs_ids\":\"\",\"to_addrs_names\":\" \",\"to_addrs_emails\":\"\",\"to_email_addrs\":\" \[email protected]\u003E\",\"return_module\":\"Contacts\",\"return_action\":\"DetailView\",\"return_id\":\"\"}});' class=''>"; |
||
| 865 | $actual = $user->getEmailLink2("[email protected]", $contact); |
||
| 866 | $this->assertSame($expected,$actual); |
||
| 867 | |||
| 868 | } |
||
| 869 | |||
| 870 | |||
| 871 | public function testgetEmailLink() |
||
| 872 | { |
||
| 873 | |||
| 874 | $user = new User(); |
||
| 875 | |||
| 876 | $user->retrieve(1); |
||
| 877 | |||
| 878 | |||
| 879 | //test with accounts module |
||
| 880 | $account = new Account(); |
||
| 881 | $account->name = "test"; |
||
| 882 | |||
| 883 | $expected = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({\"fullComposeUrl\":\"contact_id=\u0026parent_type=Accounts\u0026parent_id=\u0026parent_name=test\u0026to_addrs_ids=\u0026to_addrs_names=\u0026to_addrs_emails=\u0026to_email_addrs=test%26nbsp%3B%26lt%3Btest%26gt%3B\u0026return_module=Accounts\u0026return_action=DetailView\u0026return_id=\",\"composePackage\":{\"contact_id\":\"\",\"parent_type\":\"Accounts\",\"parent_id\":\"\",\"parent_name\":\"test\",\"to_addrs_ids\":\"\",\"to_addrs_names\":\"\",\"to_addrs_emails\":\"\",\"to_email_addrs\":\"test \u003Ctest\u003E\",\"return_module\":\"Accounts\",\"return_action\":\"DetailView\",\"return_id\":\"\"}});' class=''>"; |
||
| 884 | $actual = $user->getEmailLink("name", $account); |
||
| 885 | $this->assertSame($expected,$actual); |
||
| 886 | |||
| 887 | |||
| 888 | //test with contacts module |
||
| 889 | $contact = new Contact(); |
||
| 890 | $contact->name = "test"; |
||
| 891 | |||
| 892 | $expected = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({\"fullComposeUrl\":\"contact_id=\u0026parent_type=Contacts\u0026parent_id=\u0026parent_name=+\u0026to_addrs_ids=\u0026to_addrs_names=+\u0026to_addrs_emails=\u0026to_email_addrs=+%26nbsp%3B%26lt%3Btest%26gt%3B\u0026return_module=Contacts\u0026return_action=DetailView\u0026return_id=\",\"composePackage\":{\"contact_id\":\"\",\"parent_type\":\"Contacts\",\"parent_id\":\"\",\"parent_name\":\" \",\"to_addrs_ids\":\"\",\"to_addrs_names\":\" \",\"to_addrs_emails\":\"\",\"to_email_addrs\":\" \u003Ctest\u003E\",\"return_module\":\"Contacts\",\"return_action\":\"DetailView\",\"return_id\":\"\"}});' class=''>"; |
||
| 893 | $actual = $user->getEmailLink("name", $contact); |
||
| 894 | $this->assertSame($expected,$actual); |
||
| 895 | |||
| 896 | } |
||
| 897 | |||
| 898 | public function testgetLocaleFormatDesc() |
||
| 899 | { |
||
| 900 | $user = new User(); |
||
| 901 | |||
| 902 | $result = $user->getLocaleFormatDesc(); |
||
| 903 | $this->assertTrue(isset($result)); |
||
| 904 | $this->assertGreaterThan(0,strlen($result)); |
||
| 905 | |||
| 906 | } |
||
| 907 | |||
| 908 | public function testisAdmin() |
||
| 909 | { |
||
| 910 | $user = new User(); |
||
| 911 | |||
| 912 | //test without setting attribute |
||
| 913 | $this->assertEquals(false, $user->isAdmin()); |
||
| 914 | |||
| 915 | //test with attribute set |
||
| 916 | $user->is_admin = 1; |
||
| 917 | $this->assertEquals(true, $user->isAdmin()); |
||
| 918 | |||
| 919 | } |
||
| 920 | |||
| 921 | public function testisDeveloperForAnyModule() |
||
| 922 | { |
||
| 923 | $user = new User(); |
||
| 924 | |||
| 925 | //test without setting is_admin |
||
| 926 | $this->assertEquals(false, $user->isDeveloperForAnyModule()); |
||
| 927 | |||
| 928 | |||
| 929 | //test with id set |
||
| 930 | $user->id = 1; |
||
| 931 | $this->assertEquals(false, $user->isDeveloperForAnyModule()); |
||
| 932 | |||
| 933 | |||
| 934 | //test with id and is_admin set |
||
| 935 | $user->is_admin = 1; |
||
| 936 | $this->assertEquals(true, $user->isDeveloperForAnyModule()); |
||
| 937 | |||
| 938 | } |
||
| 939 | |||
| 940 | public function testgetDeveloperModules() |
||
| 941 | { |
||
| 942 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 943 | global $db; |
||
| 944 | unset ($db->database); |
||
| 945 | $db->checkConnection(); |
||
| 946 | |||
| 947 | $user = new User(); |
||
| 948 | |||
| 949 | $user->retrieve(1); |
||
| 950 | |||
| 951 | $result = $user->getDeveloperModules(); |
||
| 952 | $this->assertTrue(is_array($result)); |
||
| 953 | |||
| 954 | } |
||
| 955 | |||
| 956 | public function testisDeveloperForModule() |
||
| 957 | { |
||
| 958 | global $db; |
||
| 959 | unset ($db->database); |
||
| 960 | $db->checkConnection(); |
||
| 961 | |||
| 962 | $user = new User(); |
||
| 963 | |||
| 964 | |||
| 965 | //test without setting is_admin |
||
| 966 | $this->assertEquals(false, $user->isDeveloperForModule("Accounts")); |
||
| 967 | |||
| 968 | |||
| 969 | //test with id set |
||
| 970 | $user->id = 1; |
||
| 971 | $this->assertEquals(false, $user->isDeveloperForModule("Accounts")); |
||
| 972 | |||
| 973 | |||
| 974 | //test with id and is_admin set |
||
| 975 | $user->is_admin = 1; |
||
| 976 | $this->assertEquals(true, $user->isDeveloperForModule("Accounts")); |
||
| 977 | |||
| 978 | |||
| 979 | } |
||
| 980 | |||
| 981 | public function testgetAdminModules() |
||
| 982 | { |
||
| 983 | //unset and reconnect Db to resolve mysqli fetch exeception |
||
| 984 | global $db; |
||
| 985 | unset ($db->database); |
||
| 986 | $db->checkConnection(); |
||
| 987 | |||
| 988 | $user = new User(); |
||
| 989 | |||
| 990 | $user->retrieve(1); |
||
| 991 | |||
| 992 | $result = $user->getAdminModules(); |
||
| 993 | $this->assertTrue(is_array($result)); |
||
| 994 | |||
| 995 | } |
||
| 996 | |||
| 997 | public function testisAdminForModule() |
||
| 998 | { |
||
| 999 | global $db; |
||
| 1000 | unset ($db->database); |
||
| 1001 | $db->checkConnection(); |
||
| 1002 | |||
| 1003 | $user = new User(); |
||
| 1004 | |||
| 1005 | |||
| 1006 | //test without setting is_admin |
||
| 1007 | $this->assertEquals(false, $user->isAdminForModule("Accounts")); |
||
| 1008 | |||
| 1009 | |||
| 1010 | //test with id set |
||
| 1011 | $user->id = 1; |
||
| 1012 | $this->assertEquals(false, $user->isAdminForModule("Accounts")); |
||
| 1013 | |||
| 1014 | |||
| 1015 | //test with id and is_admin set |
||
| 1016 | $user->is_admin = 1; |
||
| 1017 | $this->assertEquals(true, $user->isAdminForModule("Accounts")); |
||
| 1018 | |||
| 1019 | |||
| 1020 | } |
||
| 1021 | |||
| 1022 | public function testshowLastNameFirst() |
||
| 1023 | { |
||
| 1024 | $user = new User(); |
||
| 1025 | |||
| 1026 | $result = $user->showLastNameFirst(); |
||
| 1027 | $this->assertEquals(false, $result); |
||
| 1028 | |||
| 1029 | } |
||
| 1030 | |||
| 1031 | public function testcreate_new_list_query() |
||
| 1032 | { |
||
| 1033 | |||
| 1034 | $user = new User(); |
||
| 1035 | |||
| 1036 | //test with empty string params |
||
| 1037 | $expected = " SELECT users.* , ' ' c_accept_status_fields , ' ' call_id , ' ' securitygroup_noninher_fields , ' ' securitygroup_id , LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as full_name, LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as name , jt2.last_name reports_to_name , jt2.created_by reports_to_name_owner , 'Users' reports_to_name_mod, ' ' m_accept_status_fields , ' ' meeting_id FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where users.deleted=0"; |
||
| 1038 | $actual = $user->create_new_list_query('',''); |
||
| 1039 | $this->assertSame($expected,$actual); |
||
| 1040 | |||
| 1041 | |||
| 1042 | //test with valid string params |
||
| 1043 | $expected = " SELECT users.* , ' ' c_accept_status_fields , ' ' call_id , ' ' securitygroup_noninher_fields , ' ' securitygroup_id , LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as full_name, LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as name , jt2.last_name reports_to_name , jt2.created_by reports_to_name_owner , 'Users' reports_to_name_mod, ' ' m_accept_status_fields , ' ' meeting_id FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where (user_name=\"\") AND users.deleted=0 ORDER BY users.id"; |
||
| 1044 | $actual = $user->create_new_list_query('id','user_name=""'); |
||
| 1045 | $this->assertSame($expected,$actual); |
||
| 1046 | |||
| 1047 | } |
||
| 1048 | |||
| 1049 | |||
| 1050 | public function testget_first_day_of_week() |
||
| 1051 | { |
||
| 1052 | $user = new User(); |
||
| 1053 | |||
| 1054 | $result = $user->get_first_day_of_week(); |
||
| 1055 | $this->assertTrue(is_numeric($result)); |
||
| 1056 | |||
| 1057 | } |
||
| 1058 | |||
| 1059 | |||
| 1060 | public function testgeneratePassword() |
||
| 1061 | { |
||
| 1062 | //generate apsswords and verify they are not same |
||
| 1063 | |||
| 1064 | $password1 = User::generatePassword(); |
||
| 1065 | $this->assertGreaterThan(0,strlen($password1)); |
||
| 1066 | |||
| 1067 | $password2 = User::generatePassword(); |
||
| 1068 | $this->assertGreaterThan(0,strlen($password2)); |
||
| 1069 | |||
| 1070 | $this->assertNotEquals($password1, $password2); |
||
| 1071 | |||
| 1072 | } |
||
| 1073 | |||
| 1074 | |||
| 1075 | public function testsendEmailForPassword() |
||
| 1076 | { |
||
| 1077 | |||
| 1078 | $user = new User(); |
||
| 1079 | |||
| 1080 | $result = $user->sendEmailForPassword("1"); |
||
| 1081 | |||
| 1082 | //expected result is a array with template not found message. |
||
| 1083 | $this->assertTrue(is_array($result)); |
||
| 1084 | |||
| 1085 | } |
||
| 1086 | |||
| 1087 | |||
| 1088 | public function testafterImportSave() |
||
| 1089 | { |
||
| 1090 | error_reporting(E_ALL); |
||
| 1091 | |||
| 1092 | $user = new User(); |
||
| 1093 | |||
| 1094 | //execute the method and test if it works and does not throws an exception. |
||
| 1095 | try { |
||
| 1096 | $result = $user->afterImportSave(); |
||
| 1097 | $this->assertTrue(true); |
||
| 1098 | } |
||
| 1099 | catch (Exception $e) { |
||
| 1100 | $this->assertStringStartsWith('Cannot modify header information', $e->getMessage()); |
||
| 1101 | } |
||
| 1102 | |||
| 1103 | } |
||
| 1104 | |||
| 1105 | |||
| 1106 | public function testisPrimaryEmail() |
||
| 1107 | { |
||
| 1108 | $user = new User(); |
||
| 1109 | |||
| 1110 | //test without user email |
||
| 1111 | $this->assertEquals(false, $user->isPrimaryEmail("[email protected]")); |
||
| 1112 | |||
| 1113 | |||
| 1114 | //test with non matching user email |
||
| 1115 | $user->email1 = "[email protected]"; |
||
| 1116 | $this->assertEquals(false, $user->isPrimaryEmail("[email protected]")); |
||
| 1117 | |||
| 1118 | |||
| 1119 | //test with matching user email |
||
| 1120 | $user->email1 = "[email protected]"; |
||
| 1121 | $this->assertEquals(true, $user->isPrimaryEmail("[email protected]")); |
||
| 1122 | |||
| 1123 | } |
||
| 1124 | |||
| 1125 | } |
||
| 1126 |