test(model): add tests for "User" model
This commit is contained in:
parent
b1fa8c098b
commit
776a0a67ae
|
|
@ -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'));
|
||||
}
|
||||
|
|
|
|||
30
tests/ModelsTest/UserTest.php
Normal file
30
tests/ModelsTest/UserTest.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Utils;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testSign()
|
||||
{
|
||||
$user = factory(User::class)->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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user