Release 0.249: banner edit fixes and thumbnail popup
This commit is contained in:
@@ -21,7 +21,10 @@ class BannerRepositoryTest extends TestCase
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_banners_langs', '*', ['id_banner' => 1])
|
||||
->with('pp_banners_langs', '*', [
|
||||
'id_banner' => 1,
|
||||
'ORDER' => ['id' => 'ASC'],
|
||||
])
|
||||
->willReturn([
|
||||
['id_lang' => 'pl', 'src' => 'banner.jpg', 'url' => '/promo'],
|
||||
['id_lang' => 'en', 'src' => 'banner-en.jpg', 'url' => '/promo-en'],
|
||||
@@ -80,7 +83,7 @@ class BannerRepositoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test zapisywania nowego banera
|
||||
* Test zapisywania nowego banera (stary format danych - zachowano kompatybilność)
|
||||
*/
|
||||
public function testSaveInsertsNewBanner()
|
||||
{
|
||||
@@ -100,9 +103,51 @@ class BannerRepositoryTest extends TestCase
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act
|
||||
// Act - nowy format z FormRequestHandler (przetworzone dane)
|
||||
$result = $repository->save([
|
||||
'name' => 'Nowy baner',
|
||||
'status' => 1, // już przetworzone na int
|
||||
'date_start' => null,
|
||||
'date_end' => null,
|
||||
'home_page' => 1, // już przetworzone na int
|
||||
'translations' => [
|
||||
1 => [ // id języka jako klucz
|
||||
'src' => 'banner.jpg',
|
||||
'url' => '/promo',
|
||||
'html' => '',
|
||||
'text' => 'Tekst',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals(10, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test zapisywania banera ze starym formatem danych (backward compatibility)
|
||||
*/
|
||||
public function testSaveWithLegacyFormat()
|
||||
{
|
||||
// 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(11);
|
||||
|
||||
// get() for checking existing translations - returns false (no existing)
|
||||
$mockDb->method('get')->willReturn(false);
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
// Act - stary format (dla kompatybilności wstecznej)
|
||||
$result = $repository->save([
|
||||
'name' => 'Baner legacy',
|
||||
'status' => 'on',
|
||||
'date_start' => '',
|
||||
'date_end' => '',
|
||||
@@ -114,6 +159,114 @@ class BannerRepositoryTest extends TestCase
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals(10, $result);
|
||||
$this->assertEquals(11, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test zapisu istniejacego banera - aktualizacja tlumaczen po id_banner + id_lang
|
||||
*/
|
||||
public function testSaveUpdatesExistingTranslationsByBannerAndLang(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('update')
|
||||
->withConsecutive(
|
||||
[
|
||||
'pp_banners',
|
||||
$this->arrayHasKey('name'),
|
||||
['id' => 5],
|
||||
],
|
||||
[
|
||||
'pp_banners_langs',
|
||||
$this->callback(function (array $data): bool {
|
||||
return $data['id_banner'] === 5
|
||||
&& $data['id_lang'] === 'pl'
|
||||
&& $data['src'] === 'banner-new.jpg';
|
||||
}),
|
||||
['AND' => ['id_banner' => 5, 'id_lang' => 'pl']],
|
||||
]
|
||||
);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('count')
|
||||
->with('pp_banners_langs', ['AND' => ['id_banner' => 5, 'id_lang' => 'pl']])
|
||||
->willReturn(2);
|
||||
|
||||
$mockDb->expects($this->never())
|
||||
->method('insert');
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
$result = $repository->save([
|
||||
'id' => 5,
|
||||
'name' => 'Baner update',
|
||||
'status' => 1,
|
||||
'date_start' => null,
|
||||
'date_end' => null,
|
||||
'home_page' => 0,
|
||||
'translations' => [
|
||||
'pl' => [
|
||||
'src' => 'banner-new.jpg',
|
||||
'url' => '/promo-new',
|
||||
'html' => '<b>promo</b>',
|
||||
'text' => 'Nowa tresc',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(5, $result);
|
||||
}
|
||||
|
||||
public function testListForAdminIncludesThumbnailSrc(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$countStmt = $this->createMock(\PDOStatement::class);
|
||||
$countStmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->willReturn([[2]]);
|
||||
|
||||
$itemsStmt = $this->createMock(\PDOStatement::class);
|
||||
$itemsStmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->willReturn([
|
||||
[
|
||||
'id' => 10,
|
||||
'name' => 'Baner A',
|
||||
'status' => 1,
|
||||
'home_page' => 0,
|
||||
'date_start' => null,
|
||||
'date_end' => null,
|
||||
],
|
||||
[
|
||||
'id' => 11,
|
||||
'name' => 'Baner B',
|
||||
'status' => 1,
|
||||
'home_page' => 1,
|
||||
'date_start' => null,
|
||||
'date_end' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$thumbsStmt = $this->createMock(\PDOStatement::class);
|
||||
$thumbsStmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->willReturn([
|
||||
['id_banner' => 10, 'src' => '/uploads/banner-a.jpg'],
|
||||
]);
|
||||
|
||||
$mockDb->expects($this->exactly(3))
|
||||
->method('query')
|
||||
->willReturnOnConsecutiveCalls($countStmt, $itemsStmt, $thumbsStmt);
|
||||
|
||||
$repository = new BannerRepository($mockDb);
|
||||
|
||||
$result = $repository->listForAdmin([], 'name', 'ASC', 1, 15);
|
||||
|
||||
$this->assertSame(2, $result['total']);
|
||||
$this->assertCount(2, $result['items']);
|
||||
$this->assertSame('/uploads/banner-a.jpg', $result['items'][0]['thumbnail_src']);
|
||||
$this->assertSame('', $result['items'][1]['thumbnail_src']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user