2021-08-04 02:53:58 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-04 02:53:58 +09:00
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2022-03-07 05:16:46 +09:00
|
|
|
namespace Component\Attachment\tests\Controller;
|
2021-08-04 02:53:58 +09:00
|
|
|
|
2022-03-27 23:19:09 +09:00
|
|
|
use App\Core\DB;
|
2021-08-04 02:53:58 +09:00
|
|
|
use App\Util\GNUsocialTestCase;
|
2022-03-07 05:16:46 +09:00
|
|
|
use Component\Attachment\Entity\Attachment;
|
|
|
|
use Component\Attachment\Entity\AttachmentToNote;
|
2021-08-04 02:53:58 +09:00
|
|
|
|
|
|
|
class AttachmentTest extends GNUsocialTestCase
|
|
|
|
{
|
|
|
|
public function testNoAttachmentID()
|
|
|
|
{
|
|
|
|
// This calls static::bootKernel(), and creates a "client" that is acting as the browser
|
|
|
|
$client = static::createClient();
|
2022-03-07 05:16:46 +09:00
|
|
|
//$client->request('GET', '/attachment');
|
|
|
|
//$this->assertResponseStatusCodeSame(404);
|
|
|
|
$client->request('GET', '/object/note/1/attachment/-1');
|
2021-08-04 02:53:58 +09:00
|
|
|
$this->assertResponseStatusCodeSame(404);
|
2022-03-07 05:16:46 +09:00
|
|
|
$client->request('GET', '/object/note/1/attachment/asd');
|
2021-08-04 02:53:58 +09:00
|
|
|
$this->assertResponseStatusCodeSame(404);
|
2022-03-07 05:16:46 +09:00
|
|
|
$client->request('GET', '/object/note/1/attachment/0');
|
2021-08-04 02:53:58 +09:00
|
|
|
// 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
|
2022-03-07 05:16:46 +09:00
|
|
|
$this->assertResponseStatusCodeSame(500); // TODO (exception page) 404
|
|
|
|
$this->assertSelectorTextContains('.stacktrace', 'No such attachment.');
|
2021-08-04 02:53:58 +09:00
|
|
|
}
|
|
|
|
|
2021-08-17 01:11:05 +09:00
|
|
|
private function testAttachment(string $suffix = '')
|
2021-08-04 02:53:58 +09:00
|
|
|
{
|
2022-03-07 05:16:46 +09:00
|
|
|
$client = static::createClient();
|
|
|
|
$attachment_id = DB::findOneBy(Attachment::class, ['filehash' => '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea'])->getId();
|
|
|
|
$note_id = DB::findOneBy(AttachmentToNote::class, ['attachment_id' => $attachment_id])->getNoteId();
|
|
|
|
$crawler = $client->request('GET', "/object/note/{$note_id}/attachment/{$attachment_id}{$suffix}");
|
2021-08-04 02:53:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAttachmentShow()
|
|
|
|
{
|
2021-08-17 01:11:05 +09:00
|
|
|
$this->testAttachment();
|
2021-08-04 02:53:58 +09:00
|
|
|
$this->assertResponseIsSuccessful();
|
2022-03-07 05:16:46 +09:00
|
|
|
$this->assertSelectorTextContains('figure figcaption', 'image.jpg');
|
2021-08-04 02:53:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAttachmentView()
|
|
|
|
{
|
|
|
|
$this->testAttachment('/view');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAttachmentDownload()
|
|
|
|
{
|
|
|
|
$this->testAttachment('/download');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
}
|
|
|
|
|
2021-10-29 02:05:28 +09:00
|
|
|
public function testAttachmentThumbnailSmall()
|
|
|
|
{
|
|
|
|
$this->testAttachment('/thumbnail/small');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
}
|
2021-08-04 02:53:58 +09:00
|
|
|
|
2021-10-29 02:05:28 +09:00
|
|
|
public function testAttachmentThumbnailMedium()
|
2021-08-04 02:53:58 +09:00
|
|
|
{
|
2021-10-29 02:05:28 +09:00
|
|
|
$this->testAttachment('/thumbnail/medium');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAttachmentThumbnailBig()
|
|
|
|
{
|
|
|
|
$this->testAttachment('/thumbnail/big');
|
|
|
|
$this->assertResponseIsSuccessful();
|
2021-08-04 02:53:58 +09:00
|
|
|
}
|
|
|
|
}
|