Articles: finish admin refactor, uploads hardening, and attachment sorting (0.262)

This commit is contained in:
2026-02-13 09:00:24 +01:00
parent e984548516
commit 3e1f417ef3
31 changed files with 1951 additions and 1512 deletions

View File

@@ -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);

View File

@@ -56,6 +56,26 @@ class ArticlesControllerTest extends TestCase
$this->assertTrue(method_exists($this->controller, 'galleryOrderSave'));
}
public function testHasImageAltChangeMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'imageAltChange'));
}
public function testHasFileNameChangeMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'fileNameChange'));
}
public function testHasImageDeleteMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'imageDelete'));
}
public function testHasFileDeleteMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'fileDelete'));
}
public function testListMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
@@ -74,6 +94,30 @@ class ArticlesControllerTest extends TestCase
$this->assertEquals('void', (string)$reflection->getMethod('galleryOrderSave')->getReturnType());
}
public function testImageAltChangeMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('imageAltChange')->getReturnType());
}
public function testFileNameChangeMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('fileNameChange')->getReturnType());
}
public function testImageDeleteMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('imageDelete')->getReturnType());
}
public function testFileDeleteMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('fileDelete')->getReturnType());
}
public function testConstructorRequiresArticleRepository(): void
{
$reflection = new \ReflectionClass(ArticlesController::class);

View File

@@ -44,6 +44,7 @@ if (!class_exists('S')) {
public static function delete_dir($path) {}
public static function alert($msg) {}
public static function htacces() {}
public static function delete_cache() {}
public static function get($key) { return null; }
public static function set_message($msg) {}
public static function clear_redis_cache() {}