null]); $first = Tenant::factory()->create([ 'bank_iban' => 'DE02120300000000202051', 'operating_mode' => Settings::MODE_LIVE, 'owner_name' => 'Brigitte Beispiel', ]); $second = Tenant::factory()->create([ 'bank_iban' => 'DE02500105170137075030', 'operating_mode' => Settings::MODE_TEST, 'test_recipient' => 'test@zweiter.example', 'owner_name' => 'Zweiter Vermieter', ]); $context = app(TenantContext::class); $context->set($first); Content::save(['legal.imprint' => 'Impressum des ersten Vermieters']); $this->assertSame('Impressum des ersten Vermieters', Content::get('legal.imprint')); $this->assertSame('DE02120300000000202051', config('fewo.bank.iban')); $this->assertSame('Brigitte Beispiel', config('fewo.owner.name')); $this->assertTrue(Settings::isLive()); $this->assertNull(Settings::mailRedirect()); $context->set($second); $this->assertNull(Content::get('legal.imprint')); Content::save(['legal.imprint' => 'Impressum des zweiten Vermieters']); $this->assertSame('DE02500105170137075030', config('fewo.bank.iban')); $this->assertSame('Zweiter Vermieter', config('fewo.owner.name')); $this->assertFalse(Settings::isLive()); $this->assertSame('test@zweiter.example', Settings::mailRedirect()); $context->set($first); $this->assertSame('Impressum des ersten Vermieters', Content::get('legal.imprint')); } public function test_without_a_landlord_the_configuration_of_the_installation_applies(): void { config(['fewo.owner.name' => 'Aus der Konfiguration']); $first = Tenant::factory()->create(['owner_name' => 'Brigitte Beispiel']); Tenant::factory()->create(); $context = app(TenantContext::class); $context->set($first); $this->assertSame('Brigitte Beispiel', config('fewo.owner.name')); $context->forget(); $this->assertSame('Aus der Konfiguration', config('fewo.owner.name')); $this->assertNull(Settings::tenant()); } public function test_only_services_the_application_really_asks_about_are_offered(): void { $this->assertSame( [TenantServiceKey::PortalSync, TenantServiceKey::PortalMail], TenantServiceKey::wired(), ); foreach (TenantServiceKey::cases() as $service) { if (! $service->isWired()) { $this->assertFalse($service->enabledByDefault(), $service->value.' darf nicht vorgegeben an sein, solange nichts danach fragt.'); } } } public function test_a_landlord_without_a_decision_keeps_the_portal_services(): void { $tenant = Tenant::factory()->create(); $this->assertSame(0, $tenant->services()->count()); $this->assertTrue(app(TenantFeatures::class)->enabled(TenantServiceKey::PortalSync, $tenant)); $this->assertFalse(app(TenantFeatures::class)->enabled(TenantServiceKey::AiOffers, $tenant)); } public function test_the_operator_switches_a_service_on_the_tenant_form(): void { $tenant = Tenant::factory()->create(); app(TenantContext::class)->set($tenant); $operator = User::factory()->create(); $operator->forceFill(['is_operator' => true])->saveQuietly(); $this->actingAs($operator); Filament::setCurrentPanel('operator'); Livewire::test(EditTenant::class, ['record' => $tenant->getRouteKey()]) ->fillForm([ 'services.'.TenantServiceKey::PortalSync->value.'.is_enabled' => false, 'services.'.TenantServiceKey::PortalMail->value.'.is_enabled' => true, ]) ->call('save') ->assertHasNoErrors(); $this->assertFalse($tenant->services()->where('service', TenantServiceKey::PortalSync->value)->sole()->is_enabled); $this->assertTrue($tenant->services()->where('service', TenantServiceKey::PortalMail->value)->sole()->is_enabled); $this->assertSame(0, $tenant->services()->where('service', TenantServiceKey::AiOffers->value)->count()); $this->assertFalse(app(TenantFeatures::class)->enabled(TenantServiceKey::PortalSync, $tenant)); } /** * The data a new landlord starts with comes from the installation, never from the landlord that happens * to be current – otherwise the migration would copy one landlord's address into the next one. */ public function test_the_defaults_of_a_new_landlord_come_from_the_configuration_not_from_the_current_one(): void { config(['fewo.owner.name' => 'Aus der Konfiguration', 'fewo.owner.email' => 'konfiguration@example.com']); $current = Tenant::factory()->create(['owner_name' => 'Erster Vermieter', 'contact_email' => 'erster@example.com']); app(TenantContext::class)->set($current); $this->assertSame('Erster Vermieter', config('fewo.owner.name')); $next = Tenant::factory()->create(); $this->assertSame('Aus der Konfiguration', $next->owner_name); $this->assertSame('konfiguration@example.com', $next->contact_email); } public function test_the_landlord_of_the_context_decides_the_sender(): void { $tenant = Tenant::factory()->create(['sender_email' => 'versand@vermieter.example', 'sender_name' => 'Vermieter']); app(TenantContext::class)->set($tenant); app(TenantConfig::class)->refresh(); $this->assertSame(['versand@vermieter.example', 'Vermieter'], [config('mail.from.address'), config('mail.from.name')]); } }