From 300eccfd172c1a97e15599b2b8cbf88745be2d06 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 16 Aug 2021 17:11:05 +0100 Subject: [PATCH] [TESTS] Raise test coverage for Attachment controller to 100% --- tests/Controller/AttachmentTest.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/Controller/AttachmentTest.php b/tests/Controller/AttachmentTest.php index 0501bc1eaa..ebe0b31eba 100644 --- a/tests/Controller/AttachmentTest.php +++ b/tests/Controller/AttachmentTest.php @@ -43,16 +43,16 @@ class AttachmentTest extends GNUsocialTestCase $this->assertSelectorTextContains('.stacktrace', 'ClientException'); } - private function testAttachment(string $suffix) + private function testAttachment(string $suffix = '') { - $client = static::createClient(); - $attachment = DB::findOneBy('attachment', ['filehash' => '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea']); - $crawler = $client->request('GET', "/attachment/{$attachment->getId()}{$suffix}"); + $client = static::createClient(); + $id = DB::findOneBy('attachment', ['filehash' => '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea'])->getId(); + $crawler = $client->request('GET', "/attachment/{$id}{$suffix}"); } public function testAttachmentShow() { - $this->testAttachment(''); + $this->testAttachment(); $this->assertResponseIsSuccessful(); $this->assertSelectorTextContains('figure figcaption', '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea'); } @@ -63,6 +63,16 @@ class AttachmentTest extends GNUsocialTestCase $this->assertResponseIsSuccessful(); } + public function testAttachmentViewNotStored() + { + $client = static::createClient(); + $last_attachment = DB::findBy('attachment', [], orderBy: ['id' => 'DESC'], limit: 1)[0]; + $id = $last_attachment->getId() + 1; + $crawler = $client->request('GET', "/attachment/{$id}/view"); + $this->assertResponseStatusCodeSame(500); // TODO (exception page) 404 + $this->assertSelectorTextContains('.stacktrace', 'ClientException'); + } + public function testAttachmentDownload() { $this->testAttachment('/download');