-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonTest.php
More file actions
108 lines (91 loc) · 3.35 KB
/
ButtonTest.php
File metadata and controls
108 lines (91 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
use PHPUnit\Framework\TestCase;
use Kiwari\Model\Button;
class ButtonTest extends TestCase
{
public function testGivenNullLabelThenShowError(): void
{
$this->expectException(\InvalidArgumentException::class);
Button::create()
->setLabel(null);
}
public function testGivenLabelThenGetLabelAndDefaultMethodDefaultType(): void
{
$label = 'Hello World';
$btn = Button::create()
->setLabel($label);
$this->assertEquals($btn->getLabel(), $label);
$this->assertEquals($btn->getMethod(), Button::METHOD_GET);
$this->assertEquals($btn->getType(), Button::TYPE_LINK);
$this->assertEquals($btn->getUrl(), null);
$this->assertEquals($btn->getPayload(), null);
}
public function testGivenLabelMethodPostTypePostBackPayload(): void
{
$label = 'Order Here';
$payload = [
'product' => [
'id' => 1,
'name' => 'chair',
'price' => 400000,
'qty' => 10
],
'payment' => 'BCA'
];
$btn = Button::create()
->setLabel($label)
->setMethod(Button::METHOD_POST)
->setType(Button::TYPE_POSTBACK)
->setPayload($payload);
$this->assertEquals($btn->getLabel(), $label);
$this->assertEquals($btn->getMethod(), Button::METHOD_POST);
$this->assertEquals($btn->getType(), Button::TYPE_POSTBACK);
$this->assertEquals($btn->getUrl(), null);
$this->assertEquals($btn->getPayload(), $payload);
}
public function testGivenAllPropsThenExpectJson(): void
{
$label = 'Order Now!';
$payload = [
'product' => [
'id' => 23,
'name' => 'yamaha psr 3000',
'price' => 10000000,
'qty' => 1
],
'payment' => 'Mandiri'
];
$btn = Button::create()
->setLabel($label)
->setMethod(Button::METHOD_POST)
->setType(Button::TYPE_POSTBACK)
->setPayload($payload);
$this->assertEquals($btn->getLabel(), $label);
$this->assertEquals($btn->getMethod(), Button::METHOD_POST);
$this->assertEquals($btn->getType(), Button::TYPE_POSTBACK);
$this->assertEquals($btn->getUrl(), null);
$this->assertEquals($btn->getPayload(), $payload);
$this->assertEquals(json_encode($btn), json_encode([
'label' => $label,
'type' => Button::TYPE_POSTBACK,
'payload' => [
'url' => null,
'method' => Button::METHOD_POST,
'payload' => $payload
],
]));
}
public function testGivenUrlThenShowDefaultWithLink(): void
{
$label = 'Go to Facebook';
$url = 'https://www.facebook.com';
$btn = Button::create()
->setLabel($label)
->setUrl($url);
$this->assertEquals($btn->getLabel(), $label);
$this->assertEquals($btn->getMethod(), Button::METHOD_GET);
$this->assertEquals($btn->getType(), Button::TYPE_LINK);
$this->assertEquals($btn->getUrl(), $url);
$this->assertEquals($btn->getPayload(), null);
}
}