[COMPONENT][Attachment][TESTS] Fix Controller/AttachmentTest
This commit is contained in:
parent
808a3b219e
commit
416665d830
|
@ -21,10 +21,12 @@ declare(strict_types = 1);
|
|||
|
||||
// }}}
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
namespace Component\Attachment\tests\Controller;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Util\GNUsocialTestCase;
|
||||
use Component\Attachment\Entity\Attachment;
|
||||
use Component\Attachment\Entity\AttachmentToNote;
|
||||
|
||||
class AttachmentTest extends GNUsocialTestCase
|
||||
{
|
||||
|
@ -32,31 +34,33 @@ class AttachmentTest extends GNUsocialTestCase
|
|||
{
|
||||
// This calls static::bootKernel(), and creates a "client" that is acting as the browser
|
||||
$client = static::createClient();
|
||||
$client->request('GET', '/attachment');
|
||||
//$client->request('GET', '/attachment');
|
||||
//$this->assertResponseStatusCodeSame(404);
|
||||
$client->request('GET', '/object/note/1/attachment/-1');
|
||||
$this->assertResponseStatusCodeSame(404);
|
||||
$client->request('GET', '/attachment/-1');
|
||||
$client->request('GET', '/object/note/1/attachment/asd');
|
||||
$this->assertResponseStatusCodeSame(404);
|
||||
$client->request('GET', '/attachment/asd');
|
||||
$this->assertResponseStatusCodeSame(404);
|
||||
$client->request('GET', '/attachment/0');
|
||||
$client->request('GET', '/object/note/1/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');
|
||||
$this->assertResponseStatusCodeSame(500); // TODO (exception page) 404
|
||||
$this->assertSelectorTextContains('.stacktrace', 'No such attachment.');
|
||||
}
|
||||
|
||||
private function testAttachment(string $suffix = '')
|
||||
{
|
||||
$client = static::createClient();
|
||||
$id = DB::findOneBy('attachment', ['filehash' => '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea'])->getId();
|
||||
$crawler = $client->request('GET', "/attachment/{$id}{$suffix}");
|
||||
$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}");
|
||||
}
|
||||
|
||||
public function testAttachmentShow()
|
||||
{
|
||||
$this->testAttachment();
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorTextContains('figure figcaption', '5d8ee7ead51a28803b4ee5cb2306a0b90b6ba570f1e5bcc2209926f6ab08e7ea');
|
||||
$this->assertSelectorTextContains('figure figcaption', 'image.jpg');
|
||||
}
|
||||
|
||||
public function testAttachmentView()
|
||||
|
@ -65,16 +69,6 @@ class AttachmentTest extends GNUsocialTestCase
|
|||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testAttachmentViewNotStored()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$last_attachment = DB::findBy('attachment', [], order_by: ['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');
|
|
@ -324,7 +324,8 @@ class Note extends Entity
|
|||
|
||||
public function getRenderedSplit(): array
|
||||
{
|
||||
return preg_split('/(<\s*p\s*\/?>)|(<\s*br\s*\/?>)|(\s\s+)|(<\s*\/p\s*\/?>)/', $this->getRendered(), -1, PREG_SPLIT_NO_EMPTY);
|
||||
$rendered = $this->getRendered();
|
||||
return is_null($rendered) ? [] : preg_split('/(<\s*p\s*\/?>)|(<\s*br\s*\/?>)|(\s\s+)|(<\s*\/p\s*\/?>)/', $rendered, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
public static function getAllNotesByActor(Actor $actor): array
|
||||
|
|
Loading…
Reference in New Issue
Block a user