Compare commits
4 Commits
ae39c8dd31
...
0437511bf1
Author | SHA1 | Date |
---|---|---|
|
0437511bf1 | |
|
1328f359b2 | |
|
4997895dfb | |
|
4f1c02acac |
|
@ -20,11 +20,8 @@ class FormConditionResolver extends ConditionResolver
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function filterBlock(array $block): bool
|
public function filterCondition($mode, $ifs): bool
|
||||||
{
|
{
|
||||||
$mode = data_get($block, 'tunes.condition.mode', 'any');
|
|
||||||
$ifs = data_get($block, 'tunes.condition.ifs', []);
|
|
||||||
|
|
||||||
if (count($ifs) === 0) {
|
if (count($ifs) === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ class ConfirmRegistrationMail extends Mailable
|
||||||
$conditionResolver = app(FormConditionResolver::class)->forParticipant($participant);
|
$conditionResolver = app(FormConditionResolver::class)->forParticipant($participant);
|
||||||
$this->fullname = $participant->getFields()->getFullname();
|
$this->fullname = $participant->getFields()->getFullname();
|
||||||
$this->config = $participant->getConfig();
|
$this->config = $participant->getConfig();
|
||||||
$this->topText = $conditionResolver->make($participant->form->mail_top);
|
$this->topText = $conditionResolver->makeBlocks($participant->form->mail_top);
|
||||||
$this->bottomText = $conditionResolver->make($participant->form->mail_bottom);
|
$this->bottomText = $conditionResolver->makeBlocks($participant->form->mail_bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,13 @@ class ConfirmRegistrationMail extends Mailable
|
||||||
*/
|
*/
|
||||||
public function attachments()
|
public function attachments()
|
||||||
{
|
{
|
||||||
|
$conditionResolver = app(FormConditionResolver::class)->forParticipant($this->participant);
|
||||||
|
|
||||||
return $this->participant->form->getMedia('mailattachments')
|
return $this->participant->form->getMedia('mailattachments')
|
||||||
|
->filter(fn ($media) => $conditionResolver->filterCondition(
|
||||||
|
data_get($media->getCustomProperty('conditions'), 'mode', 'all'),
|
||||||
|
data_get($media->getCustomProperty('conditions'), 'ifs', []),
|
||||||
|
))
|
||||||
->map(fn ($media) => Attachment::fromStorageDisk($media->disk, $media->getPathRelativeToRoot()))
|
->map(fn ($media) => Attachment::fromStorageDisk($media->disk, $media->getPathRelativeToRoot()))
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,11 +139,12 @@ class Form extends Model implements HasMedia
|
||||||
public static function booted(): void
|
public static function booted(): void
|
||||||
{
|
{
|
||||||
static::saving(function (self $model) {
|
static::saving(function (self $model) {
|
||||||
if (is_null($model->meta)) {
|
if (is_null(data_get($model->meta, 'active_columns'))) {
|
||||||
$model->setAttribute('meta', [
|
$model->setAttribute('meta', [
|
||||||
'active_columns' => $model->getFields()->count() ? $model->getFields()->take(4)->pluck('key')->toArray() : null,
|
'active_columns' => $model->getFields()->count() ? $model->getFields()->take(4)->pluck('key')->toArray() : null,
|
||||||
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()->key, 'asc'] : null,
|
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()->key, 'asc'] : null,
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array(data_get($model->meta, 'active_columns'))) {
|
if (is_array(data_get($model->meta, 'active_columns'))) {
|
||||||
|
@ -151,6 +152,7 @@ class Form extends Model implements HasMedia
|
||||||
...$model->meta,
|
...$model->meta,
|
||||||
'active_columns' => array_values(array_intersect([...$model->getFields()->pluck('key')->toArray(), 'created_at'], $model->meta['active_columns'])),
|
'active_columns' => array_values(array_intersect([...$model->getFields()->pluck('key')->toArray(), 'created_at'], $model->meta['active_columns'])),
|
||||||
]);
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,27 @@ abstract class ConditionResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $block
|
* @param array<string, mixed> $ifs
|
||||||
*/
|
*/
|
||||||
abstract public function filterBlock(array $block): bool;
|
abstract public function filterCondition(string $mode, array $ifs): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $content
|
* @param array<string, mixed> $content
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public function make(array $content): array
|
public function makeBlocks(array $content): array
|
||||||
{
|
{
|
||||||
return array_filter(data_get($content, 'blocks', []), fn ($block) => $this->filterBlock($block));
|
return array_filter(data_get($content, 'blocks', []), fn ($block) => $this->filterBlock($block));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function filterBlock(array $block): bool
|
||||||
|
{
|
||||||
|
$mode = data_get($block, 'tunes.condition.mode', 'any');
|
||||||
|
$ifs = data_get($block, 'tunes.condition.ifs', []);
|
||||||
|
|
||||||
|
return $this->filterCondition($mode, $ifs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ trait FakesMedia
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withDocument(string $collection, string $filename, string $content = ''): self
|
public function withDocument(string $collection, string $filename, string $content = '', array $properties = []): self
|
||||||
{
|
{
|
||||||
return $this->afterCreating(function (HasMedia $model) use ($filename, $collection, $content) {
|
return $this->afterCreating(function (HasMedia $model) use ($filename, $collection, $content, $properties) {
|
||||||
$pathinfo = pathinfo($filename);
|
$pathinfo = pathinfo($filename);
|
||||||
|
|
||||||
UploadedFile::fake()->create($filename, $content, 'application/pdf')->storeAs('media-library', $filename, 'temp');
|
UploadedFile::fake()->create($filename, $content, 'application/pdf')->storeAs('media-library', $filename, 'temp');
|
||||||
|
@ -32,6 +32,7 @@ trait FakesMedia
|
||||||
$model->addMediaFromDisk('media-library/' . $filename, 'temp')
|
$model->addMediaFromDisk('media-library/' . $filename, 'temp')
|
||||||
->usingName($pathinfo['filename'])
|
->usingName($pathinfo['filename'])
|
||||||
->usingFileName($pathinfo['basename'])
|
->usingFileName($pathinfo['basename'])
|
||||||
|
->withCustomProperties($properties)
|
||||||
->toMediaCollection($collection);
|
->toMediaCollection($collection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
<x-mail-view::editor :content="$topText"></x-mail-view::editor>
|
<x-mail-view::editor :content="$topText"></x-mail-view::editor>
|
||||||
|
|
||||||
|
# Deine Daten
|
||||||
|
|
||||||
@foreach($config->sections as $section)
|
@foreach($config->sections as $section)
|
||||||
## {{$section->name}}
|
## {{$section->name}}
|
||||||
@foreach ($section->fields as $field)
|
@foreach ($section->fields as $field)
|
||||||
|
|
|
@ -214,6 +214,8 @@ class FormRegisterMailTest extends FormTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider blockDataProvider
|
* @dataProvider blockDataProvider
|
||||||
|
* @param array<string, mixed> $conditions
|
||||||
|
* @param array<string, mixed> $participantValues
|
||||||
*/
|
*/
|
||||||
public function testItFiltersForBlockConditions(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void
|
public function testItFiltersForBlockConditions(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void
|
||||||
{
|
{
|
||||||
|
@ -238,4 +240,52 @@ class FormRegisterMailTest extends FormTestCase
|
||||||
$mail->assertDontSeeInText('::content::');
|
$mail->assertDontSeeInText('::content::');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItSendsEmailWhenMailTopIsEmpty(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
|
||||||
|
$participant = Participant::factory()->for(
|
||||||
|
Form::factory()
|
||||||
|
->fields([
|
||||||
|
$this->textField('firstname')->specialType(SpecialType::FIRSTNAME),
|
||||||
|
$this->textField('lastname')->specialType(SpecialType::LASTNAME),
|
||||||
|
])->state(['mail_top' => []])
|
||||||
|
)
|
||||||
|
->data(['firstname' => 'Max', 'lastname' => 'Muster'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$mail = new ConfirmRegistrationMail($participant);
|
||||||
|
$mail->assertSeeInText('Max');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider blockDataProvider
|
||||||
|
* @param array<string, mixed> $conditions
|
||||||
|
* @param array<string, mixed> $participantValues
|
||||||
|
*/
|
||||||
|
public function testItFiltersForAttachments(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
|
||||||
|
$participant = Participant::factory()->for(
|
||||||
|
Form::factory()
|
||||||
|
->fields([
|
||||||
|
$field,
|
||||||
|
$this->textField('firstname')->specialType(SpecialType::FIRSTNAME),
|
||||||
|
$this->textField('lastname')->specialType(SpecialType::LASTNAME),
|
||||||
|
])
|
||||||
|
->withDocument('mailattachments', 'beispiel.pdf', 'content', ['conditions' => $conditions])
|
||||||
|
)
|
||||||
|
->data(['firstname' => 'Max', 'lastname' => 'Muster', ...$participantValues])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$mail = new ConfirmRegistrationMail($participant);
|
||||||
|
$mail->assertSeeInHtml('Daten');
|
||||||
|
if ($result) {
|
||||||
|
$this->assertTrue($mail->hasAttachedData('content', 'beispiel.pdf', ['mime' => 'application/pdf']));
|
||||||
|
} else {
|
||||||
|
$this->assertFalse($mail->hasAttachedData('content', 'beispiel.pdf', ['mime' => 'application/pdf']));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,4 +47,22 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
||||||
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
|
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItUpdatesActiveColumnsWhenFieldsAdded(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$form = Form::factory()
|
||||||
|
->sections([FormtemplateSectionRequest::new()->fields([])])
|
||||||
|
->create();
|
||||||
|
$payload = FormRequest::new()->sections([
|
||||||
|
FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->textField('firstname'),
|
||||||
|
$this->textField('geb'),
|
||||||
|
$this->textField('lastname'),
|
||||||
|
])
|
||||||
|
])->create();
|
||||||
|
|
||||||
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
||||||
|
$this->assertEquals(['firstname', 'geb', 'lastname'], $form->fresh()->meta['active_columns']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue