UserTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace tests\unit\models;
  3. use app\models\User;
  4. class UserTest extends \Codeception\Test\Unit
  5. {
  6. public function testFindUserById()
  7. {
  8. expect_that($user = User::findIdentity(100));
  9. expect($user->username)->equals('admin');
  10. expect_not(User::findIdentity(999));
  11. }
  12. public function testFindUserByAccessToken()
  13. {
  14. expect_that($user = User::findIdentityByAccessToken('100-token'));
  15. expect($user->username)->equals('admin');
  16. expect_not(User::findIdentityByAccessToken('non-existing'));
  17. }
  18. public function testFindUserByUsername()
  19. {
  20. expect_that($user = User::findByUsername('admin'));
  21. expect_not(User::findByUsername('not-admin'));
  22. }
  23. /**
  24. * @depends testFindUserByUsername
  25. */
  26. public function testValidateUser($user)
  27. {
  28. $user = User::findByUsername('admin');
  29. expect_that($user->validateAuthKey('test100key'));
  30. expect_not($user->validateAuthKey('test102key'));
  31. expect_that($user->validatePassword('admin'));
  32. expect_not($user->validatePassword('123456'));
  33. }
  34. }