-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By: Andreas Hofmann <andreas.hofmann@check24.de>
- Loading branch information
Showing
8 changed files
with
185 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jeremeamia\Slack\BlockKit\Inputs; | ||
|
||
use Jeremeamia\Slack\BlockKit\Exception; | ||
use Jeremeamia\Slack\BlockKit\Partials\HasOptions; | ||
|
||
class OverflowMenu extends InputElement | ||
{ | ||
use HasConfirm; | ||
use HasOptions; | ||
|
||
private const MIN_OPTIONS = 2; | ||
private const MAX_OPTIONS = 5; | ||
|
||
public function validate(): void | ||
{ | ||
|
||
$this->validateOptions(); | ||
|
||
if (!empty($this->confirm)) { | ||
$this->confirm->validate(); | ||
} | ||
|
||
if (count($this->options) > self::MAX_OPTIONS) { | ||
throw new Exception('Option Size cannot exceed %d', [self::MAX_OPTIONS]); | ||
} | ||
|
||
if (count($this->options) < self::MIN_OPTIONS) { | ||
throw new Exception('Option Size must be at least %d', [self::MIN_OPTIONS]); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
|
||
$data = parent::toArray(); | ||
$data += $this->getOptionsAsArray(); | ||
|
||
if (!empty($this->confirm)) { | ||
$data['confirm'] = $this->confirm->toArray(); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jeremeamia\Slack\BlockKit\Tests\Inputs; | ||
|
||
use Jeremeamia\Slack\BlockKit\Exception; | ||
use Jeremeamia\Slack\BlockKit\Inputs\OverflowMenu; | ||
use Jeremeamia\Slack\BlockKit\Partials\Confirm; | ||
use Jeremeamia\Slack\BlockKit\Tests\TestCase; | ||
use Jeremeamia\Slack\BlockKit\Type; | ||
|
||
/** | ||
* @covers \Jeremeamia\Slack\BlockKit\Inputs\OverflowMenu | ||
*/ | ||
class OverflowMenuTest extends TestCase | ||
{ | ||
public function testOverflowMenuWithConfirm() | ||
{ | ||
$input = (new OverflowMenu('overflow-identifier')) | ||
->option('foo', 'foo') | ||
->option('bar', 'bar') | ||
->option('foobar', 'foobar') | ||
->setConfirm(new Confirm('Choose', 'Do you really want to choose this?', 'Yes choose')); | ||
|
||
$this->assertJsonData([ | ||
'type' => Type::OVERFLOW_MENU, | ||
'action_id' => 'overflow-identifier', | ||
'options' => [ | ||
[ | ||
'text' => [ | ||
'type' => 'plain_text', | ||
'text' => 'foo', | ||
], | ||
'value' => 'foo', | ||
], | ||
[ | ||
'text' => [ | ||
'type' => 'plain_text', | ||
'text' => 'bar', | ||
], | ||
'value' => 'bar', | ||
], | ||
[ | ||
'text' => [ | ||
'type' => 'plain_text', | ||
'text' => 'foobar', | ||
], | ||
'value' => 'foobar', | ||
], | ||
], | ||
'confirm' => [ | ||
'title' => [ | ||
'type' => 'plain_text', | ||
'text' => 'Choose', | ||
], | ||
'text' => [ | ||
'type' => 'mrkdwn', | ||
'text' => 'Do you really want to choose this?', | ||
], | ||
'confirm' => [ | ||
'type' => 'plain_text', | ||
'text' => 'Yes choose', | ||
], | ||
'deny' => [ | ||
'type' => 'plain_text', | ||
'text' => 'Cancel', | ||
], | ||
] | ||
], $input); | ||
} | ||
|
||
public function testTooManyOptions() | ||
{ | ||
$this->expectException(Exception::class); | ||
$input = (new OverflowMenu()) | ||
->option('foo', 'foo') | ||
->option('foo', 'foo') | ||
->option('foo', 'foo') | ||
->option('foo', 'foo') | ||
->option('foo', 'foo') | ||
->option('foo', 'foo'); | ||
$input->validate(); | ||
} | ||
|
||
public function testTooFewOptions() | ||
{ | ||
$this->expectException(Exception::class); | ||
$input = (new OverflowMenu()) | ||
->option('foo', 'foo'); | ||
$input->validate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters