Compare commits
No commits in common. "0437511bf105b729c48d204ef80b298bf8b38557" and "ae39c8dd31d3677589654c2de30e406a035e5fea" have entirely different histories.
0437511bf1
...
ae39c8dd31
|
@ -20,8 +20,11 @@ class FormConditionResolver extends ConditionResolver
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function filterCondition($mode, $ifs): bool
|
public function filterBlock(array $block): 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->makeBlocks($participant->form->mail_top);
|
$this->topText = $conditionResolver->make($participant->form->mail_top);
|
||||||
$this->bottomText = $conditionResolver->makeBlocks($participant->form->mail_bottom);
|
$this->bottomText = $conditionResolver->make($participant->form->mail_bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,13 +68,7 @@ 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,12 +139,11 @@ 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(data_get($model->meta, 'active_columns'))) {
|
if (is_null($model->meta)) {
|
||||||
$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'))) {
|
||||||
|
@ -152,7 +151,6 @@ 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,27 +6,16 @@ abstract class ConditionResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $ifs
|
* @param array<string, mixed> $block
|
||||||
*/
|
*/
|
||||||
abstract public function filterCondition(string $mode, array $ifs): bool;
|
abstract public function filterBlock(array $block): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $content
|
* @param array<string, mixed> $content
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public function makeBlocks(array $content): array
|
public function make(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 = '', array $properties = []): self
|
public function withDocument(string $collection, string $filename, string $content = ''): self
|
||||||
{
|
{
|
||||||
return $this->afterCreating(function (HasMedia $model) use ($filename, $collection, $content, $properties) {
|
return $this->afterCreating(function (HasMedia $model) use ($filename, $collection, $content) {
|
||||||
$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,7 +32,6 @@ 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,8 +4,6 @@
|
||||||
|
|
||||||
<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,8 +214,6 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -240,52 +238,4 @@ 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,22 +47,4 @@ 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