2026-04-04 18:34:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Module\Helpdesk\Service;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
|
|
|
use MintyPHP\Module\Helpdesk\Service\DebitorCacheControl;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class DebitorCacheControlTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function testParseRefreshFlagRecognizesTruthyValues(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertTrue(DebitorCacheControl::parseRefreshFlag('1'));
|
|
|
|
|
$this->assertTrue(DebitorCacheControl::parseRefreshFlag('true'));
|
|
|
|
|
$this->assertTrue(DebitorCacheControl::parseRefreshFlag('YES'));
|
|
|
|
|
$this->assertTrue(DebitorCacheControl::parseRefreshFlag(true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testParseRefreshFlagReturnsFalseForNonTruthyValues(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag(''));
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag('0'));
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag('false'));
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag('nope'));
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag(false));
|
|
|
|
|
$this->assertFalse(DebitorCacheControl::parseRefreshFlag(null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testResolveTenantScopeUsesTenantIdOrGlobal(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertSame('9', DebitorCacheControl::resolveTenantScope([
|
|
|
|
|
'current_tenant' => ['id' => 9],
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$this->assertSame('global', DebitorCacheControl::resolveTenantScope([]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvalidateDebitorCachesRemovesDebitorAndTenantSharedKeys(): void
|
|
|
|
|
{
|
|
|
|
|
$sessionStore = $this->createMock(SessionStoreInterface::class);
|
2026-04-13 14:13:29 +02:00
|
|
|
$sessionStore->expects($this->exactly(14))
|
2026-04-04 18:34:03 +02:00
|
|
|
->method('remove')
|
|
|
|
|
->with($this->callback(static function (string $key): bool {
|
|
|
|
|
return str_contains($key, '.13.10259')
|
|
|
|
|
|| $key === 'module.helpdesk.debitor.v1.escalation-definitions.13';
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
DebitorCacheControl::invalidateDebitorCaches($sessionStore, '13', '10259', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testContractLinesKeyFormat(): void
|
|
|
|
|
{
|
|
|
|
|
$key = DebitorCacheControl::contractLinesKey('5', '10254');
|
|
|
|
|
$this->assertSame('module.helpdesk.debitor.v2.contract-lines.5.10254', $key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllDebitorCacheKeysIncludesContractLinesKey(): void
|
|
|
|
|
{
|
|
|
|
|
$keys = DebitorCacheControl::allDebitorCacheKeys('5', '10254');
|
|
|
|
|
$this->assertContains('module.helpdesk.debitor.v2.contract-lines.5.10254', $keys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testControllingTicketsKeyFormat(): void
|
|
|
|
|
{
|
|
|
|
|
$key = DebitorCacheControl::controllingTicketsKey('7', '10610');
|
|
|
|
|
$this->assertSame('module.helpdesk.debitor.v2.controlling-tickets.7.10610', $key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllDebitorCacheKeysIncludesControllingKey(): void
|
|
|
|
|
{
|
|
|
|
|
$keys = DebitorCacheControl::allDebitorCacheKeys('7', '10610');
|
|
|
|
|
$this->assertContains('module.helpdesk.debitor.v2.controlling-tickets.7.10610', $keys);
|
|
|
|
|
}
|
2026-04-13 15:16:57 +02:00
|
|
|
|
|
|
|
|
public function testMeetingsKeyFormat(): void
|
|
|
|
|
{
|
|
|
|
|
$key = DebitorCacheControl::meetingsKey('3', '10254');
|
|
|
|
|
$this->assertSame('module.helpdesk.debitor.v2.meetings.3.10254', $key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllDebitorCacheKeysIncludesMeetingsKey(): void
|
|
|
|
|
{
|
|
|
|
|
$keys = DebitorCacheControl::allDebitorCacheKeys('3', '10254');
|
|
|
|
|
$this->assertContains('module.helpdesk.debitor.v2.meetings.3.10254', $keys);
|
|
|
|
|
}
|
2026-04-04 18:34:03 +02:00
|
|
|
}
|