Add new settings and cache repository files, update admin settings controller and templates
- Introduced new `SettingsRepository` and `CacheRepository` classes in the `autoload\Domain` namespace. - Updated `SettingsController` in the `admin\Controllers` namespace to enhance settings management. - Added new templates for settings in `admin\templates\settings` and `admin\templates\site`. - Improved overall structure and organization of settings-related files.
This commit is contained in:
119
tests/Unit/Domain/Banner/BannerRepositoryTest.php
Normal file
119
tests/Unit/Domain/Banner/BannerRepositoryTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Domain\Banner;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Domain\Banner\BannerRepository;
|
||||
|
||||
class BannerRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test pobierania banera - zwraca dane z tłumaczeniami
|
||||
*/
|
||||
public function testFindReturnsBannerWithTranslations()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_banners', '*', ['id' => 1])
|
||||
->willReturn(['id' => 1, 'name' => 'Baner testowy', 'status' => 1]);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_banners_langs', '*', ['id_banner' => 1])
|
||||
->willReturn([
|
||||
['id_lang' => 'pl', 'src' => 'banner.jpg', 'url' => '/promo'],
|
||||
['id_lang' => 'en', 'src' => 'banner-en.jpg', 'url' => '/promo-en'],
|
||||
]);
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$banner = $repository->find(1);
|
||||
|
||||
// Assert
|
||||
$this->assertIsArray($banner);
|
||||
$this->assertEquals('Baner testowy', $banner['name']);
|
||||
$this->assertArrayHasKey('languages', $banner);
|
||||
$this->assertCount(2, $banner['languages']);
|
||||
$this->assertEquals('banner.jpg', $banner['languages']['pl']['src']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test pobierania banera - nie istnieje
|
||||
*/
|
||||
public function testFindReturnsNullWhenNotFound()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(false);
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$banner = $repository->find(999);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($banner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test usuwania banera - sukces
|
||||
*/
|
||||
public function testDeleteReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('delete')
|
||||
->with('pp_banners', ['id' => 5])
|
||||
->willReturn($this->createMock(\PDOStatement::class));
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$result = $repository->delete(5);
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test zapisywania nowego banera
|
||||
*/
|
||||
public function testSaveInsertsNewBanner()
|
||||
{
|
||||
// Arrange
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
// insert() wywoływane 2x: raz dla banera, raz dla tłumaczenia
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('insert');
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('id')
|
||||
->willReturn(10);
|
||||
|
||||
// get() for checking existing translations - returns false (no existing)
|
||||
$mockDb->method('get')->willReturn(false);
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act
|
||||
$result = $repository->save([
|
||||
'name' => 'Nowy baner',
|
||||
'status' => 'on',
|
||||
'date_start' => '',
|
||||
'date_end' => '',
|
||||
'home_page' => 'on',
|
||||
'src' => ['pl' => 'banner.jpg'],
|
||||
'url' => ['pl' => '/promo'],
|
||||
'html' => ['pl' => ''],
|
||||
'text' => ['pl' => 'Tekst'],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals(10, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user