$style * @return array */ private function section(array $style, string $text = 'Inhalt'): array { return ['layout' => 'u4', 'style' => $style, 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]]]]; } /** * @param array $style */ private function publish(string $path, array $style): Page { $page = Page::query()->create(['path' => $path]); $service = app(PageService::class); $service->publish($page, $service->saveRevision($page, [$this->section($style)], null, null, null)); return $page->fresh(); } private function sectionTag(string $html): string { preg_match('/
]*object-position: 0% 0%#', $html); } public function test_no_class_is_added_without_a_surface_or_with_the_full_content_width(): void { $page = $this->publish('/ohne-flaeche', ['background' => 'default', 'background_width' => 'section']); $this->assertStringNotContainsString('section-bg-width-section', $this->get('/ohne-flaeche')->getContent()); $this->assertArrayNotHasKey('background_width', $page->latestRevision->sections[0]['style'], 'Ohne Fläche gibt es nichts zu begrenzen.'); $this->publish('/vollbreit', ['background' => 'dark', 'background_width' => 'section', 'width' => 'full']); $this->assertStringNotContainsString('section-bg-width-section', $this->get('/vollbreit')->getContent(), 'Bei Vollbreite gibt es keinen Unterschied.'); } public function test_an_unknown_background_width_is_refused(): void { $this->expectException(ValidationException::class); app(PageSections::class)->normalize([$this->section(['background' => 'light', 'background_width' => 'schmal'])]); } // --------------------------------------------------------------------------------------------------------------- // Editor // --------------------------------------------------------------------------------------------------------------- public function test_the_editor_saves_a_palette_colour_and_the_background_width_and_an_untouched_page_stays_unchanged(): void { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); $page = Page::query()->create(['path' => '/editor']); app(PageService::class)->saveRevision($page, [$this->section(['background' => 'light'])], null, null, null); $revisions = $page->revisions()->count(); $component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]); $key = array_key_first($component->get('data.sections')); $component->assertSet("data.sections.{$key}.style.background", 'light')->assertSet("data.sections.{$key}.style.palette_slot", null); $component->call('save')->assertHasNoFormErrors(); $this->assertSame($revisions, $page->revisions()->count(), 'Speichern ohne Änderung legt keine Revision an.'); $key = array_key_first($component->get('data.sections')); $component->set("data.sections.{$key}.style.palette_slot", 'c2')->set("data.sections.{$key}.style.background", 'palette') ->set("data.sections.{$key}.style.background_width", 'section')->call('save')->assertHasNoFormErrors(); $style = $page->fresh()->latestRevision->sections[0]['style']; $this->assertSame(['palette', 'c2', 'section'], [$style['background'], $style['palette_slot'], $style['background_width']]); $key = array_key_first($component->get('data.sections')); $component->set("data.sections.{$key}.style.background", 'light')->set("data.sections.{$key}.style.palette_slot", null) ->set("data.sections.{$key}.style.background_width", 'full')->call('save')->assertHasNoFormErrors(); $style = $page->fresh()->latestRevision->sections[0]['style']; $this->assertArrayNotHasKey('palette_slot', $style, 'Der Verweis verschwindet mit der Palettenfarbe.'); $this->assertArrayNotHasKey('background_width', $style); } public function test_the_editor_offers_the_palette_colours_as_tiles_to_an_editor_without_access_to_the_palette(): void { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); $page = Page::query()->create(['path' => '/auswahl']); app(PageService::class)->saveRevision($page, [$this->section([])], null, null, null); $html = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id])->html(); $this->assertStringContainsString('luf-flaeche', $html); $this->assertStringContainsString('Dunkelblau', $html); $this->assertStringContainsString('Helles Grün', $html); $this->assertStringContainsString('Hintergrundbild', $html); $this->assertStringContainsString('Die Farbpalette pflegt die Systemverwaltung', $html); $this->assertStringNotContainsString('Farbpalette verwalten', $html); } }