adrema/tests/Feature/Activity/StoreTest.php

79 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2023-02-15 01:36:59 +01:00
<?php
namespace Tests\Feature\Activity;
use App\Activity;
use App\Subactivity;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class StoreTest extends TestCase
{
use DatabaseTransactions;
public function testItStoresAnActivity(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
2023-02-25 18:00:23 +01:00
$response = $this->post(route('activity.store'), [
2023-02-15 01:36:59 +01:00
'name' => 'Lorem',
2023-03-04 12:51:49 +01:00
'is_filterable' => true,
2023-02-15 01:36:59 +01:00
'subactivities' => [],
]);
$response->assertRedirect('/activity');
$this->assertDatabaseHas('activities', [
'name' => 'Lorem',
2023-03-04 12:51:49 +01:00
'is_filterable' => 1,
2023-02-15 01:36:59 +01:00
'nami_id' => null,
]);
$this->assertDatabaseCount('activity_subactivity', 0);
}
public function testNameIsRequired(): void
{
$this->login()->loginNami();
$response = $this->post(route('activity.store'), []);
$response->assertSessionHasErrors([
'name' => 'Name ist erforderlich.',
'subactivities' => 'Untergliederungen muss vorhanden sein.',
]);
}
public function testNamiIdIsNotSet(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$response = $this->post(route('activity.store'), [
'name' => 'Lorem',
'nami_id' => 556,
2023-03-04 12:51:49 +01:00
'is_filterable' => true,
2023-02-15 01:36:59 +01:00
'subactivities' => [],
]);
$this->assertDatabaseHas('activities', [
'nami_id' => null,
]);
}
public function testItCanStoreASubactivityWithTheActivity(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$subactivity = Subactivity::factory()->create();
$response = $this->from('/activity')->post(route('activity.store'), [
'name' => 'Lorem',
2023-03-04 12:51:49 +01:00
'is_filterable' => true,
2023-02-15 01:36:59 +01:00
'subactivities' => [$subactivity->id],
]);
$this->assertDatabaseCount('activity_subactivity', 1);
$this->assertDatabaseHas('activity_subactivity', [
'activity_id' => Activity::firstWhere('name', 'Lorem')->id,
'subactivity_id' => $subactivity->id,
]);
}
}