Die Schalter aus Phase 3 schrieben nur in eine Tabelle, die niemand las. Ein gesperrter Portal-Abgleich lief trotzdem weiter. Das ist behoben. `App\Tenancy\TenantFeatures` ist die eine Stelle, die beantwortet, ob ein Mandant einen Dienst hat. Sie wird an allen Wegen abgefragt, die zum Dienst führen: - `RolePolicy::allows()` – damit greift die Mandanten-Ebene in *jeder* Richtlinie des Admins. Die Rolle sagt, was ein Benutzer darf; der Dienst sagt, was der Mandant überhaupt hat. Keine Rolle wiegt einen gesperrten Dienst auf. - `Channel::importsOccupations()` – Import und Scheduler. - Der öffentliche iCal-Feed antwortet mit 404. - `ProcessPortalMail` und `channels:fetch-mail` für den Postfach-Schnellweg. `TenantServiceKey::isWired()` trennt Gebautes von Geplantem. Nur verdrahtete Dienste erscheinen als Schalter; die drei KI-Dienste stehen als Hinweis da, bis die Anwendung sie abfragt. Eigene API-Schlüssel sind aus dem Betreiber- Formular verschwunden – sie gehören in den Admin des Mandanten, wenn es soweit ist (A16). Neu im Betreiber-Bereich: Seite „System" mit den Grenzen, die für alle Mandanten gelten (aus der .env, bewusst nicht änderbar), der Mandantenliste und dem Zugriffsprotokoll. Bisher war dort nur die Mandantenliste. Die Migration schaltet jedem vorhandenen Mandanten die Portal-Dienste frei, damit der Umbau laufenden Betrieb nicht stillschweigend stoppt. 240 Feature-Tests grün, davon fünf neue in `TenantServiceGateTest`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
154 lines
6.3 KiB
PHP
154 lines
6.3 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\Enums\TenantServiceKey;
|
||
use App\Filament\Operator\Tenants\Pages\EditTenant;
|
||
use App\Models\Tenant;
|
||
use App\Models\User;
|
||
use App\Support\Content;
|
||
use App\Support\Settings;
|
||
use App\Tenancy\TenantConfig;
|
||
use App\Tenancy\TenantContext;
|
||
use App\Tenancy\TenantFeatures;
|
||
use Filament\Facades\Filament;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Livewire\Livewire;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Phase 3: operating data and texts belong to the landlord, not to the installation.
|
||
*/
|
||
class TenantSettingsTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
public function test_each_landlord_has_its_own_imprint_bank_and_operating_mode(): void
|
||
{
|
||
config(['fewo.mail_redirect_to' => 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')]);
|
||
}
|
||
}
|