1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\View; |
4
|
|
|
|
5
|
|
|
use Pagerfanta\View\TelegramInlineView; |
6
|
|
|
|
7
|
|
|
class TelegramInlineViewTest extends ViewTestCase |
8
|
|
|
{ |
9
|
|
|
protected function createView() |
10
|
|
|
{ |
11
|
|
|
return new TelegramInlineView(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function testRenderNormal() |
15
|
|
|
{ |
16
|
|
|
$this->setNbPages(100); |
17
|
|
|
$this->setCurrentPage(10); |
18
|
|
|
|
19
|
|
|
$options = array(); |
20
|
|
|
|
21
|
|
|
$this->assertRenderedView(<<<EOF |
22
|
|
|
{"inline_keyboard":[[{"text":"1","callback_data":"|1|"},{"text":"8","callback_data":"|8|"},{"text":"9","callback_data":"|9|"},{"text":"· 10 ·","callback_data":"|10|"},{"text":"11","callback_data":"|11|"},{"text":"12","callback_data":"|12|"},{"text":"12 ›","callback_data":"|12|"},{"text":"100 »","callback_data":"|100|"}]]} |
23
|
|
|
EOF |
24
|
|
|
, $this->renderView($options)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testRenderFirstPage() |
28
|
|
|
{ |
29
|
|
|
$this->setNbPages(100); |
30
|
|
|
$this->setCurrentPage(1); |
31
|
|
|
|
32
|
|
|
$options = array(); |
33
|
|
|
|
34
|
|
|
$this->assertRenderedView(<<<EOF |
35
|
|
|
{"inline_keyboard":[[{"text":"· 1 ·","callback_data":"|1|"},{"text":"2","callback_data":"|2|"},{"text":"3","callback_data":"|3|"},{"text":"4","callback_data":"|4|"},{"text":"5","callback_data":"|5|"},{"text":"6","callback_data":"|6|"},{"text":"7","callback_data":"|7|"},{"text":"8","callback_data":"|8|"},{"text":"9","callback_data":"|9|"},{"text":"10","callback_data":"|10|"},{"text":"11 ›","callback_data":"|11|"},{"text":"100 »","callback_data":"|100|"}]]} |
36
|
|
|
EOF |
37
|
|
|
, $this->renderView($options)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testRenderLastPage() |
41
|
|
|
{ |
42
|
|
|
$this->setNbPages(100); |
43
|
|
|
$this->setCurrentPage(100); |
44
|
|
|
|
45
|
|
|
$options = array(); |
46
|
|
|
|
47
|
|
|
$this->assertRenderedView(<<<EOF |
48
|
|
|
{"inline_keyboard":[[{"text":"« 1","callback_data":"|1|"},{"text":"‹ 95","callback_data":"|95|"},{"text":"97","callback_data":"|97|"},{"text":"98","callback_data":"|98|"},{"text":"99","callback_data":"|99|"}]]} |
49
|
|
|
EOF |
50
|
|
|
, $this->renderView($options)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testRenderWhenStartProximityIs2() |
54
|
|
|
{ |
55
|
|
|
$this->setNbPages(100); |
56
|
|
|
$this->setCurrentPage(4); |
57
|
|
|
|
58
|
|
|
$options = array(); |
59
|
|
|
|
60
|
|
|
$this->assertRenderedView(<<<EOF |
61
|
|
|
{"inline_keyboard":[[{"text":"1","callback_data":"|1|"},{"text":"2","callback_data":"|2|"},{"text":"3","callback_data":"|3|"},{"text":"· 4 ·","callback_data":"|4|"},{"text":"5","callback_data":"|5|"},{"text":"6","callback_data":"|6|"},{"text":"7 ›","callback_data":"|7|"},{"text":"100 »","callback_data":"|100|"}]]} |
62
|
|
|
EOF |
63
|
|
|
, $this->renderView($options)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testRenderWhenStartProximityIs3() |
67
|
|
|
{ |
68
|
|
|
$this->setNbPages(100); |
69
|
|
|
$this->setCurrentPage(5); |
70
|
|
|
|
71
|
|
|
$options = array(); |
72
|
|
|
|
73
|
|
|
$this->assertRenderedView(<<<EOF |
74
|
|
|
{"inline_keyboard":[[{"text":"1","callback_data":"|1|"},{"text":"3","callback_data":"|3|"},{"text":"4","callback_data":"|4|"},{"text":"· 5 ·","callback_data":"|5|"},{"text":"6","callback_data":"|6|"},{"text":"7","callback_data":"|7|"},{"text":"8 ›","callback_data":"|8|"},{"text":"100 »","callback_data":"|100|"}]]} |
75
|
|
|
EOF |
76
|
|
|
, $this->renderView($options)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testRenderWhenEndProximityIs2FromLast() |
80
|
|
|
{ |
81
|
|
|
$this->setNbPages(100); |
82
|
|
|
$this->setCurrentPage(97); |
83
|
|
|
|
84
|
|
|
$options = array(); |
85
|
|
|
|
86
|
|
|
$this->assertRenderedView(<<<EOF |
87
|
|
|
{"inline_keyboard":[[{"text":"« 1","callback_data":"|1|"},{"text":"‹ 94","callback_data":"|94|"},{"text":"96","callback_data":"|96|"},{"text":"· 97 ·","callback_data":"|97|"},{"text":"98","callback_data":"|98|"},{"text":"99","callback_data":"|99|"},{"text":"100","callback_data":"|100|"}]]} |
88
|
|
|
EOF |
89
|
|
|
, $this->renderView($options)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testRenderWhenEndProximityIs3FromLast() |
93
|
|
|
{ |
94
|
|
|
$this->setNbPages(100); |
95
|
|
|
$this->setCurrentPage(96); |
96
|
|
|
|
97
|
|
|
$options = array(); |
98
|
|
|
|
99
|
|
|
$this->assertRenderedView(<<<EOF |
100
|
|
|
{"inline_keyboard":[[{"text":"« 1","callback_data":"|1|"},{"text":"‹ 93","callback_data":"|93|"},{"text":"95","callback_data":"|95|"},{"text":"· 96 ·","callback_data":"|96|"},{"text":"97","callback_data":"|97|"},{"text":"98 ›","callback_data":"|98|"},{"text":"100","callback_data":"|100|"}]]} |
101
|
|
|
EOF |
102
|
|
|
, $this->renderView($options)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testRenderModifyingProximity() |
106
|
|
|
{ |
107
|
|
|
$this->setNbPages(100); |
108
|
|
|
$this->setCurrentPage(10); |
109
|
|
|
|
110
|
|
|
$options = array('proximity' => 3); |
111
|
|
|
|
112
|
|
|
$this->assertRenderedView(<<<EOF |
113
|
|
|
{"inline_keyboard":[[{"text":"1","callback_data":"|1|"},{"text":"7","callback_data":"|7|"},{"text":"8","callback_data":"|8|"},{"text":"9","callback_data":"|9|"},{"text":"· 10 ·","callback_data":"|10|"},{"text":"11","callback_data":"|11|"},{"text":"12","callback_data":"|12|"},{"text":"13","callback_data":"|13|"},{"text":"13 ›","callback_data":"|13|"},{"text":"100 »","callback_data":"|100|"}]]} |
114
|
|
|
EOF |
115
|
|
|
, $this->renderView($options)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testRenderModifyingPreviousAndNextTemplates() |
119
|
|
|
{ |
120
|
|
|
$this->setNbPages(100); |
121
|
|
|
$this->setCurrentPage(10); |
122
|
|
|
|
123
|
|
|
$options = array( |
124
|
|
|
'previous_template' => '< %text%', |
125
|
|
|
'next_template' => '%text% >', |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$this->assertRenderedView(<<<EOF |
129
|
|
|
{"inline_keyboard":[[{"text":"1","callback_data":"|1|"},{"text":"8","callback_data":"|8|"},{"text":"9","callback_data":"|9|"},{"text":"· 10 ·","callback_data":"|10|"},{"text":"11","callback_data":"|11|"},{"text":"12","callback_data":"|12|"},{"text":"12 >","callback_data":"|12|"},{"text":"100 »","callback_data":"|100|"}]]} |
130
|
|
|
EOF |
131
|
|
|
, $this->renderView($options)); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testRenderModifiyingStringTemplate() |
135
|
|
|
{ |
136
|
|
|
$this->setNbPages(100); |
137
|
|
|
$this->setCurrentPage(1); |
138
|
|
|
|
139
|
|
|
$options = array( |
140
|
|
|
'first_page_template' => '<< %text%', |
141
|
|
|
'last_page_template' => '%text% >>', |
142
|
|
|
'previous_template' => '< %text%', |
143
|
|
|
'next_template' => '%text% >', |
144
|
|
|
'container_template' => '%pages%', |
145
|
|
|
'page_template' => '(%text%)', |
146
|
|
|
'current_template' => '| %text% |', |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$this->assertRenderedView(<<<EOF |
150
|
|
|
{"inline_keyboard":[[{"text":"(| 1 |)","callback_data":"|1|"},{"text":"(2)","callback_data":"|2|"},{"text":"(3)","callback_data":"|3|"},{"text":"(4)","callback_data":"|4|"},{"text":"(5)","callback_data":"|5|"},{"text":"(6)","callback_data":"|6|"},{"text":"(7)","callback_data":"|7|"},{"text":"(8)","callback_data":"|8|"},{"text":"(9)","callback_data":"|9|"},{"text":"(10)","callback_data":"|10|"},{"text":"(11 >)","callback_data":"|11|"},{"text":"(100 >>)","callback_data":"|100|"}]]} |
151
|
|
|
EOF |
152
|
|
|
, $this->renderView($options)); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|