adrema/tests/Feature/Form/FormUpdateActionTest.php

168 lines
7.0 KiB
PHP
Raw Permalink Normal View History

2024-02-03 17:51:27 +01:00
<?php
namespace Tests\Feature\Form;
2024-06-29 18:02:23 +02:00
use App\Fileshare\Data\FileshareResourceData;
use App\Form\Data\ExportData;
2024-02-03 17:51:27 +01:00
use App\Form\Models\Form;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2024-07-06 15:08:13 +02:00
use Tests\RequestFactories\EditorRequestFactory;
2024-02-03 17:51:27 +01:00
2024-02-19 01:07:54 +01:00
class FormUpdateActionTest extends FormTestCase
2024-02-03 17:51:27 +01:00
{
use DatabaseTransactions;
public function testItSetsCustomAttributesOfFields(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
2024-07-14 19:29:42 +02:00
$payload = FormRequest::new()->fields([
$this->dateField()->state(['max_today' => true]),
2024-02-03 17:51:27 +01:00
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)
->assertOk();
$form = $form->fresh();
2024-03-07 00:58:14 +01:00
$this->assertTrue($form->config->sections->get(0)->fields->get(0)->maxToday);
2024-02-03 17:51:27 +01:00
}
public function testItSetsRegistrationDates(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$payload = FormRequest::new()->registrationFrom('2023-05-04 01:00:00')->registrationUntil('2023-07-07 01:00:00')->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertOk();
$form = $form->fresh();
$this->assertEquals('2023-05-04 01:00', $form->registration_from->format('Y-m-d H:i'));
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));
}
2024-07-14 19:29:42 +02:00
public function testItSetsTexts(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$payload = FormRequest::new()->fields([])
->mailTop(EditorRequestFactory::new()->text(11, 'lala'))
->mailBottom(EditorRequestFactory::new()->text(12, 'lalab'))
->description(EditorRequestFactory::new()->text(12, 'desc'))
->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)
->assertOk();
$this->assertEquals('lala', $form->fresh()->mail_top->blocks[0]['data']['text']);
$this->assertEquals('lalab', $form->fresh()->mail_bottom->blocks[0]['data']['text']);
$this->assertEquals('desc', $form->fresh()->description->blocks[0]['data']['text']);
}
public function testItClearsFrontendCacheWhenFormUpdated(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->create());
$this->assertFrontendCacheCleared();
}
2024-06-29 18:02:23 +02:00
public function testItUpdatesExport(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc']))->create());
$this->assertEquals(2, $form->fresh()->export->root->connectionId);
}
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
2024-07-14 19:29:42 +02:00
$form = Form::factory()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
])
->create();
2024-07-14 19:29:42 +02:00
$payload = FormRequest::new()->fields([
$this->textField('firstname'),
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
}
2024-04-23 23:12:14 +02:00
2024-06-18 14:54:44 +02:00
public function testItUpdatesIntroOfSections(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()
->sections([FormtemplateSectionRequest::new()->intro('aaa')])
->create();
$payload = FormRequest::new()->sections([
FormtemplateSectionRequest::new()->intro('aaa')
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
$this->assertEquals('aaa', $form->fresh()->config->sections[0]->intro);
}
2024-05-27 18:30:05 +02:00
public function testItUpdatesActiveState(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(false)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertFalse($form->fresh()->is_active);
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(true)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertTrue($form->fresh()->is_active);
}
2024-05-27 18:49:11 +02:00
public function testItUpdatesPrivateState(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(false)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertFalse($form->fresh()->is_private);
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isPrivate(true)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertTrue($form->fresh()->is_private);
}
2024-04-23 23:12:14 +02:00
public function testItUpdatesActiveColumnsWhenFieldsAdded(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()
2024-07-14 19:29:42 +02:00
->fields([])
2024-04-23 23:12:14 +02:00
->create();
2024-07-14 19:29:42 +02:00
$payload = FormRequest::new()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
2024-04-23 23:12:14 +02:00
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
$this->assertEquals(['firstname', 'geb', 'lastname'], $form->fresh()->meta['active_columns']);
}
2024-07-02 22:55:37 +02:00
public function testItUpdatesPrevention(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
2024-07-06 15:08:13 +02:00
$payload = FormRequest::new()
2024-07-08 23:06:45 +02:00
->preventionText(EditorRequestFactory::new()->text(10, 'lorem ipsum'))
2024-07-12 18:05:11 +02:00
->state(['needs_prevention' => true, 'prevention_conditions' => ['mode' => 'all', 'ifs' => [['field' => 'vorname', 'value' => 'Max', 'comparator' => 'isEqual']]]])
2024-07-06 15:08:13 +02:00
->create();
2024-07-02 22:55:37 +02:00
$this->patchJson(route('form.update', ['form' => $form]), $payload);
$this->assertTrue($form->fresh()->needs_prevention);
2024-07-06 15:08:13 +02:00
$this->assertEquals('lorem ipsum', $form->fresh()->prevention_text->blocks[0]['data']['text']);
2024-07-12 18:05:11 +02:00
$this->assertEquals(['mode' => 'all', 'ifs' => [['field' => 'vorname', 'value' => 'Max', 'comparator' => 'isEqual']]], $form->fresh()->prevention_conditions->toArray());
2024-07-02 22:55:37 +02:00
}
2024-02-03 17:51:27 +01:00
}