Réalisation du tp3, tp4, tp5 et tp6 avec documentation.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CrudTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_client_crud_is_available(): void
|
||||
{
|
||||
$this->get(route('clients.index'))->assertOk();
|
||||
$this->get(route('clients.create'))->assertOk();
|
||||
|
||||
$this->post(route('clients.store'), [
|
||||
'name' => 'Alice Martin',
|
||||
'email' => 'alice@example.com',
|
||||
'city' => 'Paris',
|
||||
])->assertRedirect(route('clients.index'));
|
||||
|
||||
$client = Client::where('email', 'alice@example.com')->firstOrFail();
|
||||
$this->get(route('clients.show', $client))->assertOk()->assertSee('Alice Martin');
|
||||
$this->get(route('clients.edit', $client))->assertOk();
|
||||
|
||||
$this->put(route('clients.update', $client), [
|
||||
'name' => 'Alice Martin',
|
||||
'email' => 'alice@example.com',
|
||||
'city' => 'Lyon',
|
||||
])->assertRedirect(route('clients.index'));
|
||||
$this->assertDatabaseHas('clients', ['id' => $client->id, 'city' => 'Lyon']);
|
||||
|
||||
$this->delete(route('clients.destroy', $client))->assertRedirect(route('clients.index'));
|
||||
$this->assertDatabaseMissing('clients', ['id' => $client->id]);
|
||||
}
|
||||
|
||||
public function test_product_crud_is_available(): void
|
||||
{
|
||||
$this->get(route('products.index'))->assertOk();
|
||||
$this->get(route('products.create'))->assertOk();
|
||||
|
||||
$this->post(route('products.store'), [
|
||||
'name' => 'Casque',
|
||||
'price' => 120,
|
||||
'stock' => 3,
|
||||
])->assertRedirect(route('products.index'));
|
||||
|
||||
$product = Product::where('name', 'Casque')->firstOrFail();
|
||||
$this->get(route('products.show', $product))->assertOk()->assertSee('Casque');
|
||||
$this->get(route('products.edit', $product))->assertOk();
|
||||
|
||||
$this->put(route('products.update', $product), [
|
||||
'name' => 'Casque Bluetooth',
|
||||
'price' => 150,
|
||||
'stock' => 8,
|
||||
])->assertRedirect(route('products.index'));
|
||||
$this->assertDatabaseHas('products', ['id' => $product->id, 'stock' => 8]);
|
||||
|
||||
$this->delete(route('products.destroy', $product))->assertRedirect(route('products.index'));
|
||||
$this->assertDatabaseMissing('products', ['id' => $product->id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user