1
0
Files
breadcrumb-the-shire/tests/Service/AddressBook/AddressBookServiceTest.php

87 lines
2.9 KiB
PHP
Raw Normal View History

2026-03-04 15:56:58 +01:00
<?php
namespace MintyPHP\Tests\Service\AddressBook;
use MintyPHP\Service\AddressBook\AddressBookAvatarGateway;
use MintyPHP\Service\AddressBook\AddressBookCustomFieldGateway;
use MintyPHP\Service\AddressBook\AddressBookDirectoryGateway;
use MintyPHP\Service\AddressBook\AddressBookService;
use MintyPHP\Service\User\UserAccountService;
use MintyPHP\Service\User\UserAssignmentService;
use PHPUnit\Framework\TestCase;
class AddressBookServiceTest extends TestCase
{
public function testBuildIndexContextBuildsTenantDepartmentMapForGlobalScope(): void
{
$userAccountService = $this->createMock(UserAccountService::class);
$userAssignmentService = $this->createMock(UserAssignmentService::class);
$directoryGateway = $this->createMock(AddressBookDirectoryGateway::class);
$customFieldGateway = $this->createMock(AddressBookCustomFieldGateway::class);
$avatarGateway = $this->createMock(AddressBookAvatarGateway::class);
$directoryGateway
->expects($this->once())
->method('getUserTenantIds')
->with(7)
->willReturn([]);
$directoryGateway
->expects($this->once())
->method('listTenants')
->willReturn([
['id' => 1, 'uuid' => 'tenant-a', 'description' => 'Tenant A'],
['id' => 2, 'uuid' => 'tenant-b', 'description' => 'Tenant B'],
]);
$directoryGateway
->expects($this->exactly(2))
->method('isStrictScope')
->willReturn(false);
$directoryGateway
->expects($this->once())
->method('listDepartments')
->willReturn([
['id' => 10, 'tenant_id' => 1, 'description' => 'Sales'],
['id' => 20, 'tenant_id' => 2, 'description' => 'Support'],
]);
$directoryGateway
->expects($this->never())
->method('listDepartmentsByTenantIds');
$directoryGateway
->expects($this->once())
->method('listActiveRoles')
->willReturn([]);
$customFieldGateway
->expects($this->once())
->method('extractFilterSpec')
->with([], 7)
->willReturn([
'definitions' => [],
'query' => [],
]);
$customFieldGateway
->expects($this->once())
->method('listOptionsByDefinitionIds')
->with([], true)
->willReturn([]);
$service = new AddressBookService(
$userAccountService,
$userAssignmentService,
$directoryGateway,
$customFieldGateway,
$avatarGateway
);
$context = $service->buildIndexContext(7, []);
$this->assertSame(
[
'tenant-a' => ['10'],
'tenant-b' => ['20'],
],
$context['tenantDepartmentMap']
);
}
}