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:
@@ -4,15 +4,6 @@ namespace Tests\Unit\Domain\Settings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Domain\Settings\SettingsRepository;
|
||||
|
||||
/**
|
||||
* Testy dla SettingsRepository
|
||||
*
|
||||
* UWAGA: SettingsRepository jest krokiem pośrednim migracji - deleguje do
|
||||
* statycznych metod admin\factory\Settings. Pełne testy jednostkowe z mockami
|
||||
* będą możliwe po migracji do DI (jak ProductRepository/BannerRepository).
|
||||
*
|
||||
* Na razie testujemy tylko to, co da się zweryfikować bez bazy danych.
|
||||
*/
|
||||
class SettingsRepositoryTest extends TestCase
|
||||
{
|
||||
public function testCanBeInstantiated(): void
|
||||
@@ -30,4 +21,105 @@ class SettingsRepositoryTest extends TestCase
|
||||
{
|
||||
$this->assertTrue(method_exists(SettingsRepository::class, 'getSettings'));
|
||||
}
|
||||
|
||||
public function testAllSettingsReturnsAssociativeArray(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_settings', '*')
|
||||
->willReturn([
|
||||
['param' => 'firm_name', 'value' => 'Test Shop'],
|
||||
['param' => 'contact_email', 'value' => 'test@example.com'],
|
||||
['param' => 'ssl', 'value' => '1'],
|
||||
]);
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$settings = $service->allSettings(true);
|
||||
|
||||
$this->assertIsArray($settings);
|
||||
$this->assertEquals('Test Shop', $settings['firm_name']);
|
||||
$this->assertEquals('test@example.com', $settings['contact_email']);
|
||||
$this->assertEquals('1', $settings['ssl']);
|
||||
$this->assertCount(3, $settings);
|
||||
}
|
||||
|
||||
public function testAllSettingsReturnsEmptyArrayWhenNoSettings(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_settings', '*')
|
||||
->willReturn([]);
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$settings = $service->allSettings(true);
|
||||
|
||||
$this->assertIsArray($settings);
|
||||
$this->assertEmpty($settings);
|
||||
}
|
||||
|
||||
public function testAllSettingsHandlesNullFromDb(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_settings', '*')
|
||||
->willReturn(null);
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$settings = $service->allSettings(true);
|
||||
|
||||
$this->assertIsArray($settings);
|
||||
$this->assertEmpty($settings);
|
||||
}
|
||||
|
||||
public function testGetSingleValueReturnsCorrectParam(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_settings', 'value', ['param' => 'contact_email'])
|
||||
->willReturn('test@example.com');
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$value = $service->getSingleValue('contact_email');
|
||||
|
||||
$this->assertEquals('test@example.com', $value);
|
||||
}
|
||||
|
||||
public function testGetSingleValueUsesParamNotHardcoded(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
// Kluczowy test: sprawdza ze param NIE jest hardcoded na 'firm_name'
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_settings', 'value', ['param' => 'ssl'])
|
||||
->willReturn('1');
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$value = $service->getSingleValue('ssl');
|
||||
|
||||
$this->assertEquals('1', $value);
|
||||
}
|
||||
|
||||
public function testGetSingleValueReturnsEmptyStringWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_settings', 'value', ['param' => 'nonexistent'])
|
||||
->willReturn(null);
|
||||
|
||||
$service = new SettingsRepository($mockDb);
|
||||
$value = $service->getSingleValue('nonexistent');
|
||||
|
||||
$this->assertEquals('', $value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user