. // }}} namespace App\Tests\Core; use App\Core\DB\DB; use App\Util\GNUsocialTestCase; class AttachmentTest extends GNUsocialTestCase { public function testNoAttachmentID() { // This calls static::bootKernel(), and creates a "client" that is acting as the browser $client = static::createClient(); $client->request('GET', '/attachment'); $this->assertResponseStatusCodeSame(404); $client->request('GET', '/attachment/-1'); $this->assertResponseStatusCodeSame(404); $client->request('GET', '/attachment/asd'); $this->assertResponseStatusCodeSame(404); $client->request('GET', '/attachment/0'); // In the meantime, throwing ClientException doesn't actually result in the reaching the UI, as it's intercepted // by the helpful framework that displays the stack traces and such. This should be easily fixable when we have // our own error pages $this->assertSelectorTextContains('.stacktrace', 'ClientException'); } private function testAttachment(string $suffix) { $client = static::createClient(); $attachment = DB::findOneBy('attachment', ['filehash' => '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea']); $crawler = $client->request('GET', "/attachment/{$attachment->getId()}{$suffix}"); } public function testAttachmentShow() { $this->testAttachment(''); $this->assertResponseIsSuccessful(); $this->assertSelectorTextContains('figure figcaption', '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea'); } public function testAttachmentView() { $this->testAttachment('/view'); $this->assertResponseIsSuccessful(); } public function testAttachmentDownload() { $this->testAttachment('/download'); $this->assertResponseIsSuccessful(); } public function testAttachmentThumbnail() { $this->testAttachment('/thumbnail'); $this->assertResponseIsSuccessful(); } public function testAttachmentThumbnailWrongSize() { $this->testAttachment('/thumbnail?w=1&h=1'); $this->assertSelectorTextContains('.stacktrace', 'ClientException'); // $this->assertResponseStatusCodeSame(400); } }