1
0
Files
breadcrumb-the-shire/modules/helpdesk/tests/Module/Helpdesk/Service/DebitorCacheControlTest.php
fs 3827b09205 test(helpdesk): add OData injection rejection tests and meetings cache key coverage
Adds 11 tests for BcODataGateway covering getMeetingsForCustomer (empty,
whitespace, not-configured), OData injection rejection for all customerNo
methods (meetings, contract lines, escalation tickets, controlling), and
valid input acceptance. Also adds meetingsKey format and inclusion tests
for DebitorCacheControl.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 15:16:57 +02:00

87 lines
3.4 KiB
PHP

<?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);
$sessionStore->expects($this->exactly(14))
->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);
}
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);
}
}