Initial commit: Import existing Laravel project

This commit is contained in:
jeremy bayse
2026-06-15 08:12:33 +02:00
parent 7420d1b466
commit 030d76af53
143 changed files with 21885 additions and 1 deletions

View File

@@ -0,0 +1,81 @@
<?php
namespace Tests\Feature;
use App\Models\Attachment;
use App\Models\Order;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AttachmentTest extends TestCase
{
use RefreshDatabase;
public function test_guest_cannot_access_attachment()
{
$order = Order::create([
'number' => 'CMD-2026-0001',
'label' => 'Ordinateur portable',
'type' => 'Matériel réseau / Serveur',
'supplier' => 'Dell',
'quote_number' => 'DEV-2026-0001',
'amount_ht' => 1000.00,
'amount_ttc' => 1200.00,
'requested_by' => 'Sylvain',
'delivery_deadline' => now()->addDays(30),
'status' => 'draft',
]);
$attachment = Attachment::create([
'order_id' => $order->id,
'file_path' => 'commandes/1/devis.pdf',
'file_name' => 'devis.pdf',
'file_type' => 'quote',
]);
$response = $this->get(route('attachments.show', $attachment->id));
$response->assertRedirect('/login');
}
public function test_authenticated_user_can_access_attachment_when_file_exists()
{
Storage::fake('public');
$user = User::create([
'name' => 'Jérémy',
'email' => 'jeremy@agglo.local',
'password' => bcrypt('password'),
'role' => 'chef_service',
]);
$order = Order::create([
'number' => 'CMD-2026-0001',
'label' => 'Ordinateur portable',
'type' => 'Matériel réseau / Serveur',
'supplier' => 'Dell',
'quote_number' => 'DEV-2026-0001',
'amount_ht' => 1000.00,
'amount_ttc' => 1200.00,
'requested_by' => 'Sylvain',
'delivery_deadline' => now()->addDays(30),
'status' => 'draft',
]);
Storage::disk('public')->put("commandes/{$order->id}/devis.pdf", "dummy content");
$attachment = Attachment::create([
'order_id' => $order->id,
'file_path' => "commandes/{$order->id}/devis.pdf",
'file_name' => 'devis.pdf',
'file_type' => 'quote',
]);
$response = $this->actingAs($user)->get(route('attachments.show', $attachment->id));
$response->assertOk();
$response->assertHeader('Content-Disposition', 'inline; filename="devis.pdf"');
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get('/login');
$response->assertStatus(200);
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$user = User::factory()->create();
$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$user = User::factory()->create();
$this->post('/login', [
'email' => $user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
}
public function test_users_can_logout(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/logout');
$this->assertGuest();
$response->assertRedirect('/');
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_email_verification_screen_can_be_rendered(): void
{
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/verify-email');
$response->assertStatus(200);
}
public function test_email_can_be_verified(): void
{
$user = User::factory()->unverified()->create();
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}
public function test_email_is_not_verified_with_invalid_hash(): void
{
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
$this->assertFalse($user->fresh()->hasVerifiedEmail());
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/confirm-password');
$response->assertStatus(200);
}
public function test_password_can_be_confirmed(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/confirm-password', [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/confirm-password', [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get('/forgot-password');
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/forgot-password', ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('login'));
return true;
});
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->put('/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
public function test_correct_password_must_be_provided_to_update_password(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->put('/password', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasErrors('current_password')
->assertRedirect('/profile');
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_is_disabled(): void
{
$response = $this->get('/register');
$response->assertStatus(404);
}
public function test_registration_post_is_disabled(): void
{
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertStatus(404);
$this->assertGuest();
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertRedirect('/login');
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Tests\Feature;
use App\Models\Hardware;
use App\Models\Order;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class HardwareTest extends TestCase
{
use RefreshDatabase;
private User $admin;
private User $chef;
protected function setUp(): void
{
parent::setUp();
$this->admin = User::create([
'name' => 'Sylvain',
'email' => 'sylvain@agglo.local',
'password' => bcrypt('password'),
'role' => 'admin_reseau',
]);
$this->chef = User::create([
'name' => 'Jérémy',
'email' => 'jeremy@agglo.local',
'password' => bcrypt('password'),
'role' => 'chef_service',
]);
}
public function test_guest_cannot_access_hardware_index()
{
$response = $this->get(route('materiels.index'));
$response->assertRedirect('/login');
}
public function test_authenticated_user_can_access_hardware_index()
{
$response = $this->actingAs($this->admin)->get(route('materiels.index'));
$response->assertOk();
}
public function test_can_create_hardware_with_valid_data()
{
$order = Order::create([
'number' => 'CMD-2026-0001',
'label' => 'Achat Commutateurs',
'type' => 'Matériel réseau / Serveur',
'supplier' => 'Cisco',
'quote_number' => 'DEV-999',
'amount_ht' => 5000.00,
'amount_ttc' => 6000.00,
'requested_by' => 'Sylvain',
'delivery_deadline' => now()->addDays(30),
'status' => 'ordered',
]);
$payload = [
'name' => 'Switch Coeur Informatique',
'type' => 'switch',
'brand' => 'Cisco',
'model' => 'Catalyst 9300',
'serial_number' => 'CSCO987654321',
'status' => 'en_stock',
'purchase_date' => '2026-06-01',
'commissioning_date' => '2026-06-10',
'warranty_expiration_date' => '2029-06-01',
'location' => 'Salle Serveur 1, Baie 3',
'ip_address' => '10.0.0.1',
'order_id' => $order->id,
'notes' => 'Acheté pour le renouvellement du coeur de réseau.',
];
$response = $this->actingAs($this->admin)->post(route('materiels.store'), $payload);
$this->assertDatabaseHas('hardwares', [
'serial_number' => 'CSCO987654321',
'name' => 'Switch Coeur Informatique',
'order_id' => $order->id,
]);
$hardware = Hardware::where('serial_number', 'CSCO987654321')->first();
$response->assertRedirect(route('materiels.show', $hardware->id));
}
public function test_cannot_create_hardware_with_duplicate_serial_number()
{
Hardware::create([
'name' => 'Serveur Test',
'type' => 'serveur',
'brand' => 'Dell',
'model' => 'R740',
'serial_number' => 'SN-DUPLICATE-123',
'status' => 'en_service',
'location' => 'Salle Serveur 1',
]);
$payload = [
'name' => 'Autre Serveur',
'type' => 'serveur',
'brand' => 'Dell',
'model' => 'R750',
'serial_number' => 'SN-DUPLICATE-123', // Doublon
'status' => 'en_stock',
'location' => 'Salle Serveur 2',
];
$response = $this->actingAs($this->admin)->post(route('materiels.store'), $payload);
$response->assertSessionHasErrors('serial_number');
}
public function test_can_update_hardware_successfully()
{
$hardware = Hardware::create([
'name' => 'Onduleur Salle A',
'type' => 'onduleur',
'brand' => 'APC',
'model' => 'Smart-UPS',
'serial_number' => 'APC-9999',
'status' => 'en_service',
'location' => 'Salle A',
]);
$payload = [
'name' => 'Onduleur Salle A Modifié',
'type' => 'onduleur',
'brand' => 'APC',
'model' => 'Smart-UPS XL',
'serial_number' => 'APC-9999', // Même numéro de série, ne doit pas bloquer
'status' => 'en_panne',
'location' => 'Salle A, Baie 1',
];
$response = $this->actingAs($this->admin)->put(route('materiels.update', $hardware->id), $payload);
$response->assertRedirect(route('materiels.show', $hardware->id));
$this->assertDatabaseHas('hardwares', [
'id' => $hardware->id,
'name' => 'Onduleur Salle A Modifié',
'status' => 'en_panne',
]);
}
public function test_can_delete_hardware()
{
$hardware = Hardware::create([
'name' => 'Poste Sylvain',
'type' => 'poste_travail',
'brand' => 'HP',
'model' => 'EliteBook',
'serial_number' => 'HP-5555',
'status' => 'en_service',
'location' => 'Bureau Sylvain',
]);
$response = $this->actingAs($this->chef)->delete(route('materiels.destroy', $hardware->id));
$response->assertRedirect(route('materiels.index'));
$this->assertDatabaseMissing('hardwares', [
'id' => $hardware->id,
]);
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ProfileTest extends TestCase
{
use RefreshDatabase;
public function test_profile_page_is_displayed(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->get('/profile');
$response->assertOk();
}
public function test_profile_information_can_be_updated(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => 'test@example.com',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$user->refresh();
$this->assertSame('Test User', $user->name);
$this->assertSame('test@example.com', $user->email);
$this->assertNull($user->email_verified_at);
}
public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => $user->email,
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$this->assertNotNull($user->refresh()->email_verified_at);
}
public function test_user_can_delete_their_account(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->delete('/profile', [
'password' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/');
$this->assertGuest();
$this->assertNull($user->fresh());
}
public function test_correct_password_must_be_provided_to_delete_account(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/profile')
->delete('/profile', [
'password' => 'wrong-password',
]);
$response
->assertSessionHasErrors('password')
->assertRedirect('/profile');
$this->assertNotNull($user->fresh());
}
}

10
tests/TestCase.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}