Articles: finish admin refactor, uploads hardening, and attachment sorting (0.262)
This commit is contained in:
@@ -413,6 +413,56 @@ class ArticleRepositoryTest extends TestCase
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testSaveFilesOrderUpdatesFilesOrder(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->exactly(3))
|
||||
->method('update')
|
||||
->withConsecutive(
|
||||
[
|
||||
'pp_articles_files',
|
||||
['o' => 0],
|
||||
['AND' => ['article_id' => 12, 'id' => 70]]
|
||||
],
|
||||
[
|
||||
'pp_articles_files',
|
||||
['o' => 1],
|
||||
['AND' => ['article_id' => 12, 'id' => 71]]
|
||||
],
|
||||
[
|
||||
'pp_articles_files',
|
||||
['o' => 2],
|
||||
['AND' => ['article_id' => 12, 'id' => 72]]
|
||||
]
|
||||
)
|
||||
->willReturn(true);
|
||||
|
||||
$repository = new ArticleRepository($mockDb);
|
||||
$result = $repository->saveFilesOrder(12, '70;71;72');
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testSaveFilesOrderSkipsEmptyValues(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with(
|
||||
'pp_articles_files',
|
||||
['o' => 0],
|
||||
['AND' => ['article_id' => 7, 'id' => 101]]
|
||||
)
|
||||
->willReturn(true);
|
||||
|
||||
$repository = new ArticleRepository($mockDb);
|
||||
$result = $repository->saveFilesOrder(7, ';101;');
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testArchiveSetsStatusToMinusOne(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
@@ -482,6 +532,56 @@ class ArticleRepositoryTest extends TestCase
|
||||
$this->assertSame('pp_articles', $deleteCalls[4]['table']);
|
||||
}
|
||||
|
||||
public function testPagesSummaryForArticlesBuildsLabels(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->willReturnCallback(function ($sql, $params = []) {
|
||||
return new class {
|
||||
public function fetchAll()
|
||||
{
|
||||
return [
|
||||
['article_id' => 5, 'page_id' => 10, 'title' => 'Blog'],
|
||||
['article_id' => 5, 'page_id' => 11, 'title' => 'Poradniki'],
|
||||
['article_id' => 8, 'page_id' => 12, 'title' => 'Aktualnosci'],
|
||||
];
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
$repository = new ArticleRepository($mockDb);
|
||||
$result = $repository->pagesSummaryForArticles([5, 8]);
|
||||
|
||||
$this->assertSame(' - Blog / Poradniki', $result[5]);
|
||||
$this->assertSame(' - Aktualnosci', $result[8]);
|
||||
}
|
||||
|
||||
public function testUpdateImageAltDelegatesToDatabase(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with('pp_articles_images', ['alt' => 'Nowy alt'], ['id' => 33])
|
||||
->willReturn(true);
|
||||
|
||||
$repository = new ArticleRepository($mockDb);
|
||||
$this->assertTrue($repository->updateImageAlt(33, 'Nowy alt'));
|
||||
}
|
||||
|
||||
public function testMarkFileToDeleteDelegatesToDatabase(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with('pp_articles_files', ['to_delete' => 1], ['id' => 17])
|
||||
->willReturn(true);
|
||||
|
||||
$repository = new ArticleRepository($mockDb);
|
||||
$this->assertTrue($repository->markFileToDelete(17));
|
||||
}
|
||||
|
||||
public function testListArchivedForAdminWhitelistsSortAndDirection(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
Reference in New Issue
Block a user