ver. 0.278: Settings + Languages frontend migration, bug fix get_single_settings_value
- Add cached frontend methods to existing Domain repositories (allSettings, getSingleValue, defaultLanguage, activeLanguages, translations) - Convert front\factory\Settings and Languages to facades delegating to Domain repositories - Fix get_single_settings_value() - was hardcoded to 'firm_name', now uses $param correctly - Add CacheHandler stub methods (get/set/exists) to test bootstrap - Establish architectural rule: Domain classes are shared between admin and frontend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -145,4 +145,140 @@ class LanguagesRepositoryTest extends TestCase
|
||||
$this->assertSame('en', $repository->defaultLanguageId());
|
||||
$this->assertSame('pl', $repository->defaultLanguageId());
|
||||
}
|
||||
|
||||
// --- Metody frontendowe (z cache Redis) ---
|
||||
|
||||
public function testDefaultLanguageReturnsId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockStmt = $this->createMock(\PDOStatement::class);
|
||||
$mockStmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->willReturn([['pl']]);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT id FROM pp_langs WHERE status = 1 ORDER BY start DESC, o ASC LIMIT 1')
|
||||
->willReturn($mockStmt);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$langId = $repository->defaultLanguage();
|
||||
|
||||
$this->assertEquals('pl', $langId);
|
||||
}
|
||||
|
||||
public function testDefaultLanguageReturnsFallbackWhenEmpty(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockStmt = $this->createMock(\PDOStatement::class);
|
||||
$mockStmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->willReturn([]);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->willReturn($mockStmt);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$langId = $repository->defaultLanguage();
|
||||
|
||||
$this->assertEquals('pl', $langId);
|
||||
}
|
||||
|
||||
public function testActiveLanguagesReturnsList(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with(
|
||||
'pp_langs',
|
||||
['id', 'name'],
|
||||
['status' => 1, 'ORDER' => ['o' => 'ASC']]
|
||||
)
|
||||
->willReturn([
|
||||
['id' => 'pl', 'name' => 'Polski'],
|
||||
['id' => 'en', 'name' => 'English'],
|
||||
]);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$languages = $repository->activeLanguages();
|
||||
|
||||
$this->assertIsArray($languages);
|
||||
$this->assertCount(2, $languages);
|
||||
$this->assertEquals('pl', $languages[0]['id']);
|
||||
$this->assertEquals('English', $languages[1]['name']);
|
||||
}
|
||||
|
||||
public function testActiveLanguagesReturnsEmptyArrayWhenNone(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$languages = $repository->activeLanguages();
|
||||
|
||||
$this->assertIsArray($languages);
|
||||
$this->assertEmpty($languages);
|
||||
}
|
||||
|
||||
public function testTranslationsReturnsArray(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_langs_translations', ['text', 'pl'])
|
||||
->willReturn([
|
||||
['text' => 'basket', 'pl' => 'Koszyk'],
|
||||
['text' => 'order', 'pl' => 'Zamowienie'],
|
||||
]);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$translations = $repository->translations('pl');
|
||||
|
||||
$this->assertIsArray($translations);
|
||||
$this->assertEquals('pl', $translations['0']);
|
||||
$this->assertEquals('Koszyk', $translations['basket']);
|
||||
$this->assertEquals('Zamowienie', $translations['order']);
|
||||
}
|
||||
|
||||
public function testTranslationsDefaultsToPl(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_langs_translations', ['text', 'pl'])
|
||||
->willReturn([]);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$translations = $repository->translations();
|
||||
|
||||
$this->assertIsArray($translations);
|
||||
$this->assertEquals('pl', $translations['0']);
|
||||
}
|
||||
|
||||
public function testTranslationsForDifferentLanguage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_langs_translations', ['text', 'en'])
|
||||
->willReturn([
|
||||
['text' => 'basket', 'en' => 'Cart'],
|
||||
]);
|
||||
|
||||
$repository = new LanguagesRepository($mockDb);
|
||||
$translations = $repository->translations('en');
|
||||
|
||||
$this->assertEquals('en', $translations['0']);
|
||||
$this->assertEquals('Cart', $translations['basket']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user