Files
thankcard-system/tests/Feature/PasswordMd5Test.php
2026-07-06 14:37:32 +07:00

68 lines
2.1 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Services\Admin\Contracts\AdminServiceInterface;
use App\Services\User\Contracts\UserServiceInterface;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PasswordMd5Test extends TestCase
{
use RefreshDatabase;
private UserServiceInterface $userService;
private AdminServiceInterface $adminService;
protected function setUp(): void
{
parent::setUp();
$this->userService = $this->app->make(UserServiceInterface::class);
$this->adminService = $this->app->make(AdminServiceInterface::class);
}
public function test_user_service_update_password_stores_as_md5(): void
{
$user = User::create([
'msnv' => 4001,
'name' => 'Test User',
'mail' => 'test@example.com',
'pass' => md5('old_password'),
'departments' => 1,
'role' => User::ROLE_MEMBER,
'status' => User::STATUS_ACTIVE,
'card' => 10,
'flag_send' => User::FLAG_SEND_ENABLED,
'first_login' => User::FIRST_LOGIN_TRUE,
]);
$this->userService->updatePassword($user, 'new_secret_password');
$user->refresh();
$this->assertEquals(md5('new_secret_password'), $user->pass);
$this->assertEquals(User::FIRST_LOGIN_FALSE, $user->first_login);
}
public function test_admin_service_create_user_stores_password_as_md5(): void
{
$data = [
'msnv' => 4002,
'name' => 'Created User',
'mail' => 'created@example.com',
'departments' => 2,
'password' => 'admin_created_pass',
'role' => User::ROLE_MEMBER,
];
$this->adminService->createUser($data);
$user = User::where('msnv', 4002)->first();
$this->assertNotNull($user);
$this->assertEquals(md5('admin_created_pass'), $user->pass);
$this->assertEquals(User::FIRST_LOGIN_TRUE, $user->first_login);
}
}