From 776a0a67ae12b2bb1acb86d2a8e1ac35964050f6 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 27 Dec 2017 18:40:16 +0800 Subject: [PATCH] test(model): add tests for "User" model --- app/Models/User.php | 4 ++-- tests/ModelsTest/UserTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/ModelsTest/UserTest.php diff --git a/app/Models/User.php b/app/Models/User.php index 5f7b6d1f..52423566 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -78,7 +78,7 @@ class User extends Model { // compare directly if any responses is returned by event dispatcher if ($result = static::getEncryptedPwdFromEvent($rawPasswd, $this)) { - return hash_equals($this->password, $result); + return hash_equals($this->password, $result); // @codeCoverageIgnore } return app('cipher')->verify($rawPasswd, $this->password, config('secure.salt')); @@ -136,7 +136,7 @@ class User extends Model $responses = event(new EncryptUserPassword($new_passwd, $this)); if (isset($responses[0])) { - $this->password = $responses[0]; + $this->password = $responses[0]; // @codeCoverageIgnore } else { $this->password = app('cipher')->hash($new_passwd, config('secure.salt')); } diff --git a/tests/ModelsTest/UserTest.php b/tests/ModelsTest/UserTest.php new file mode 100644 index 00000000..7175b1bd --- /dev/null +++ b/tests/ModelsTest/UserTest.php @@ -0,0 +1,30 @@ +make([ + 'last_sign_at' => Utils::getTimeFormatted(time()) + ]); + $user->sign(); + $this->assertFalse($user->sign()); + } + + public function testGetNickName() + { + $user = new User(); + $this->assertEquals( + trans('general.unexistent-user'), + $user->getNickName() + ); + } +}