ldc-wenn-dann-mit-respekt/tests/Feature/Bo/StoresTest.php
2023-07-01 17:29:21 +00:00

138 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature\Bo;
use App\Models\Store;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Support\Str;
class StoresTest extends TestCase
{
// FIXME : Test need to be logged for requesting
/**
* Test CRUD Index is OK
*/
public function test_index_ok(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user, 'backend')->get(\route('bo.stores.index'));
$response->assertStatus(200);
}
/**
* Test CRUD Store is OK
*/
public function test_store_ok(): void
{
$user = User::factory()->create();
$store = Store::factory()->create();
$response = $this->actingAs($user, 'backend')
->post(\route('bo.stores.store'), $store->toArray());
$response->assertRedirect();
$response->assertSessionHas('success');
$response->assertSessionHasNoErrors();
// FIXME : Test DB presence
}
/**
* Test CRUD Store is NOK
*
* @test
* @dataProvider invalidsStores
*/
public function test_store_nok($invalidData, $invalidFields): void
{
$user = User::factory()->create();
$response = $this->actingAs($user, 'backend')
->post(\route('bo.stores.store'), $invalidData);
$response->assertRedirect();
$response->assertSessionHasErrors($invalidFields);
$response->assertInvalid($invalidFields);
}
public function invalidsStores(): array
{
return [
'state.required' => [
['state' => null],
['state']
],
'state.string' => [
['state' => null],
['state']
],
'state.min' => [
['state' => Str::random(2)],
['state']
],
'state.max' => [
['state' => Str::random(256)],
['state']
],
'type_id.required' => [
['type_id' => null],
['type_id']
],
'type_id.exists' => [
['type_id' => 100000000],
['type_id']
],
'street.required' => [
['street' => null],
['street']
],
'street.string' => [
['street' => null],
['street']
],
'street.min' => [
['street' => Str::random(2)],
['street']
],
'street.max' => [
['street' => Str::random(256)],
['street']
],
'zipcode.required' => [
['zipcode' => null],
['zipcode']
],
'zipcode.min' => [
['zipcode' => ''],
['zipcode']
],
'zipcode.max' => [
['zipcode' => Str::random(6)],
['zipcode']
],
'city.required' => [
['city' => null],
['city']
],
'city.string' => [
['city' => null],
['city']
],
'city.min' => [
['city' => Str::random(2)],
['city']
],
'city.max' => [
['city' => Str::random(256)],
['city']
],
];
}
}