- Dodano testy: SettingsRepositoryTest, LanguagesRepositoryTest, UserRepositoryTest - Infrastruktura: phpunit.xml, composer.json (phpunit/phpunit ^10), tests/bootstrap.php - Bootstrap stuby: \Shared\Cache\CacheHandler (in-memory), \S - Zaktualizowano docs/TESTING.md dla cmsPRO - Paczka: updates/1.60/ver_1.691.zip + manifest Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
124 lines
3.5 KiB
PHP
124 lines
3.5 KiB
PHP
<?php
|
|
namespace Tests\Unit\Domain\Languages;
|
|
|
|
use Domain\Languages\LanguagesRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class LanguagesRepositoryTest extends TestCase
|
|
{
|
|
private function mockDb(): object
|
|
{
|
|
return $this->createMock(\medoo::class);
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
\Shared\Cache\CacheHandler::reset();
|
|
}
|
|
|
|
// --- languagesList ---
|
|
|
|
public function testLanguagesListReturnsArray(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('select')->willReturn([['id' => 'pl', 'name' => 'Polski']]);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame([['id' => 'pl', 'name' => 'Polski']], $repo->languagesList());
|
|
}
|
|
|
|
public function testLanguagesListReturnsEmptyWhenNull(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('select')->willReturn(null);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame([], $repo->languagesList());
|
|
}
|
|
|
|
// --- languageDetails ---
|
|
|
|
public function testLanguageDetailsReturnsRowWhenFound(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('get')->willReturn(['id' => 'pl', 'name' => 'Polski']);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame('pl', $repo->languageDetails('pl')['id']);
|
|
}
|
|
|
|
public function testLanguageDetailsReturnsNullWhenNotFound(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('get')->willReturn(null);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertNull($repo->languageDetails('xx'));
|
|
}
|
|
|
|
// --- activeLanguages ---
|
|
|
|
public function testActiveLanguagesQueriesDbAndCaches(): void
|
|
{
|
|
$expected = [['id' => 'pl', 'name' => 'Polski', 'domain' => null]];
|
|
$db = $this->mockDb();
|
|
$db->expects($this->once())->method('select')->willReturn($expected);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame($expected, $repo->activeLanguages());
|
|
// Drugi odczyt — z cache (mock select nie zostanie wywołany drugi raz)
|
|
$this->assertSame($expected, $repo->activeLanguages());
|
|
}
|
|
|
|
public function testActiveLanguagesReturnsEmptyWhenNull(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('select')->willReturn(null);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame([], $repo->activeLanguages());
|
|
}
|
|
|
|
// --- maxOrder ---
|
|
|
|
public function testMaxOrderReturnsInteger(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('max')->willReturn('5');
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame(5, $repo->maxOrder());
|
|
}
|
|
|
|
// --- translationDelete ---
|
|
|
|
public function testTranslationDeleteReturnsTrueOnSuccess(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('delete')->willReturn(1);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertTrue($repo->translationDelete(1));
|
|
}
|
|
|
|
public function testTranslationDeleteReturnsFalseOnFailure(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('delete')->willReturn(0);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertFalse($repo->translationDelete(1));
|
|
}
|
|
|
|
// --- translationDetails ---
|
|
|
|
public function testTranslationDetailsReturnsRowOrNull(): void
|
|
{
|
|
$db = $this->mockDb();
|
|
$db->method('get')->willReturn(['id' => 1, 'text' => 'hello']);
|
|
|
|
$repo = new LanguagesRepository($db);
|
|
$this->assertSame(['id' => 1, 'text' => 'hello'], $repo->translationDetails(1));
|
|
}
|
|
}
|