2026-03-04 15:56:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-03-18 22:20:54 +01:00
|
|
|
namespace MintyPHP\Tests\Module\AddressBook\Service;
|
2026-03-04 15:56:58 +01:00
|
|
|
|
2026-03-18 22:20:54 +01:00
|
|
|
use MintyPHP\Module\AddressBook\Service\AddressBookService;
|
2026-03-26 12:24:06 +01:00
|
|
|
use MintyPHP\Service\Access\RoleService;
|
2026-03-13 11:31:33 +01:00
|
|
|
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\UserAssignmentService;
|
2026-03-13 11:31:33 +01:00
|
|
|
use MintyPHP\Service\User\UserAvatarService;
|
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);
|
|
|
|
|
$userAssignmentService = $this->createMock(UserAssignmentService::class);
|
2026-03-13 11:31:33 +01:00
|
|
|
$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-03-04 15:56:58 +01:00
|
|
|
|
2026-03-13 11:31:33 +01:00
|
|
|
$scopeGateway
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->once())
|
|
|
|
|
->method('getUserTenantIds')
|
|
|
|
|
->with(7)
|
|
|
|
|
->willReturn([]);
|
2026-03-13 11:31:33 +01:00
|
|
|
$tenantService
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->once())
|
2026-03-13 11:31:33 +01:00
|
|
|
->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'],
|
|
|
|
|
]);
|
2026-03-13 11:31:33 +01:00
|
|
|
$scopeGateway
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->exactly(2))
|
2026-03-13 11:31:33 +01:00
|
|
|
->method('isStrict')
|
2026-03-04 15:56:58 +01:00
|
|
|
->willReturn(false);
|
2026-03-13 11:31:33 +01:00
|
|
|
$departmentService
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->once())
|
2026-03-13 11:31:33 +01:00
|
|
|
->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'],
|
|
|
|
|
]);
|
2026-03-13 11:31:33 +01:00
|
|
|
$departmentService
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->never())
|
2026-03-13 11:31:33 +01:00
|
|
|
->method('listByTenantIds');
|
|
|
|
|
$roleService
|
2026-03-04 15:56:58 +01:00
|
|
|
->expects($this->once())
|
2026-03-13 11:31:33 +01:00
|
|
|
->method('listActive')
|
2026-03-04 15:56:58 +01:00
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
|
|
$customFieldGateway
|
|
|
|
|
->expects($this->once())
|
2026-03-18 22:20:54 +01:00
|
|
|
->method('extractCustomFieldFilterSpec')
|
2026-03-04 15:56:58 +01:00
|
|
|
->with([], 7)
|
|
|
|
|
->willReturn([
|
|
|
|
|
'definitions' => [],
|
|
|
|
|
'query' => [],
|
|
|
|
|
]);
|
|
|
|
|
$service = new AddressBookService(
|
|
|
|
|
$userAccountService,
|
|
|
|
|
$userAssignmentService,
|
2026-03-13 11:31:33 +01:00
|
|
|
$tenantService,
|
|
|
|
|
$departmentService,
|
|
|
|
|
$roleService,
|
|
|
|
|
$scopeGateway,
|
2026-03-04 15:56:58 +01:00
|
|
|
$customFieldGateway,
|
2026-03-13 11:31:33 +01:00
|
|
|
$avatarService
|
2026-03-04 15:56:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$context = $service->buildIndexContext(7, []);
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[
|
|
|
|
|
'tenant-a' => ['10'],
|
|
|
|
|
'tenant-b' => ['20'],
|
|
|
|
|
],
|
|
|
|
|
$context['tenantDepartmentMap']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|