From f2644deb5120c76a6c415c8dc05c6cb3a029dac5 Mon Sep 17 00:00:00 2001 From: Samet Yilmaz Date: Fri, 19 May 2017 11:23:27 +0200 Subject: [PATCH 1/5] Add attachment action so actions can be added --- src/CL/Slack/Model/Attachment.php | 23 ++++ src/CL/Slack/Model/AttachmentAction.php | 125 ++++++++++++++++++ .../serializer/CL.Slack.Model.Attachment.yml | 2 + .../CL.Slack.Model.AttachmentAction.yml | 12 ++ 4 files changed, 162 insertions(+) create mode 100644 src/CL/Slack/Model/AttachmentAction.php create mode 100644 src/CL/Slack/Resources/config/serializer/CL.Slack.Model.AttachmentAction.yml diff --git a/src/CL/Slack/Model/Attachment.php b/src/CL/Slack/Model/Attachment.php index 1307548b..66898fbe 100644 --- a/src/CL/Slack/Model/Attachment.php +++ b/src/CL/Slack/Model/Attachment.php @@ -74,6 +74,11 @@ class Attachment extends AbstractModel * @var AttachmentField[]|ArrayCollection */ private $fields; + + /** + * @var AttachmentAction[]|ArrayCollection + */ + private $actions; /** * @var Array @@ -278,4 +283,22 @@ public function getMrkdwnIn() { return $this->mrkdwnIn; } + + + /** + * @param AttachmentAction $action + */ + public function addAction(AttachmentAction $action) + { + $this->actions->add($action); + } + + /** + * @return AttachmentAction[]|ArrayCollection + */ + public function getActions() + { + return $this->actions; + } + } diff --git a/src/CL/Slack/Model/AttachmentAction.php b/src/CL/Slack/Model/AttachmentAction.php new file mode 100644 index 00000000..e553f503 --- /dev/null +++ b/src/CL/Slack/Model/AttachmentAction.php @@ -0,0 +1,125 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Model; + +/** + * @author Samet Yilmaz + * + * @link Official documentation at https://api.slack.com/docs/attachments + */ +class AttachmentAction extends AbstractModel +{ + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $text; + + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $value; + + /** + * @var string + */ + private $style; + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText($text) + { + $this->text = $text; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * @param string $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * @return string + */ + public function getStyle() + { + return $this->style; + } + + /** + * @param string $style + */ + public function setStyle($style) + { + $this->style = $style; + } +} diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml index 89ffe5a3..f154f4fc 100644 --- a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml @@ -14,3 +14,5 @@ CL\Slack\Model\Attachment: type: string fields: type: ArrayCollection + actions: + type: ArrayCollection diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.AttachmentAction.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.AttachmentAction.yml new file mode 100644 index 00000000..ff8733db --- /dev/null +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.AttachmentAction.yml @@ -0,0 +1,12 @@ +CL\Slack\Model\AttachmentAction: + properties: + name: + type: string + text: + type: string + type: + type: string + value: + type: string + style: + type: string From ec68b7fd7167ac8f971140edad8a9d5e050fa3bd Mon Sep 17 00:00:00 2001 From: Samet Yilmaz Date: Fri, 19 May 2017 13:15:59 +0200 Subject: [PATCH 2/5] Initialize actions --- src/CL/Slack/Model/Attachment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CL/Slack/Model/Attachment.php b/src/CL/Slack/Model/Attachment.php index 66898fbe..36a8a0c0 100644 --- a/src/CL/Slack/Model/Attachment.php +++ b/src/CL/Slack/Model/Attachment.php @@ -88,6 +88,7 @@ class Attachment extends AbstractModel public function __construct() { $this->fields = new ArrayCollection(); + $this->actions = new ArrayCollection(); } /** From 57a44c21e5ef832e497bf74a9971b48dd43a307c Mon Sep 17 00:00:00 2001 From: Samet Yilmaz Date: Fri, 19 May 2017 13:23:44 +0200 Subject: [PATCH 3/5] Update tests --- .../Tests/Model/AttachmentActionTest.php | 57 +++++++++++++++++++ .../CL/Slack/Tests/Model/AttachmentTest.php | 14 +++++ 2 files changed, 71 insertions(+) create mode 100644 tests/src/CL/Slack/Tests/Model/AttachmentActionTest.php diff --git a/tests/src/CL/Slack/Tests/Model/AttachmentActionTest.php b/tests/src/CL/Slack/Tests/Model/AttachmentActionTest.php new file mode 100644 index 00000000..6e722af2 --- /dev/null +++ b/tests/src/CL/Slack/Tests/Model/AttachmentActionTest.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Tests\Model; + +use CL\Slack\Model\AbstractModel; +use CL\Slack\Model\AttachmentAction; + +/** + * @author Samet Yilmaz + */ +class AttachmentActionTest extends AbstractModelTest +{ + /** + * @return array + */ + protected function getModelData() + { + return [ + 'name' => 'foo', + 'text' => 'bar', + 'type' => 'fooType', + 'value' => 'barValue', + 'style' => 'fooStyle' + ]; + } + + /** + * @return string + */ + protected function getModelClass() + { + return 'CL\Slack\Model\AttachmentAction'; + } + + /** + * @inheritdoc + * + * @param AttachmentAction $actualModel + */ + protected function assertModel(array $expectedData, AbstractModel $actualModel) + { + $this->assertEquals($expectedData['name'], $actualModel->getName()); + $this->assertEquals($expectedData['text'], $actualModel->getText()); + $this->assertEquals($expectedData['type'], $actualModel->getType()); + $this->assertEquals($expectedData['value'], $actualModel->getValue()); + $this->assertEquals($expectedData['style'], $actualModel->getStyle()); + } +} diff --git a/tests/src/CL/Slack/Tests/Model/AttachmentTest.php b/tests/src/CL/Slack/Tests/Model/AttachmentTest.php index 80dad4e8..a04f205c 100644 --- a/tests/src/CL/Slack/Tests/Model/AttachmentTest.php +++ b/tests/src/CL/Slack/Tests/Model/AttachmentTest.php @@ -36,6 +36,15 @@ protected function getModelData() 'short' => false, ], ], + 'actions' => [ + [ + 'name' => 'foo', + 'text' => 'bar', + 'type' => 'fooType', + 'value' => 'barValue', + 'style' => 'fooStyle' + ], + ] ]; } @@ -61,5 +70,10 @@ protected function assertModel(array $expectedData, AbstractModel $actualModel) $this->assertEquals($expectedData['fields'][0]['title'], $actualModel->getFields()->first()->getTitle()); $this->assertEquals($expectedData['fields'][0]['value'], $actualModel->getFields()->first()->getValue()); $this->assertEquals($expectedData['fields'][0]['short'], $actualModel->getFields()->first()->isShort()); + $this->assertEquals($expectedData['actions'][0]['name'], $actualModel->getActions()->first()->getName()); + $this->assertEquals($expectedData['actions'][0]['text'], $actualModel->getActions()->first()->getText()); + $this->assertEquals($expectedData['actions'][0]['type'], $actualModel->getActions()->first()->getType()); + $this->assertEquals($expectedData['actions'][0]['value'], $actualModel->getActions()->first()->getValue()); + $this->assertEquals($expectedData['actions'][0]['style'], $actualModel->getActions()->first()->getStyle()); } } From 1840d353b9ca8c02bed6546791a444b313c3054e Mon Sep 17 00:00:00 2001 From: Samet Yilmaz Date: Fri, 19 May 2017 13:28:00 +0200 Subject: [PATCH 4/5] Update ChatPostMessagePayloadTest --- .../Payload/ChatPostMessagePayloadTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/src/CL/Slack/Tests/Payload/ChatPostMessagePayloadTest.php b/tests/src/CL/Slack/Tests/Payload/ChatPostMessagePayloadTest.php index 13509ce8..7200fc00 100644 --- a/tests/src/CL/Slack/Tests/Payload/ChatPostMessagePayloadTest.php +++ b/tests/src/CL/Slack/Tests/Payload/ChatPostMessagePayloadTest.php @@ -12,6 +12,7 @@ namespace CL\Slack\Tests\Payload; use CL\Slack\Model\Attachment; +use CL\Slack\Model\AttachmentAction; use CL\Slack\Model\AttachmentField; use CL\Slack\Payload\ChatPostMessagePayload; use CL\Slack\Payload\PayloadInterface; @@ -43,6 +44,13 @@ protected function createPayload() $fakeAttachmentField->setTitle('the title'); $fakeAttachmentField->setValue('the value'); + $fakeAttachmentAction = new AttachmentAction(); + $fakeAttachmentAction->setName('the name'); + $fakeAttachmentAction->setText('the text'); + $fakeAttachmentAction->setType('the type'); + $fakeAttachmentAction->setValue('the value'); + $fakeAttachmentAction->setStyle('the style'); + $fakeAttachment = new Attachment(); $fakeAttachment->setTitle('the title'); $fakeAttachment->setTitleLink('http://thetitlelink.com'); @@ -55,6 +63,7 @@ protected function createPayload() $fakeAttachment->setAuthorName('the author'); $fakeAttachment->setAuthorLink('http://theauthor.com'); $fakeAttachment->addField($fakeAttachmentField); + $fakeAttachment->addAction($fakeAttachmentAction); $payload->addAttachment($fakeAttachment); @@ -74,6 +83,9 @@ protected function getExpectedPayloadData(PayloadInterface $payload) /** @var AttachmentField $attachmentField */ $attachmentField = $attachment->getFields()->first(); + /** @var AttachmentAction $attachmentAction */ + $attachmentAction = $attachment->getActions()->first(); + return [ 'channel' => $payload->getChannel(), 'text' => $payload->getText(), @@ -104,6 +116,15 @@ protected function getExpectedPayloadData(PayloadInterface $payload) 'short' => $attachmentField->isShort(), ], ], + 'actions' => [ + [ + 'name' => $attachmentAction->getName(), + 'text' => $attachmentAction->getText(), + 'type' => $attachmentAction->getType(), + 'value' => $attachmentAction->getValue(), + 'style' => $attachmentAction->getStyle(), + ], + ], ], ]), ]; From 6be32529ab1428df1e6683fa820d89a34c5fd687 Mon Sep 17 00:00:00 2001 From: Samet Yilmaz Date: Wed, 28 Jun 2017 17:34:32 +0200 Subject: [PATCH 5/5] Add callback_id field --- src/CL/Slack/Model/Attachment.php | 20 +++++++++++++++++++ .../serializer/CL.Slack.Model.Attachment.yml | 2 ++ .../CL/Slack/Tests/Model/AttachmentTest.php | 2 ++ 3 files changed, 24 insertions(+) diff --git a/src/CL/Slack/Model/Attachment.php b/src/CL/Slack/Model/Attachment.php index 36a8a0c0..7847b901 100644 --- a/src/CL/Slack/Model/Attachment.php +++ b/src/CL/Slack/Model/Attachment.php @@ -70,6 +70,11 @@ class Attachment extends AbstractModel */ private $fallback; + /** + * @var string + */ + private $callbackId; + /** * @var AttachmentField[]|ArrayCollection */ @@ -205,6 +210,21 @@ public function getFallback() return $this->fallback; } + /** + * @param string $callbackId Required if the attachment contains actions + */ + public function setCallbackId($callbackId) + { + $this->callbackId = $callbackId; + } + + /** + * @return string Returns the callback id + */ + public function getCallbackId() + { + return $this->callbackId; + } /** * @param string|null $preText Optional text that should appear above the formatted data. */ diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml index f154f4fc..d1b330c8 100644 --- a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Attachment.yml @@ -12,6 +12,8 @@ CL\Slack\Model\Attachment: type: string color: type: string + callbackId: + type: string fields: type: ArrayCollection actions: diff --git a/tests/src/CL/Slack/Tests/Model/AttachmentTest.php b/tests/src/CL/Slack/Tests/Model/AttachmentTest.php index a04f205c..0b2cdf5d 100644 --- a/tests/src/CL/Slack/Tests/Model/AttachmentTest.php +++ b/tests/src/CL/Slack/Tests/Model/AttachmentTest.php @@ -29,6 +29,7 @@ protected function getModelData() 'fallback' => 'fallback text', 'text' => 'normal text', 'pre_text' => 'pre text', + 'callback_id' => '123', 'fields' => [ [ 'title' => 'foo', @@ -67,6 +68,7 @@ protected function assertModel(array $expectedData, AbstractModel $actualModel) $this->assertEquals($expectedData['fallback'], $actualModel->getFallback()); $this->assertEquals($expectedData['pre_text'], $actualModel->getPreText()); $this->assertEquals($expectedData['text'], $actualModel->getText()); + $this->assertEquals($expectedData['callback_id'], $actualModel->getCallbackId()); $this->assertEquals($expectedData['fields'][0]['title'], $actualModel->getFields()->first()->getTitle()); $this->assertEquals($expectedData['fields'][0]['value'], $actualModel->getFields()->first()->getValue()); $this->assertEquals($expectedData['fields'][0]['short'], $actualModel->getFields()->first()->isShort());