UserModelTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Models\Group;
  4. use App\Models\TwoFAccount;
  5. use App\Models\User;
  6. use Tests\ModelTestCase;
  7. /**
  8. * @covers \App\Models\User
  9. */
  10. class UserModelTest extends ModelTestCase
  11. {
  12. /**
  13. * @test
  14. */
  15. public function test_model_configuration()
  16. {
  17. $this->runConfigurationAssertions(new User(),
  18. ['name', 'email', 'password'],
  19. ['password', 'remember_token'],
  20. ['*'],
  21. [],
  22. [
  23. 'id' => 'int',
  24. 'email_verified_at' => 'datetime',
  25. 'is_admin' => 'boolean',
  26. 'twofaccounts_count' => 'integer',
  27. 'groups_count' => 'integer',
  28. ]
  29. );
  30. }
  31. /**
  32. * @test
  33. */
  34. public function test_email_is_set_lowercased()
  35. {
  36. $user = User::factory()->make([
  37. 'email' => 'UPPERCASE@example.COM',
  38. ]);
  39. $this->assertEquals(strtolower('UPPERCASE@example.COM'), $user->email);
  40. }
  41. /**
  42. * @test
  43. */
  44. public function test_twofaccounts_relation()
  45. {
  46. $user = new User();
  47. $accounts = $user->twofaccounts();
  48. $this->assertHasManyRelation($accounts, $user, new TwoFAccount());
  49. }
  50. /**
  51. * @test
  52. */
  53. public function test_groups_relation()
  54. {
  55. $user = new User();
  56. $groups = $user->groups();
  57. $this->assertHasManyRelation($groups, $user, new Group());
  58. }
  59. }