ver. 0.291: ShopProducer frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -237,4 +237,79 @@ class ProducerRepositoryTest extends TestCase
|
||||
$this->assertArrayHasKey('ls', $result);
|
||||
$this->assertSame(3, $result['ls']);
|
||||
}
|
||||
|
||||
public function testAllActiveProducersReturnsFullData(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('select')
|
||||
->with('pp_shop_producer', ['id', 'name', 'img'], [
|
||||
'status' => 1,
|
||||
'ORDER' => ['name' => 'ASC'],
|
||||
])
|
||||
->willReturn([
|
||||
['id' => '3', 'name' => 'Apple', 'img' => '/apple.png'],
|
||||
['id' => '7', 'name' => 'Samsung', 'img' => null],
|
||||
]);
|
||||
|
||||
$repository = new ProducerRepository($mockDb);
|
||||
$result = $repository->allActiveProducers();
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertSame(3, $result[0]['id']);
|
||||
$this->assertSame('Apple', $result[0]['name']);
|
||||
$this->assertSame('/apple.png', $result[0]['img']);
|
||||
$this->assertSame(7, $result[1]['id']);
|
||||
$this->assertSame('Samsung', $result[1]['name']);
|
||||
$this->assertNull($result[1]['img']);
|
||||
}
|
||||
|
||||
public function testAllActiveProducersReturnsEmptyOnNull(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('select')->willReturn(null);
|
||||
|
||||
$repository = new ProducerRepository($mockDb);
|
||||
$result = $repository->allActiveProducers();
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
public function testFindForFrontendReturnsNullForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new ProducerRepository($mockDb);
|
||||
$this->assertNull($repository->findForFrontend(0, 'pl'));
|
||||
}
|
||||
|
||||
public function testFindForFrontendReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repository = new ProducerRepository($mockDb);
|
||||
$this->assertNull($repository->findForFrontend(99, 'pl'));
|
||||
}
|
||||
|
||||
public function testFindForFrontendReturnsProducerWithLanguage(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['id' => '5', 'name' => 'Sony', 'status' => '1', 'img' => '/sony.png'],
|
||||
['lang_id' => 'pl', 'description' => 'Opis', 'data' => null, 'meta_title' => 'Sony PL']
|
||||
);
|
||||
|
||||
$repository = new ProducerRepository($mockDb);
|
||||
$result = $repository->findForFrontend(5, 'pl');
|
||||
|
||||
$this->assertSame(5, $result['id']);
|
||||
$this->assertSame('Sony', $result['name']);
|
||||
$this->assertArrayHasKey('pl', $result['languages']);
|
||||
$this->assertSame('Sony PL', $result['languages']['pl']['meta_title']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user