Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL button support webview_share_button #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions spec/Model/Button/WebUrlSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function it_has_a_webview_height_ratio()
$this->getWebviewHeightRatio()->shouldReturn(WebUrl::HEIGHT_RATIO_FULL);
}

function it_has_a_webview_share_button()
{
$this->getWebviewShareButton()->shouldReturn(WebUrl::WEBVIEW_SHARE_BUTTON_SHOW);
}

function it_not_using_messenger_extensions()
{
$this->useMessengerExtensions()->shouldReturn(false);
Expand All @@ -59,6 +64,12 @@ function its_webview_height_ratio_is_mutable()
$this->getWebviewHeightRatio()->shouldReturn(WebUrl::HEIGHT_RATIO_TALL);
}

function its_webview_share_button_is_mutable()
{
$this->setWebviewShareButton(WebUrl::WEBVIEW_SHARE_BUTTON_HIDE);
$this->getWebviewShareButton()->shouldReturn(WebUrl::WEBVIEW_SHARE_BUTTON_HIDE);
}

function its_messenger_extensions_is_mutable()
{
$this->setMessengerExtensions(true);
Expand Down Expand Up @@ -87,6 +98,7 @@ function it_should_be_serializable()
'title' => 'title',
'url' => 'http://www.google.com',
'webview_height_ratio' => 'full',
'webview_share_button' => 'show'
];

$this->jsonSerialize()->shouldBeLike($expected);
Expand All @@ -102,6 +114,7 @@ function it_should_be_full_serializable()
'title' => 'title',
'url' => 'http://www.google.com',
'webview_height_ratio' => 'full',
'webview_share_button' => 'show',
'messenger_extensions' => true,
'fallback_url' => 'fallback url',
];
Expand Down
43 changes: 43 additions & 0 deletions src/Model/Button/WebUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class WebUrl extends Button
const HEIGHT_RATIO_COMPACT = 'compact';
const HEIGHT_RATIO_TALL = 'tall';

const WEBVIEW_SHARE_BUTTON_SHOW = 'show';
const WEBVIEW_SHARE_BUTTON_HIDE = 'hide';

/**
* @var string
*/
Expand All @@ -35,6 +38,11 @@ class WebUrl extends Button
*/
public $fallbackUrl;

/**
* @var string
*/
private $webviewShareButton = self::WEBVIEW_SHARE_BUTTON_SHOW;

/**
* @param string $title
* @param string $url
Expand Down Expand Up @@ -116,6 +124,26 @@ public function useMessengerExtensions()
return $this->messengerExtensions;
}

/**
* @param $value
*/
public function setWebviewShareButton($value)
{
if (!in_array($value, $this->getAllowedWebviewShareButton())) {
throw new \InvalidArgumentException(sprintf('Webview share button must be one of this values: [%s]', implode(', ', $this->getAllowedWebviewShareButton())));
}

$this->webviewShareButton = $value;
}

/**
* @return string|null
*/
public function getWebviewShareButton()
{
return $this->webviewShareButton;
}

/**
* @inheritdoc
*/
Expand All @@ -130,6 +158,10 @@ public function jsonSerialize()
$json['webview_height_ratio'] = $this->webviewHeightRatio;
}

if (!empty($this->webviewShareButton)) {
$json['webview_share_button'] = $this->webviewShareButton;
}

if ($this->messengerExtensions) {
$json['messenger_extensions'] = $this->messengerExtensions;
}
Expand All @@ -152,4 +184,15 @@ private function getAllowedHeights()
self::HEIGHT_RATIO_TALL
];
}

/**
* @return string[]
*/
private function getAllowedWebviewShareButton()
{
return [
self::WEBVIEW_SHARE_BUTTON_SHOW,
self::WEBVIEW_SHARE_BUTTON_HIDE
];
}
}