travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed([PropertySeeder::class, SiteSeeder::class]); $this->property = Property::sole(); $this->property->update(['contract_data' => ['wlan_passwort' => 'geheim&<1>']]); Mail::fake(); Storage::fake('local'); $this->withoutVite(); } public function test_placeholders_are_filled_escaped_and_unknown_ones_stay_visible(): void { $booking = $this->booking(); $html = '
{{ mieter }} reist {{ anreise_datum }} an, {{ naechte }} Nächte, {{ wohnung.wlan_passwort }} {{ gibtsnicht }}
'; $out = ContractPlaceholders::render($html, $booking, ['wlan_passwort' => 'geheim&<1>']); $this->assertStringContainsString($booking->guest->full_name, $out); $this->assertStringContainsString('07.11.2026 an, 3 Nächte', $out); $this->assertStringContainsString('geheim&<1>', $out); $this->assertStringContainsString('[gibtsnicht?]', $out); $this->assertSame(['gibtsnicht'], ContractPlaceholders::missing($html, $booking, ['wlan_passwort' => 'x'])); } public function test_offer_with_a_document_template_freezes_body_and_property_facts_and_renders_the_contract(): void { $template = $this->template('Direkt', 'Mieter {{ mieter }}, WLAN {{ wohnung.wlan_passwort }}
', 'Anlage Haus', 'Anlagentext {{ buchungsnummer }}
'); $offer = $this->offer(['contract_template_id' => $template->id]); $this->assertSame($template->body, $offer->offer_terms['document']['body']); $this->assertSame('geheim&<1>', $offer->offer_terms['property_data']['wlan_passwort']); $document = OfferTerms::document($offer); $this->assertStringContainsString($offer->guest->full_name, $document['body']); $this->assertStringContainsString($offer->reference, $document['annex']); $this->get(app(SendOffer::class)->offerUrl($offer))->assertOk()->assertSee('Mietvertrag')->assertSee('Anlage Haus')->assertSee($offer->guest->full_name); Storage::disk('local')->assertExists($offer->offer_path); // later changes of the template or the property facts do not touch the sent offer $template->update(['body' => 'GEÄNDERT
']); $this->property->update(['contract_data' => ['wlan_passwort' => 'neu']]); $this->assertStringContainsString($offer->guest->full_name, OfferTerms::document($offer->fresh())['body']); $this->assertStringNotContainsString('GEÄNDERT', OfferTerms::document($offer->fresh())['body']); } public function test_template_without_a_body_keeps_the_text_blocks(): void { $template = $this->template('Bausteine', null, null, null); $template->fill(['texts' => ['terms' => 'NUR BAUSTEIN
']])->applyStatements(released: true, portalTerms: false, actor: 'Test'); $template->save(); $offer = $this->offer(['contract_template_id' => $template->id]); $this->assertNull(OfferTerms::document($offer)); $this->assertStringContainsString('NUR BAUSTEIN', $offer->offerText('contract.terms')); } public function test_portal_reservation_uses_the_reservation_template_and_a_confirmation_without_payment_instructions(): void { $inquiry = $this->template('Anfrage', 'ANFRAGE-VERTRAG
', null, null); $reservation = $this->template('FeWo-direkt', 'PORTAL-VERTRAG {{ mieter }}
', null, null); $portal = Channel::factory()->for($this->property)->create([ 'booking_model' => 'portal_booking', 'process_overrides' => ['inquiry' => ['contract_template_id' => $inquiry->id], 'booking' => ['contract_template_id' => $reservation->id, 'payments' => 'portal']], ]); $booking = $this->booking(['import_channel_id' => $portal->id, 'source' => 'portal']); app(ConfirmBooking::class)->handle($booking, notifyGuest: true); $booking = $booking->fresh(); $this->assertSame(BookingStatus::Confirmed, $booking->status); $this->assertSame('FeWo-direkt', $booking->offer_terms['template']['name']); $this->assertStringContainsString('PORTAL-VERTRAG', OfferTerms::document($booking)['body']); Storage::disk('local')->assertExists($booking->contract_path); // Binding on the portal: booking documentation without payment instructions (payments run via the portal). Mail::assertSent(BookingDocumentation::class, fn (BookingDocumentation $mail): bool => ! str_contains($mail->render(), 'überweisen') && str_contains($mail->render(), 'Die Zahlung läuft über')); Mail::assertNotSent(BookingConfirmed::class); $inquiryPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'inquiry', 'process_overrides' => ['inquiry' => ['contract_template_id' => $inquiry->id], 'booking' => ['contract_template_id' => $reservation->id]]]); $this->assertSame($inquiry->id, OfferTerms::templateFor($this->booking(['import_channel_id' => $inquiryPortal->id, 'source' => 'portal', 'arrival' => '2026-12-01', 'departure' => '2026-12-03']))->id); } public function test_installer_creates_the_fewo_direkt_template_once_and_sets_property_facts_without_storing_them_in_code(): void { $this->artisan('contracts:install-fewo-direkt', ['--data' => ['wlan_benutzer=Gast1', 'kellercode=1234']])->assertSuccessful(); $this->artisan('contracts:install-fewo-direkt')->assertSuccessful(); $template = ContractTemplate::query()->where('name', 'FeWo-direkt Direktbuchung')->sole(); $this->assertTrue($template->hasDocument()); $this->assertStringContainsString('{{ wohnung.kellercode }}', $template->body); $this->assertStringNotContainsString('0050', $template->body.$template->annex_body); $this->assertStringNotContainsString('ostseeurlaub', $template->body.$template->annex_body); $data = $this->property->fresh()->contract_data; $this->assertSame('1234', $data['kellercode']); $this->assertSame('geheim&<1>', $data['wlan_passwort']); } private function template(string $name, ?string $body, ?string $annexTitle, ?string $annexBody): ContractTemplate { return ContractTemplate::query()->create(['released_at' => now(), 'name' => $name, 'version' => 1, 'body' => $body, 'annex_title' => $annexTitle, 'annex_body' => $annexBody]); } /** * @param array