Files
shopPRO/tests/Unit/Domain/Article/ArticleRepositoryTest.php
Jacek Pyziak e33978e1bb feat: Refactor article handling and introduce ArticleRepository
- Introduced Domain\Article\ArticleRepository for better data access.
- Migrated article_edit functionality to admin\Controllers\ArticlesController.
- Updated admin\factory\Articles::article_details() to use the new repository.
- Marked legacy methods in admin\controls as @deprecated for clarity.
- Updated changelog and versioning to reflect changes in version 0.242.
2026-02-06 08:41:34 +01:00

61 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit\Domain\Article;
use PHPUnit\Framework\TestCase;
use Domain\Article\ArticleRepository;
class ArticleRepositoryTest extends TestCase
{
public function testFindReturnsArticleWithRelations(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_articles', '*', ['id' => 7])
->willReturn(['id' => 7, 'status' => 1]);
$mockDb->expects($this->exactly(4))
->method('select')
->willReturnOnConsecutiveCalls(
[
['lang_id' => 'pl', 'title' => 'Artykul'],
['lang_id' => 'en', 'title' => 'Article'],
],
[
['id' => 10, 'src' => '/img/a.jpg']
],
[
['id' => 20, 'src' => '/files/a.pdf']
],
[1, 2]
);
$repository = new ArticleRepository($mockDb);
$article = $repository->find(7);
$this->assertIsArray($article);
$this->assertEquals(7, $article['id']);
$this->assertArrayHasKey('languages', $article);
$this->assertEquals('Artykul', $article['languages']['pl']['title']);
$this->assertCount(1, $article['images']);
$this->assertCount(1, $article['files']);
$this->assertEquals([1, 2], $article['pages']);
}
public function testFindReturnsNullWhenArticleDoesNotExist(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('get')
->with('pp_articles', '*', ['id' => 999])
->willReturn(false);
$mockDb->expects($this->never())->method('select');
$repository = new ArticleRepository($mockDb);
$article = $repository->find(999);
$this->assertNull($article);
}
}