From 84b97f7cd187cd1b357b9dbdf7e848d236864525 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 12 Mar 2015 20:01:41 +0100 Subject: [PATCH] Add support for attachment's title and title link --- src/Attachment.php | 68 +++++++++++++++++++++++++++++++++- tests/AttachmentUnitTest.php | 2 + tests/ClientFunctionalTest.php | 6 ++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/Attachment.php b/src/Attachment.php index 82c3659..d22607a 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -32,6 +32,20 @@ class Attachment { */ protected $pretext; + /** + * Optional title for the attachment + * + * @var string + */ + protected $title; + + /** + * Optional title link for the attachment + * + * @var string + */ + protected $title_link; + /** * The color to use for the attachment * @@ -75,6 +89,10 @@ public function __construct(array $attributes) if (isset($attributes['fields'])) $this->setFields($attributes['fields']); if (isset($attributes['mrkdwn_in'])) $this->setMarkdownFields($attributes['mrkdwn_in']); + + if (isset($attributes['title'])) $this->setTitle($attributes['title']); + + if (isset($attributes['title_link'])) $this->setTitleLink($attributes['title_link']); } /** @@ -193,6 +211,52 @@ public function setColor($color) } /** + * Get the title to use for the attachment + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set the title to use for the attachment + * + * @param string $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get the title link to use for the attachment + * + * @return string + */ + public function getTitleLink() + { + return $this->title_link; + } + + /** + * Set the title link to use for the attachment + * + * @param string $title_link + * @return void + */ + public function setTitleLink($title_link) + { + $this->title_link = $title_link; + + return $this; + } + + /** * Get the fields for the attachment * * @return array @@ -295,7 +359,9 @@ public function toArray() 'pretext' => $this->getPretext(), 'color' => $this->getColor(), 'mrkdwn_in' => $this->getMarkdownFields(), - 'image_url' => $this->getImageUrl() + 'image_url' => $this->getImageUrl(), + 'title' => $this->getTitle(), + 'title_link' => $this->getTitleLink() ]; $data['fields'] = $this->getFieldsAsArrays(); diff --git a/tests/AttachmentUnitTest.php b/tests/AttachmentUnitTest.php index 356b2dc..5e82deb 100644 --- a/tests/AttachmentUnitTest.php +++ b/tests/AttachmentUnitTest.php @@ -67,6 +67,8 @@ public function testAttachmentToArray() 'color' => 'bad', 'mrkdwn_in' => ['pretext', 'text'], 'image_url' => 'http://fake.host/image.png', + 'title' => 'A title', + 'title_link' => 'http://fake.host/', 'fields' => [ [ 'title' => 'Title 1', diff --git a/tests/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php index dd9840d..adcf7af 100644 --- a/tests/ClientFunctionalTest.php +++ b/tests/ClientFunctionalTest.php @@ -36,7 +36,9 @@ public function testMessageWithAttachments() 'color' => 'bad', 'mrkdwn_in' => ['pretext', 'text'], 'image_url' => 'http://fake.host/image.png', - 'fields' => [] + 'fields' => [], + 'title' => null, + 'title_link' => null ]; $expectedHttpData = [ @@ -75,6 +77,8 @@ public function testMessageWithAttachmentsAndFields() 'color' => 'bad', 'mrkdwn_in' => [], 'image_url' => 'http://fake.host/image.png', + 'title' => 'A title', + 'title_link' => 'http://fake.host/', 'fields' => [ [ 'title' => 'Field 1',