Files

93 lines
3.3 KiB
PHP
Raw Permalink Normal View History

2026-03-04 15:56:58 +01:00
<?php
namespace MintyPHP\Tests\Module\AddressBook\Service;
2026-03-04 15:56:58 +01:00
use MintyPHP\Module\AddressBook\Service\AddressBookService;
use MintyPHP\Repository\CustomField\TenantCustomFieldOptionRepositoryInterface;
use MintyPHP\Service\Access\RoleService;
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
use MintyPHP\Service\Org\DepartmentService;
use MintyPHP\Service\Tenant\TenantScopeService;
use MintyPHP\Service\Tenant\TenantService;
2026-03-04 15:56:58 +01:00
use MintyPHP\Service\User\UserAccountService;
use MintyPHP\Service\User\UserAvatarService;
2026-04-22 15:49:10 +02:00
use MintyPHP\Service\User\UserProfileViewService;
2026-03-04 15:56:58 +01:00
use PHPUnit\Framework\TestCase;
class AddressBookServiceTest extends TestCase
{
public function testBuildIndexContextBuildsTenantDepartmentMapForGlobalScope(): void
{
$userAccountService = $this->createMock(UserAccountService::class);
$tenantService = $this->createMock(TenantService::class);
$departmentService = $this->createMock(DepartmentService::class);
$roleService = $this->createMock(RoleService::class);
$scopeGateway = $this->createMock(TenantScopeService::class);
$customFieldGateway = $this->createMock(UserCustomFieldValueService::class);
$avatarService = $this->createMock(UserAvatarService::class);
2026-04-22 15:49:10 +02:00
$userProfileViewService = $this->createMock(UserProfileViewService::class);
$tenantCustomFieldOptionRepository = $this->createMock(TenantCustomFieldOptionRepositoryInterface::class);
2026-03-04 15:56:58 +01:00
$scopeGateway
2026-03-04 15:56:58 +01:00
->expects($this->once())
->method('getUserTenantIds')
->with(7)
->willReturn([]);
$tenantService
2026-03-04 15:56:58 +01:00
->expects($this->once())
->method('list')
2026-03-04 15:56:58 +01:00
->willReturn([
['id' => 1, 'uuid' => 'tenant-a', 'description' => 'Tenant A'],
['id' => 2, 'uuid' => 'tenant-b', 'description' => 'Tenant B'],
]);
$scopeGateway
2026-03-04 15:56:58 +01:00
->expects($this->exactly(2))
->method('isStrict')
2026-03-04 15:56:58 +01:00
->willReturn(false);
$departmentService
2026-03-04 15:56:58 +01:00
->expects($this->once())
->method('list')
2026-03-04 15:56:58 +01:00
->willReturn([
['id' => 10, 'tenant_id' => 1, 'description' => 'Sales'],
['id' => 20, 'tenant_id' => 2, 'description' => 'Support'],
]);
$departmentService
2026-03-04 15:56:58 +01:00
->expects($this->never())
->method('listByTenantIds');
$roleService
2026-03-04 15:56:58 +01:00
->expects($this->once())
->method('listActive')
2026-03-04 15:56:58 +01:00
->willReturn([]);
$customFieldGateway
->expects($this->once())
->method('extractCustomFieldFilterSpec')
2026-03-04 15:56:58 +01:00
->with([], 7)
->willReturn([
'definitions' => [],
'query' => [],
]);
$service = new AddressBookService(
$userAccountService,
$tenantService,
$departmentService,
$roleService,
$scopeGateway,
2026-03-04 15:56:58 +01:00
$customFieldGateway,
2026-04-22 15:49:10 +02:00
$avatarService,
$userProfileViewService,
$tenantCustomFieldOptionRepository
2026-03-04 15:56:58 +01:00
);
$context = $service->buildIndexContext(7, []);
$this->assertSame(
[
'tenant-a' => ['10'],
'tenant-b' => ['20'],
],
$context['tenantDepartmentMap']
);
}
}