Save
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminAccessTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_guest_is_redirected_to_login(): void
|
||||
{
|
||||
$response = $this->get('/admin');
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function test_non_admin_user_cannot_access_admin_panel(): void
|
||||
{
|
||||
$role = Role::create(['libelle' => 'Utilisateur']);
|
||||
$user = User::factory()->create(['id_role' => $role->id]);
|
||||
|
||||
$response = $this->actingAs($user)->get('/admin');
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_admin_user_can_access_admin_panel(): void
|
||||
{
|
||||
$role = Role::create(['libelle' => 'Admin']);
|
||||
$user = User::factory()->create(['id_role' => $role->id]);
|
||||
|
||||
$response = $this->actingAs($user)->get('/admin');
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\StressEvent;
|
||||
use App\Models\ResultatDiag;
|
||||
use Illuminate\Foundation.Testing.RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class DiagnosticTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_diagnostic_score_calculation_and_storage()
|
||||
public function test_diagnostic_score_calculation_and_storage(): void
|
||||
{
|
||||
$this->withoutMiddleware();
|
||||
|
||||
// Créer un utilisateur
|
||||
$user = User::factory()->create();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\StressCalculator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StressCalculatorTest extends TestCase
|
||||
{
|
||||
private StressCalculator $calculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->calculator = new StressCalculator();
|
||||
}
|
||||
|
||||
public function test_calculate_score_sums_points_correctly(): void
|
||||
{
|
||||
$points = [100, 73, 50];
|
||||
$this->assertEquals(223, $this->calculator->calculateScore($points));
|
||||
}
|
||||
|
||||
public function test_calculate_score_returns_zero_for_empty_array(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->calculator->calculateScore([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stressLevelProvider
|
||||
*/
|
||||
public function test_determine_level_returns_correct_label(int $score, string $expectedLevel): void
|
||||
{
|
||||
$this->assertEquals($expectedLevel, $this->calculator->determineLevel($score));
|
||||
}
|
||||
|
||||
public static function stressLevelProvider(): array
|
||||
{
|
||||
return [
|
||||
[350, StressCalculator::LEVEL_HIGH],
|
||||
[300, StressCalculator::LEVEL_HIGH],
|
||||
[299, StressCalculator::LEVEL_MODERATE],
|
||||
[150, StressCalculator::LEVEL_MODERATE],
|
||||
[149, StressCalculator::LEVEL_LOW],
|
||||
[0, StressCalculator::LEVEL_LOW],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user