Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
parse images
Browse files Browse the repository at this point in the history
  • Loading branch information
ElfSundae committed Sep 1, 2017
1 parent 14b9a8a commit 894a20c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Message.php
Expand Up @@ -417,7 +417,15 @@ public function attachments($attachments)
public function addAttachment($attachment)
{
if (! is_array($attachment)) {
$attachment = call_user_func_array([$this, 'getAttachmentPayload'], func_get_args());
$attachment = call_user_func_array(
[$this, 'getAttachmentPayload'],
func_get_args()
);
} elseif (
! empty($attachment['images']) &&
$images = $this->getImagesPayload($attachment['images'])
) {
$attachment['images'] = $images;
}

if (! empty($attachment)) {
Expand Down
9 changes: 9 additions & 0 deletions tests/MessageTest.php
Expand Up @@ -171,6 +171,15 @@ public function testAddAttachment()

$message = (new Message)->add('foo')->add('bar');
$this->assertEquals([['text' => 'foo'], ['text' => 'bar']], $message->getAttachments());

$message = (new Message)->add(['images' => 'img']);
$this->assertEquals([['images' => [['url' => 'img']]]], $message->getAttachments());

$message = (new Message)->add(['images' => ['img', 'img1']]);
$this->assertEquals([['images' => [['url' => 'img'], ['url' => 'img1']]]], $message->getAttachments());

$message = (new Message)->add(['images' => ['url' => 'img']]);
$this->assertEquals([['images' => [['url' => 'img']]]], $message->getAttachments());
}

public function testMergeAttachmentDefaults()
Expand Down

0 comments on commit 894a20c

Please sign in to comment.