|
|
|
@ -60,4 +60,130 @@ class NoteAttachmentTest extends TestCase
|
|
|
|
$valid = Helpers::verifyAttachments($this->invalidMime);
|
|
|
|
$valid = Helpers::verifyAttachments($this->invalidMime);
|
|
|
|
$this->assertFalse($valid);
|
|
|
|
$this->assertFalse($valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Compacted (single JSON-LD object instead of a one-item array) attachments (#6588) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function compacted_create_note_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = $activity['object']['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$valid = Helpers::verifyAttachments($activity);
|
|
|
|
|
|
|
|
$this->assertTrue($valid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function compacted_bare_note_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->pixelfed;
|
|
|
|
|
|
|
|
$activity['attachment'] = $activity['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$valid = Helpers::verifyAttachments($activity);
|
|
|
|
|
|
|
|
$this->assertTrue($valid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function compacted_invalid_attachment_type()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->invalidType;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = $activity['object']['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$valid = Helpers::verifyAttachments($activity);
|
|
|
|
|
|
|
|
$this->assertFalse($valid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function compacted_invalid_mime_type()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->invalidMime;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = $activity['object']['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$valid = Helpers::verifyAttachments($activity);
|
|
|
|
|
|
|
|
$this->assertFalse($valid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_returns_list_for_compacted_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = $activity['object']['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$attachments = Helpers::getAttachments($activity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $attachments);
|
|
|
|
|
|
|
|
$this->assertSame('Document', $attachments[0]['type']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Additional edge cases ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_preserves_list_form()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// A normal array-form attachment list must pass through unchanged.
|
|
|
|
|
|
|
|
$attachments = Helpers::getAttachments($this->pleroma);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertCount(2, $attachments);
|
|
|
|
|
|
|
|
$this->assertSame('Document', $attachments[0]['type']);
|
|
|
|
|
|
|
|
$this->assertSame('Document', $attachments[1]['type']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_returns_empty_for_bare_input()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Bare Note (no "object" wrapper) with a compacted attachment normalizes to one item.
|
|
|
|
|
|
|
|
$activity = $this->pixelfed;
|
|
|
|
|
|
|
|
$activity['attachment'] = $activity['attachment'][0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$attachments = Helpers::getAttachments($activity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $attachments);
|
|
|
|
|
|
|
|
$this->assertSame('Image', $attachments[0]['type']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_returns_empty_when_missing()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
unset($activity['object']['attachment']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertSame([], Helpers::getAttachments($activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_returns_empty_when_empty_array()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertSame([], Helpers::getAttachments($activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function get_attachments_returns_empty_for_scalar_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// A non-array attachment (e.g. a bare URL string) must not blow up.
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = 'https://example.org/not-an-object.jpg';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertSame([], Helpers::getAttachments($activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function verify_attachments_false_for_missing_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
unset($activity['object']['attachment']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(Helpers::verifyAttachments($activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
|
|
|
public function verify_attachments_false_for_scalar_attachment()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$activity = $this->mastodon;
|
|
|
|
|
|
|
|
$activity['object']['attachment'] = 'https://example.org/not-an-object.jpg';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(Helpers::verifyAttachments($activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|