Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/CL/Slack/Model/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,20 @@ class Attachment extends AbstractModel
*/
private $fallback;

/**
* @var string
*/
private $callbackId;

/**
* @var AttachmentField[]|ArrayCollection
*/
private $fields;

/**
* @var AttachmentAction[]|ArrayCollection
*/
private $actions;

/**
* @var Array
Expand All @@ -83,6 +93,7 @@ class Attachment extends AbstractModel
public function __construct()
{
$this->fields = new ArrayCollection();
$this->actions = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -199,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.
*/
Expand Down Expand Up @@ -278,4 +304,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;
}

}
125 changes: 125 additions & 0 deletions src/CL/Slack/Model/AttachmentAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <info@casleentfaar.com>
*
* 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 <syilmaz@e-sites.nl>
*
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ CL\Slack\Model\Attachment:
type: string
color:
type: string
callbackId:
type: string
fields:
type: ArrayCollection<CL\Slack\Model\AttachmentField>
actions:
type: ArrayCollection<CL\Slack\Model\AttachmentAction>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CL\Slack\Model\AttachmentAction:
properties:
name:
type: string
text:
type: string
type:
type: string
value:
type: string
style:
type: string
57 changes: 57 additions & 0 deletions tests/src/CL/Slack/Tests/Model/AttachmentActionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <info@casleentfaar.com>
*
* 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 <syilmaz@e-sites.nl>
*/
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());
}
}
16 changes: 16 additions & 0 deletions tests/src/CL/Slack/Tests/Model/AttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ protected function getModelData()
'fallback' => 'fallback text',
'text' => 'normal text',
'pre_text' => 'pre text',
'callback_id' => '123',
'fields' => [
[
'title' => 'foo',
'value' => 'bar',
'short' => false,
],
],
'actions' => [
[
'name' => 'foo',
'text' => 'bar',
'type' => 'fooType',
'value' => 'barValue',
'style' => 'fooStyle'
],
]
];
}

Expand All @@ -58,8 +68,14 @@ 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());
$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());
}
}
21 changes: 21 additions & 0 deletions tests/src/CL/Slack/Tests/Payload/ChatPostMessagePayloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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);

Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
],
],
],
]),
];
Expand Down