Refactor Scontainers management
- Removed legacy Scontainers controller and view files, transitioning to a new controller structure. - Introduced ScontainersController to handle CRUD operations with improved dependency injection. - Created ScontainersRepository for database interactions, encapsulating logic for container management. - Updated container edit and list views to utilize new templating system. - Added unit tests for ScontainersRepository and ScontainersController to ensure functionality. - Enhanced form handling for container editing, including validation and error management.
This commit is contained in:
63
tests/Unit/Domain/Scontainers/ScontainersRepositoryTest.php
Normal file
63
tests/Unit/Domain/Scontainers/ScontainersRepositoryTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Domain\Scontainers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Domain\Scontainers\ScontainersRepository;
|
||||
|
||||
class ScontainersRepositoryTest extends TestCase
|
||||
{
|
||||
public function testFindReturnsDefaultContainerForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$repository = new ScontainersRepository($mockDb);
|
||||
|
||||
$container = $repository->find(0);
|
||||
|
||||
$this->assertIsArray($container);
|
||||
$this->assertSame(0, (int)$container['id']);
|
||||
$this->assertSame(1, (int)$container['status']);
|
||||
}
|
||||
|
||||
public function testDeleteReturnsFalseForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$repository = new ScontainersRepository($mockDb);
|
||||
|
||||
$this->assertFalse($repository->delete(0));
|
||||
}
|
||||
|
||||
public function testFindReturnsContainerWithTranslations(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_scontainers', '*', ['id' => 7])
|
||||
->willReturn(['id' => 7, 'status' => 1, 'show_title' => 1]);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_scontainers_langs', '*', ['container_id' => 7])
|
||||
->willReturn([
|
||||
['lang_id' => 'pl', 'title' => 'Tytul PL', 'text' => 'Tekst PL'],
|
||||
['lang_id' => 'en', 'title' => 'Title EN', 'text' => 'Text EN'],
|
||||
]);
|
||||
|
||||
$repository = new ScontainersRepository($mockDb);
|
||||
$container = $repository->find(7);
|
||||
|
||||
$this->assertSame(7, (int)$container['id']);
|
||||
$this->assertArrayHasKey('languages', $container);
|
||||
$this->assertArrayHasKey('pl', $container['languages']);
|
||||
$this->assertArrayHasKey('en', $container['languages']);
|
||||
}
|
||||
|
||||
public function testDetailsForLanguageReturnsNullForInvalidData(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$repository = new ScontainersRepository($mockDb);
|
||||
|
||||
$this->assertNull($repository->detailsForLanguage(0, 'pl'));
|
||||
$this->assertNull($repository->detailsForLanguage(1, ''));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user