| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace Tests\Unit\Helpers;
- use App\Models\Role;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Tests\TestCase;
- class RolesHelperTest extends TestCase
- {
- use RefreshDatabase;
- protected $seed = true;
- public function test_get_roles_returns_all_roles(): void
- {
- $roles = getRoles();
- $this->assertIsArray($roles);
- $this->assertArrayHasKey(Role::ADMIN, $roles);
- $this->assertArrayHasKey(Role::MANAGER, $roles);
- $this->assertArrayHasKey(Role::BRIGADIER, $roles);
- }
- public function test_get_roles_returns_name_by_key(): void
- {
- $this->assertEquals('Админ', getRoles(Role::ADMIN));
- $this->assertEquals('Менеджер', getRoles(Role::MANAGER));
- $this->assertEquals('Бригадир', getRoles(Role::BRIGADIER));
- }
- public function test_get_roles_returns_all_when_key_not_found(): void
- {
- $result = getRoles('nonexistent');
- $this->assertIsArray($result);
- $this->assertCount(3, $result);
- }
- public function test_has_role_returns_true_for_correct_role(): void
- {
- $user = new \App\Models\User();
- $user->role = Role::ADMIN;
- $this->assertTrue(hasRole(Role::ADMIN, $user));
- }
- public function test_has_role_returns_false_for_wrong_role(): void
- {
- $user = new \App\Models\User();
- $user->role = Role::MANAGER;
- $this->assertFalse(hasRole(Role::ADMIN, $user));
- }
- public function test_has_role_supports_multiple_roles(): void
- {
- $user = new \App\Models\User();
- $user->role = Role::BRIGADIER;
- $this->assertTrue(hasRole(Role::MANAGER . ',' . Role::BRIGADIER, $user));
- }
- public function test_has_role_returns_false_when_user_null(): void
- {
- $this->assertFalse(hasRole(Role::ADMIN, null));
- }
- public function test_role_name_returns_correct_name(): void
- {
- $this->assertEquals('Админ', roleName(Role::ADMIN));
- $this->assertEquals('Менеджер', roleName(Role::MANAGER));
- $this->assertEquals('Бригадир', roleName(Role::BRIGADIER));
- }
- public function test_file_name_replaces_special_chars(): void
- {
- $result = fileName('file*name:test\\path/to?file<more>');
- $this->assertStringNotContainsString('*', $result);
- $this->assertStringNotContainsString(':', $result);
- $this->assertStringNotContainsString('\\', $result);
- $this->assertStringNotContainsString('/', $result);
- $this->assertStringNotContainsString('?', $result);
- $this->assertStringNotContainsString('<', $result);
- $this->assertStringNotContainsString('>', $result);
- }
- public function test_file_name_keeps_safe_chars(): void
- {
- $result = fileName('normal-file_name.xlsx');
- $this->assertEquals('normal-file_name.xlsx', $result);
- }
- public function test_year_returns_integer(): void
- {
- $this->assertIsInt(year());
- }
- public function test_year_returns_current_year_by_default(): void
- {
- $this->assertEquals((int) date('Y'), year());
- }
- }
|