Wohnung je Baustein wählen und Gitea-Runner-Kompatibilität herstellen
This commit is contained in:
1 parent
3a0bb6e40f
commit
abf0e9004b
8 files changed
+308
-27
No files matched your search
@@ -36,7 +36,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
# act_runner v0.2.11 supports Node 20; newer setup-php releases require Node 24.
|
||||
- uses: shivammathur/setup-php@2.36.0
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, pdo_sqlite, sqlite3, pdo_mysql, fileinfo, openssl
|
||||
@@ -56,7 +57,7 @@ jobs:
|
||||
php artisan key:generate
|
||||
|
||||
- name: Tests (SQLite)
|
||||
run: php artisan test --compact
|
||||
run: php artisan test --compact --testsuite=Feature
|
||||
|
||||
- name: Tests (MariaDB 11.8, wie auf Strato)
|
||||
env:
|
||||
@@ -66,7 +67,7 @@ jobs:
|
||||
DB_DATABASE: fewo_test
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: test
|
||||
run: php artisan test --compact
|
||||
run: php artisan test --compact --testsuite=Feature
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
@@ -75,7 +76,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
# Keep the runtime compatible with the test job and the installed act_runner.
|
||||
- uses: shivammathur/setup-php@2.36.0
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, fileinfo, openssl
|
||||
|
||||
@@ -28,7 +28,7 @@ public static function configure(Schema $schema): Schema
|
||||
->schema([
|
||||
Builder::make('sections')
|
||||
->hiddenLabel()
|
||||
->blocks(fn (): array => app(SectionRegistry::class)->blocks())
|
||||
->blocks(fn (callable $get): array => app(SectionRegistry::class)->blocks($get('site_id')))
|
||||
->addActionLabel('Baustein hinzufügen')
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
|
||||
@@ -3,18 +3,19 @@
|
||||
namespace App\Themes;
|
||||
|
||||
use App\Models\Appearance;
|
||||
use App\Models\Property;
|
||||
use App\Themes\Sections\Section;
|
||||
use Filament\Forms\Components\Builder\Block;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\View as ViewFactory;
|
||||
|
||||
/**
|
||||
* The section catalogue from config/themes.php: builder blocks for the admin and rendering for the website.
|
||||
*
|
||||
* Every placed section carries data.id (a stable UUID, see Page::assignSectionIds) so appearances can
|
||||
* address it, and data.appearances (appearance ids; empty = always shown).
|
||||
* address it, data.appearances (appearance ids; empty = always shown), and an optional data.property_id
|
||||
* (an active property of this website; empty = primary property).
|
||||
*/
|
||||
class SectionRegistry
|
||||
{
|
||||
@@ -38,7 +39,7 @@ public function get(string $key): ?Section
|
||||
/**
|
||||
* @return list<Block>
|
||||
*/
|
||||
public function blocks(): array
|
||||
public function blocks(?int $siteId = null): array
|
||||
{
|
||||
return array_values(array_map(
|
||||
fn (string $class): Block => Block::make($class::key())
|
||||
@@ -47,6 +48,17 @@ public function blocks(): array
|
||||
->schema([
|
||||
Hidden::make('id'),
|
||||
...$class::schema(),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->placeholder('Hauptwohnung')
|
||||
->helperText('Leer = Hauptwohnung dieser Website.')
|
||||
->options(fn (): array => Property::query()
|
||||
->where('site_id', $siteId)
|
||||
->whereNotNull('site_id')
|
||||
->where('is_active', true)
|
||||
->orderBy('name')
|
||||
->pluck('name', 'id')
|
||||
->all()),
|
||||
Select::make('appearances')
|
||||
->label('Nur anzeigen im Erscheinungsbild')
|
||||
->helperText('Leer = immer anzeigen. Z. B. ein Weihnachts-Baustein nur im Erscheinungsbild „Weihnachten“.')
|
||||
@@ -70,11 +82,11 @@ public function isVisible(Theme $theme, array $data): bool
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the stored sections of a page; unknown or failing types are skipped (and reported),
|
||||
* so a page never breaks because of one section.
|
||||
* Prepares the stored sections for deferred rendering. Unknown types, missing views, hidden sections
|
||||
* and unavailable property assignments are skipped.
|
||||
*
|
||||
* @param list<array{type: string, data?: array<string, mixed>}>|null $sections
|
||||
* @return list<View>
|
||||
* @return list<SectionView>
|
||||
*/
|
||||
public function render(Theme $theme, ?array $sections): array
|
||||
{
|
||||
@@ -85,11 +97,24 @@ public function render(Theme $theme, ?array $sections): array
|
||||
continue;
|
||||
}
|
||||
|
||||
$views[] = ViewFactory::make($section->view(), [
|
||||
...$section->data($theme, $stored['data'] ?? []),
|
||||
'theme' => $theme,
|
||||
'sectionId' => $section::key().'-'.$index,
|
||||
]);
|
||||
$data = $stored['data'] ?? [];
|
||||
$property = filled($data['property_id'] ?? null)
|
||||
? $theme->site->properties()->where('is_active', true)->whereKey($data['property_id'])->first()
|
||||
: $theme->property();
|
||||
|
||||
if (filled($data['property_id'] ?? null) && $property === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$views[] = $theme->runForProperty($property, fn (): SectionView => new SectionView(
|
||||
$theme,
|
||||
$property,
|
||||
ViewFactory::make($section->view(), [
|
||||
...$section->data($theme, $data),
|
||||
'theme' => $theme,
|
||||
'sectionId' => $section::key().'-'.$index,
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
||||
return $views;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Themes;
|
||||
|
||||
use App\Models\Property;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
/**
|
||||
* Keeps the section's property active when the page eventually renders its Blade view and partials.
|
||||
*/
|
||||
class SectionView implements Renderable
|
||||
{
|
||||
public function __construct(
|
||||
private Theme $theme,
|
||||
private ?Property $property,
|
||||
private View $view,
|
||||
) {}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return $this->theme->runForProperty($this->property, fn (): string => $this->view->render());
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,29 @@ public function property(): ?Property
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a section with its property, restoring the previous cache even when rendering fails.
|
||||
*
|
||||
* @template T
|
||||
*
|
||||
* @param callable(): T $callback
|
||||
* @return T
|
||||
*/
|
||||
public function runForProperty(?Property $property, callable $callback): mixed
|
||||
{
|
||||
$previousProperty = $this->property;
|
||||
$previousResolved = $this->propertyResolved;
|
||||
$this->property = $property;
|
||||
$this->propertyResolved = true;
|
||||
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
$this->property = $previousProperty;
|
||||
$this->propertyResolved = $previousResolved;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Published pages of a menu location ("main" or "footer").
|
||||
*
|
||||
|
||||
@@ -78,6 +78,7 @@ ## 4. Tägliche Nutzung
|
||||
## 5. Automatisch über Gitea Actions
|
||||
|
||||
- Workflow `.gitea/workflows/deploy.yml`: **Tests bei jedem Push**; **Deployment** bei Tags `v*` (z. B. `git tag v1.0.0 && git push --tags`) oder per Knopfdruck (Actions › Deploy › Run workflow, Ziel production/staging).
|
||||
- Runner-Kompatibilität (26.10.2026): Der vorhandene `act_runner v0.2.11` unterstützt Actions bis Node 20. `setup-php` ist deshalb in beiden Jobs auf `2.36.0` (Node 20) festgelegt; das bewegliche `@v2` benötigt inzwischen Node 24 und bricht vor den Tests ab. Erst nach einem Runner-Upgrade wieder anheben. Beide Datenbank-Testläufe wählen ausdrücklich `--testsuite=Feature`, weil `tests/Unit` nicht existiert.
|
||||
- Voraussetzung: Gitea Actions aktiviert und ein **act_runner** registriert – passt gut auf den privaten Server (Docker). Anleitung: Gitea-Doku „Act Runner“.
|
||||
- Repository-Secrets: `DEPLOY_SSH_KEY` (privater Schlüssel, dessen öffentlicher Teil bei Strato hinterlegt ist), `DEPLOY_HOST`, `DEPLOY_USER`, `DEPLOY_PATH`, `DEPLOY_PHP`, `DEPLOY_URL`.
|
||||
|
||||
|
||||
+13
-11
@@ -1,6 +1,6 @@
|
||||
# Projektstand
|
||||
|
||||
Stand: 26.10.2026 · ausgelieferter Stand: `deploy/staging/20261026065920` · 272 Feature-Tests grün
|
||||
Stand: 26.10.2026 · ausgelieferter Stand: `deploy/staging/20261026065920` · lokal Phase-7-Kern auf `feature/section-properties`: 285 Feature-Tests grün
|
||||
|
||||
> Dieses Dokument ist der Einstieg für jede neue Arbeitssitzung. Bitte bei größeren Änderungen fortschreiben (Abschnitte „Fertig“, „Offen“, „Nächste Schritte“).
|
||||
|
||||
@@ -70,7 +70,7 @@ ## 3. Offen
|
||||
**Technik**
|
||||
- Cronjob auf Strato einrichten (BETRIEB.md §6).
|
||||
- Design-Theme Seebad 0.3 ist auf `main` und auf stommer.info aktiv (Abschnitt 6).
|
||||
- Mandantenfähigkeit: **Phasen 1 bis 5 sind umgesetzt** – der Grundumbau ist fertig. Stand, Bausteine und Fallen stehen in Abschnitt 7. Plan: `docs/MANDANTEN-PLAN.md`.
|
||||
- Mandantenfähigkeit: **Phasen 1 bis 5 und die Anwendungsseite von Phase 6 sind ausgeliefert**. Der Kern von Phase 7 ist lokal auf `feature/section-properties` umgesetzt, noch nicht ausgeliefert. Stand, Bausteine und Fallen stehen in Abschnitt 7. Plan: `docs/MANDANTEN-PLAN.md`.
|
||||
- Logo in E-Mails und im Vertrags-PDF (`public/brand/logo-600.png` liegt bereit).
|
||||
- Content-Security-Policy: braucht wegen Livewire/Filament Nonces und einen sorgfältigen Test.
|
||||
- Produktion `www.fewo-stommer.de` vorbereiten:
|
||||
@@ -135,25 +135,27 @@ ## 6. Design-Theme „Seebad“ (Abschnitt der Design-Session)
|
||||
|
||||
## 7. Mandanten – Übergabe an die nächste Sitzung
|
||||
|
||||
Stand: 26.10.2026 · Branch `main` · Plan: [MANDANTEN-PLAN.md](MANDANTEN-PLAN.md) · Anforderungen: [MANDANTEN-ANFORDERUNGEN.md](MANDANTEN-ANFORDERUNGEN.md)
|
||||
Stand: 26.10.2026 · Phase 7 lokal auf `feature/section-properties` · Plan: [MANDANTEN-PLAN.md](MANDANTEN-PLAN.md) · Anforderungen: [MANDANTEN-ANFORDERUNGEN.md](MANDANTEN-ANFORDERUNGEN.md)
|
||||
|
||||
> **Server und `main` sind gleich.** Ausgeliefert ist `20261026065920` – Phasen 1–5 und die Anwendungsseite von Phase 6. Vor jedem Deploy sichern: `bash scripts/backup-pull.sh staging /c/Dev/fewo-backups/staging`, dann `bash scripts/deploy.sh staging deploy`.
|
||||
> **Server unverändert:** Ausgeliefert ist `20261026065920` – Phasen 1–5 und die Anwendungsseite von Phase 6. Phase 7 ist noch nicht zusammengeführt oder ausgeliefert. Vor jedem Deploy sichern: `bash scripts/backup-pull.sh staging /c/Dev/fewo-backups/staging`, dann `bash scripts/deploy.sh staging deploy` (nur aus aktuellem `main`).
|
||||
|
||||
**Der Grundumbau (Phasen 1–5) ist fertig.** Von Phase 6 ist die **Anwendungsseite gebaut** (Bildwelten, Marke je Website) – ohne eine einzige Theme-Datei zu ändern; der Rest ist ein Vertragsfall und steht als Aufgabe für die Theme-Sitzung in ZUSAMMENARBEIT.md §6: Favicon und die fest verdrahteten Grafiken in `ostsee-licht` auf `$theme->brand()` bzw. Plätze umstellen. Offen bleibt Phase 7 (mehrere Wohnungen je Website). Nicht im Plan und offen: Subscription/Abrechnung und die Zertifikatsfrage bei Strato.
|
||||
**Der Grundumbau (Phasen 1–5) ist fertig.** Von Phase 6 ist die **Anwendungsseite gebaut** (Bildwelten, Marke je Website) – ohne eine einzige Theme-Datei zu ändern; der Rest ist ein Vertragsfall und steht als Aufgabe für die Theme-Sitzung in ZUSAMMENARBEIT.md §6: Favicon und die fest verdrahteten Grafiken in `ostsee-licht` auf `$theme->brand()` bzw. Plätze umstellen. Der Kern von Phase 7 ist jetzt lokal umgesetzt. Nicht im Plan und offen: Subscription/Abrechnung und die Zertifikatsfrage bei Strato.
|
||||
|
||||
### Hier weitermachen: Phase 7
|
||||
### Phase 7: Kern umgesetzt, noch nicht ausgeliefert
|
||||
|
||||
Ziel (A21): Ein Baustein kann eine Wohnung **dieser Website** wählen; ohne Wahl gilt wie heute die Hauptwohnung. Voraussetzung für die Bergwohnung unter `fewo-stommer.de`.
|
||||
|
||||
**Der Kern braucht keine Theme-Änderung.** Bestehende Vorlagen rufen `$theme->property()`; wenn der Renderer vor dem Baustein die gewählte Wohnung setzt, bleiben sie unverändert gültig. Ein Eintrag in [ZUSAMMENARBEIT.md](ZUSAMMENARBEIT.md) §6 wird erst fällig, wenn **neue** Bausteine dazukommen (Übersicht aller Wohnungen, Suche über mehrere) – die brauchen eine Pflicht-Vorlage im Basis-Theme.
|
||||
**Ohne Theme-Änderung umgesetzt.** Alle Bausteine haben im Seiten-Baukasten das gemeinsame Feld „Wohnung“ (`data.property_id`). Die Auswahl und ihre Validierung erlauben nur aktive Wohnungen der Website der bearbeiteten Seite. Leer bleibt die Hauptwohnung. Ein Eintrag in [ZUSAMMENARBEIT.md](ZUSAMMENARBEIT.md) §6 wird erst fällig, wenn **neue** Bausteine dazukommen (Übersicht aller Wohnungen, Suche über mehrere) – diese gehören nicht zum Kern und brauchen eine Pflicht-Vorlage im Basis-Theme.
|
||||
|
||||
Anzufassen wären vermutlich:
|
||||
Die Umsetzung:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| `app/Themes/Theme.php` | `property()` merkt sich die Wohnung (`$this->property`, `$this->propertyResolved`). Für Phase 7 braucht es einen Weg, sie je Baustein zu setzen und danach zurückzusetzen – am ehesten ein `runForProperty(Property $p, Closure $c)` nach dem Vorbild von `TenantContext::run()`. **Achtung:** eine solche Methode gibt es heute nicht – ein Test, der sie voraussetzt, schlägt fehl. |
|
||||
| `app/Themes/Sections/*` | Gemeinsames Feld „Wohnung" im Admin-Formular der Bausteine, leer = Hauptwohnung. |
|
||||
| Seiten-Renderer | Setzt die Wohnung, bevor der Baustein läuft. |
|
||||
| `app/Themes/Theme.php` | `runForProperty(?Property, callable)` setzt die Wohnung für einen Callback und stellt im `finally` beide bisherigen Cache-Werte wieder her, auch bei Verschachtelung oder Fehlern. |
|
||||
| `app/Themes/SectionRegistry.php`, `PageForm` | Gemeinsames Auswahlfeld für jeden Baustein. Der Renderer prüft Website-Zugehörigkeit und Aktivität erneut; fremde, inaktive oder gelöschte Zuordnungen werden übersprungen, ohne auf eine andere Wohnung umzulenken. |
|
||||
| `app/Themes/SectionView.php` | Die Ausgabe bleibt verzögert (`render()` wie bisher). Auch während Blade, Partials und Livewire laufen, ist die gewählte Wohnung aktiv; das gilt ebenso für die Bildwelt über den Theme-Kontext. Danach gilt wieder der vorherige Zustand. |
|
||||
|
||||
Tests: `tests/Feature/SectionPropertyTest.php` prüft in 13 Fällen gemischte Wohnungen auf einer Seite, Hauptwohnungs-Fallback, das Buchungsformular, verzögerte Ausgabe, verschachtelte Kontexte und Fehler sowie Speichern und Ablehnen im Admin über Website- und Mandantengrenzen. Gesamte Feature-Suite: **285 Tests, 1289 Assertions grün**; Pint ausgeführt. Keine neue Tabelle, Migration oder Abhängigkeit. Nächster Schritt: Änderungen prüfen und nach Zusammenführung in aktuelles `main` mit vorheriger Sicherung ausliefern.
|
||||
|
||||
**Nicht vergessen:** Jede neue Tabelle bekommt `tenant_id` von Anfang an und gehört in `TenantArchive::DELETE_ORDER`, sonst überlebt sie die Kündigung ihres Mandanten. `tests/Feature/TenantSeparationTest.php` merkt das – aber nur, wenn der Testaufbau dort die neue Tabelle auch füllt.
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\Page;
|
||||
use App\Models\Property;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Tenancy\TenantContext;
|
||||
use App\Themes\SectionRegistry;
|
||||
use App\Themes\Theme;
|
||||
use App\Themes\ThemeFactory;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Livewire\Livewire;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SectionPropertyTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_sections_use_the_selected_property_and_return_to_the_primary_property(): void
|
||||
{
|
||||
$this->withoutVite();
|
||||
$site = Site::factory()->create(['domain' => 'wohnungen.test', 'is_default' => true]);
|
||||
Property::factory()->for($site)->create(['name' => 'Hauptwohnung', 'size_sqm' => 53]);
|
||||
$second = Property::factory()->for($site)->create(['name' => 'Bergwohnung', 'size_sqm' => 87]);
|
||||
Page::factory()->for($site)->create([
|
||||
'slug' => Page::HOME,
|
||||
'sections' => [
|
||||
['type' => 'facts', 'data' => ['heading' => 'Erste Wohnung']],
|
||||
['type' => 'facts', 'data' => ['heading' => 'Zweite Wohnung', 'property_id' => (string) $second->id]],
|
||||
['type' => 'facts', 'data' => ['heading' => 'Wieder Hauptwohnung', 'property_id' => null]],
|
||||
['type' => 'booking', 'data' => ['property_id' => $second->id]],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->get('http://wohnungen.test/')
|
||||
->assertOk()
|
||||
->assertSeeInOrder(['Erste Wohnung', '53 m²', 'Zweite Wohnung', '87 m²', 'Wieder Hauptwohnung', '53 m²'])
|
||||
->assertSee('"propertyId":'.$second->id, false);
|
||||
|
||||
$this->assertSame('Hauptwohnung', app(Theme::class)->property()->name);
|
||||
}
|
||||
|
||||
public function test_deferred_views_and_partials_see_the_selected_theme_property(): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
$primary = Property::factory()->for($site)->create(['name' => 'Hauptwohnung']);
|
||||
$second = Property::factory()->for($site)->create(['name' => 'Bergwohnung']);
|
||||
$theme = app(ThemeFactory::class)->forSite($site)->activate();
|
||||
app()->instance(Theme::class, $theme);
|
||||
View::composer('theme::sections.facts', function ($view): void {
|
||||
$view->with('heading', $view->getData()['theme']->property()->name.' / '.app(Theme::class)->property()->name);
|
||||
});
|
||||
|
||||
$sections = app(SectionRegistry::class)->render($theme, [
|
||||
['type' => 'facts', 'data' => ['property_id' => $second->id]],
|
||||
['type' => 'facts', 'data' => []],
|
||||
]);
|
||||
|
||||
$this->assertSame($primary->id, $theme->property()->id);
|
||||
$this->assertStringContainsString('Bergwohnung / Bergwohnung', $sections[0]->render());
|
||||
$this->assertStringContainsString('Hauptwohnung / Hauptwohnung', $sections[1]->render());
|
||||
$this->assertSame($primary->id, $theme->property()->id);
|
||||
}
|
||||
|
||||
public function test_nested_property_contexts_restore_the_unresolved_primary_cache_after_an_exception(): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
$primary = Property::factory()->for($site)->create();
|
||||
$second = Property::factory()->for($site)->create();
|
||||
$theme = app(ThemeFactory::class)->forSite($site);
|
||||
|
||||
try {
|
||||
$theme->runForProperty($second, function () use ($theme, $primary, $second): void {
|
||||
$this->assertSame($second->id, $theme->property()->id);
|
||||
$theme->runForProperty($primary, function () use ($theme, $primary): void {
|
||||
$this->assertSame($primary->id, $theme->property()->id);
|
||||
});
|
||||
$this->assertSame($second->id, $theme->property()->id);
|
||||
|
||||
throw new RuntimeException('Abbruch');
|
||||
});
|
||||
$this->fail('The callback must throw.');
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->assertSame('Abbruch', $exception->getMessage());
|
||||
}
|
||||
|
||||
$primary->update(['is_active' => false]);
|
||||
$this->assertSame($second->id, $theme->property()->id);
|
||||
}
|
||||
|
||||
public function test_a_failing_deferred_view_restores_the_primary_property(): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
$primary = Property::factory()->for($site)->create();
|
||||
$second = Property::factory()->for($site)->create();
|
||||
$theme = app(ThemeFactory::class)->forSite($site)->activate();
|
||||
$sections = app(SectionRegistry::class)->render($theme, [
|
||||
['type' => 'facts', 'data' => ['property_id' => $second->id]],
|
||||
]);
|
||||
View::composer('theme::sections.facts', function () use ($theme, $second): void {
|
||||
$this->assertSame($second->id, $theme->property()->id);
|
||||
|
||||
throw new RuntimeException('Vorlage abgebrochen');
|
||||
});
|
||||
|
||||
try {
|
||||
$sections[0]->render();
|
||||
$this->fail('The view must throw.');
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->assertSame('Vorlage abgebrochen', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame($primary->id, $theme->property()->id);
|
||||
}
|
||||
|
||||
/** @return array<string, array{string}> */
|
||||
public static function invalidPropertyProvider(): array
|
||||
{
|
||||
return [
|
||||
'other website of same tenant' => ['other_site'],
|
||||
'other tenant' => ['other_tenant'],
|
||||
'inactive property' => ['inactive'],
|
||||
'deleted property' => ['deleted'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('invalidPropertyProvider')]
|
||||
public function test_invalid_property_assignments_are_skipped(string $kind): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
Property::factory()->for($site)->create();
|
||||
$otherSite = Site::factory()->create(['tenant_id' => $site->tenant_id]);
|
||||
$property = match ($kind) {
|
||||
'other_site' => Property::factory()->for($otherSite)->create(),
|
||||
'other_tenant' => Property::factory()->for(Site::factory())->create(),
|
||||
default => Property::factory()->for($site)->create(['is_active' => false]),
|
||||
};
|
||||
if ($kind === 'deleted') {
|
||||
$property->delete();
|
||||
}
|
||||
app(TenantContext::class)->set($site->tenant);
|
||||
$theme = app(ThemeFactory::class)->forSite($site)->activate();
|
||||
|
||||
$sections = app(SectionRegistry::class)->render($theme, [
|
||||
['type' => 'facts', 'data' => ['property_id' => $property->id]],
|
||||
['type' => 'facts', 'data' => ['heading' => 'Hauptwohnung bleibt sichtbar']],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $sections);
|
||||
$this->assertStringContainsString('Hauptwohnung bleibt sichtbar', $sections[0]->render());
|
||||
}
|
||||
|
||||
public function test_editor_saves_a_property_of_the_pages_website(): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
$property = Property::factory()->for($site)->create();
|
||||
$page = Page::factory()->for($site)->create();
|
||||
$user = User::factory()->role(UserRole::Content)->create();
|
||||
$user->tenants()->syncWithoutDetaching([$site->tenant_id => ['role' => UserRole::Content->value]]);
|
||||
app(TenantContext::class)->set($site->tenant);
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(EditPage::class, ['record' => $page->getRouteKey()])
|
||||
->fillForm(['sections' => [['type' => 'facts', 'data' => ['property_id' => $property->id]]]])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$this->assertSame($property->id, (int) $page->fresh()->sections[0]['data']['property_id']);
|
||||
}
|
||||
|
||||
#[DataProvider('invalidPropertyProvider')]
|
||||
public function test_editor_rejects_properties_outside_the_available_selection(string $kind): void
|
||||
{
|
||||
$site = Site::factory()->create();
|
||||
$page = Page::factory()->for($site)->create(['sections' => []]);
|
||||
$otherSite = Site::factory()->create(['tenant_id' => $site->tenant_id]);
|
||||
$property = match ($kind) {
|
||||
'other_site' => Property::factory()->for($otherSite)->create(),
|
||||
'other_tenant' => Property::factory()->for(Site::factory())->create(),
|
||||
default => Property::factory()->for($site)->create(['is_active' => false]),
|
||||
};
|
||||
if ($kind === 'deleted') {
|
||||
$property->delete();
|
||||
}
|
||||
$user = User::factory()->role(UserRole::Content)->create();
|
||||
$user->tenants()->syncWithoutDetaching([$site->tenant_id => ['role' => UserRole::Content->value]]);
|
||||
app(TenantContext::class)->set($site->tenant);
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(EditPage::class, ['record' => $page->getRouteKey()])
|
||||
->fillForm(['sections' => [['type' => 'facts', 'data' => ['property_id' => $property->id]]]])
|
||||
->call('save')
|
||||
->assertHasFormErrors();
|
||||
|
||||
$this->assertSame([], $page->fresh()->sections);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user