DatabaseImporterTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Adldap\Laravel\Tests;
  3. use Adldap\Laravel\Commands\Import;
  4. use Adldap\Laravel\Tests\Models\TestUser;
  5. use Illuminate\Support\Str;
  6. class DatabaseImporterTest extends DatabaseTestCase
  7. {
  8. /** @test */
  9. public function ldap_users_are_imported()
  10. {
  11. $user = $this->makeLdapUser();
  12. $importer = new Import($user, new TestUser());
  13. $model = $importer->handle();
  14. $this->assertEquals($user->getCommonName(), $model->name);
  15. $this->assertEquals($user->getUserPrincipalName(), $model->email);
  16. $this->assertFalse($model->exists);
  17. }
  18. /** @test */
  19. public function ldap_users_are_not_duplicated_with_alternate_casing()
  20. {
  21. $firstUser = $this->makeLdapUser();
  22. $firstUser->setUserPrincipalName('JDOE@EMAIL.com');
  23. $m1 = (new Import($firstUser, new TestUser()))->handle();
  24. $m1->password = bcrypt(Str::random(16));
  25. $m1->save();
  26. $secondUser = $this->makeLdapUser();
  27. $secondUser->setUserPrincipalName('jdoe@email.com');
  28. $m2 = (new Import($secondUser, new TestUser()))->handle();
  29. $this->assertTrue($m1->is($m2));
  30. }
  31. /**
  32. * @test
  33. * @expectedException \UnexpectedValueException
  34. */
  35. public function exception_is_thrown_when_guid_is_null()
  36. {
  37. $u = $this->makeLdapUser([
  38. 'objectguid' => null,
  39. ]);
  40. (new Import($u, new TestUser()))->handle();
  41. }
  42. /**
  43. * @test
  44. * @expectedException \UnexpectedValueException
  45. */
  46. public function exception_is_thrown_when_guid_is_empty()
  47. {
  48. $u = $this->makeLdapUser([
  49. 'objectguid' => ' ',
  50. ]);
  51. (new Import($u, new TestUser()))->handle();
  52. }
  53. /**
  54. * @test
  55. * @expectedException \UnexpectedValueException
  56. */
  57. public function exception_is_thrown_when_username_is_null()
  58. {
  59. $u = $this->makeLdapUser([
  60. 'userprincipalname' => null,
  61. ]);
  62. (new Import($u, new TestUser()))->handle();
  63. }
  64. /**
  65. * @test
  66. * @expectedException \UnexpectedValueException
  67. */
  68. public function exception_is_thrown_when_username_is_empty()
  69. {
  70. $u = $this->makeLdapUser([
  71. 'userprincipalname' => ' ',
  72. ]);
  73. (new Import($u, new TestUser()))->handle();
  74. }
  75. }