lookup = new FakeArchiveLookup(); // username => [mailbox setting, domain default] $this->lookup->mailboxes = [ 'own@firma.de' => ['1', 0], 'inherit@firma.de' => ['inherit', 1], 'excluded@firma.de' => ['0', 1], 'plain@other.example' => ['inherit', 0], ]; } private function service(bool $enabled, ?Context $context = null): MailboxListService { $settings = new Settings(); $settings->enabled = $enabled; $repo = $this->createStub(SettingsRepository::class); $repo->method('load')->willReturn($settings); return new MailboxListService($this->lookup, $repo, $context ?? FakeContext::admin()); } public function testArchivedMailboxesWithTheirSource(): void { $expected = ['enabled' => 1, 'mailboxes' => [ ['username' => 'own@firma.de', 'domain' => 'firma.de', 'name' => '', 'active' => 1, 'source' => 'mailbox'], ['username' => 'inherit@firma.de', 'domain' => 'firma.de', 'name' => '', 'active' => 1, 'source' => 'domain'], ]]; $this->assertSame($expected, $this->service(true)->archived()); // read-only API keys too: archivecow keeps its mailboxes in line with this list $this->assertSame($expected, $this->service(true, new Context('admin', 'API', [], false, 'ro'))->archived()); } public function testEmptyWhileArchivingIsOff(): void { $this->assertSame(['enabled' => 0, 'mailboxes' => []], $this->service(false)->archived()); } public function testOnlyAdmins(): void { foreach ([FakeContext::domainAdmin(['own@firma.de'], ['firma.de'], ['archive' => '1']), FakeContext::user('own@firma.de')] as $context) { try { $this->service(true, $context)->archived(); $this->fail('AccessDenied expected'); } catch (AccessDenied) { $this->addToAssertionCount(1); } } } }