@@ -54,51 +54,60 @@ public function testInlineKeyboardDataMalformedSubfield()
54
54
55
55
public function testInlineKeyboardSingleButtonSingleRow ()
56
56
{
57
- $ inline_keyboard = ( new InlineKeyboard (
57
+ $ keyboard = new InlineKeyboard (
58
58
$ this ->getRandomButton ('Button Text 1 ' )
59
- ))->getProperty ('inline_keyboard ' );
60
- self ::assertSame ('Button Text 1 ' , $ inline_keyboard [0 ][0 ]->getText ());
59
+ );
60
+ KeyboardTest::assertAllButtonPropertiesEqual ([
61
+ ['Button Text 1 ' ],
62
+ ], 'text ' , $ keyboard );
61
63
62
- $ inline_keyboard = ( new InlineKeyboard (
64
+ $ keyboard = new InlineKeyboard (
63
65
[$ this ->getRandomButton ('Button Text 2 ' )]
64
- ))->getProperty ('inline_keyboard ' );
65
- self ::assertSame ('Button Text 2 ' , $ inline_keyboard [0 ][0 ]->getText ());
66
+ );
67
+ KeyboardTest::assertAllButtonPropertiesEqual ([
68
+ ['Button Text 2 ' ],
69
+ ], 'text ' , $ keyboard );
66
70
}
67
71
68
72
public function testInlineKeyboardSingleButtonMultipleRows ()
69
73
{
70
- $ keyboard = ( new InlineKeyboard (
74
+ $ keyboard = new InlineKeyboard (
71
75
$ this ->getRandomButton ('Button Text 1 ' ),
72
76
$ this ->getRandomButton ('Button Text 2 ' ),
73
77
$ this ->getRandomButton ('Button Text 3 ' )
74
- ))->getProperty ('inline_keyboard ' );
75
- self ::assertSame ('Button Text 1 ' , $ keyboard [0 ][0 ]->getText ());
76
- self ::assertSame ('Button Text 2 ' , $ keyboard [1 ][0 ]->getText ());
77
- self ::assertSame ('Button Text 3 ' , $ keyboard [2 ][0 ]->getText ());
78
+ );
79
+ KeyboardTest::assertAllButtonPropertiesEqual ([
80
+ ['Button Text 1 ' ],
81
+ ['Button Text 2 ' ],
82
+ ['Button Text 3 ' ],
83
+ ], 'text ' , $ keyboard );
78
84
79
- $ keyboard = ( new InlineKeyboard (
85
+ $ keyboard = new InlineKeyboard (
80
86
[$ this ->getRandomButton ('Button Text 4 ' )],
81
87
[$ this ->getRandomButton ('Button Text 5 ' )],
82
88
[$ this ->getRandomButton ('Button Text 6 ' )]
83
- ))->getProperty ('inline_keyboard ' );
84
- self ::assertSame ('Button Text 4 ' , $ keyboard [0 ][0 ]->getText ());
85
- self ::assertSame ('Button Text 5 ' , $ keyboard [1 ][0 ]->getText ());
86
- self ::assertSame ('Button Text 6 ' , $ keyboard [2 ][0 ]->getText ());
89
+ );
90
+ KeyboardTest::assertAllButtonPropertiesEqual ([
91
+ ['Button Text 4 ' ],
92
+ ['Button Text 5 ' ],
93
+ ['Button Text 6 ' ],
94
+ ], 'text ' , $ keyboard );
87
95
}
88
96
89
97
public function testInlineKeyboardMultipleButtonsSingleRow ()
90
98
{
91
- $ keyboard = ( new InlineKeyboard ([
99
+ $ keyboard = new InlineKeyboard ([
92
100
$ this ->getRandomButton ('Button Text 1 ' ),
93
101
$ this ->getRandomButton ('Button Text 2 ' ),
94
- ]))->getProperty ('inline_keyboard ' );
95
- self ::assertSame ('Button Text 1 ' , $ keyboard [0 ][0 ]->getText ());
96
- self ::assertSame ('Button Text 2 ' , $ keyboard [0 ][1 ]->getText ());
102
+ ]);
103
+ KeyboardTest::assertAllButtonPropertiesEqual ([
104
+ ['Button Text 1 ' , 'Button Text 2 ' ],
105
+ ], 'text ' , $ keyboard );
97
106
}
98
107
99
108
public function testInlineKeyboardMultipleButtonsMultipleRows ()
100
109
{
101
- $ keyboard = ( new InlineKeyboard (
110
+ $ keyboard = new InlineKeyboard (
102
111
[
103
112
$ this ->getRandomButton ('Button Text 1 ' ),
104
113
$ this ->getRandomButton ('Button Text 2 ' ),
@@ -107,32 +116,107 @@ public function testInlineKeyboardMultipleButtonsMultipleRows()
107
116
$ this ->getRandomButton ('Button Text 3 ' ),
108
117
$ this ->getRandomButton ('Button Text 4 ' ),
109
118
]
110
- ))-> getProperty ( ' inline_keyboard ' ) ;
119
+ );
111
120
112
- self :: assertSame ( ' Button Text 1 ' , $ keyboard [ 0 ][ 0 ]-> getText ());
113
- self :: assertSame ( 'Button Text 2 ' , $ keyboard [ 0 ][ 1 ]-> getText ());
114
- self :: assertSame ( 'Button Text 3 ' , $ keyboard [ 1 ][ 0 ]-> getText ());
115
- self :: assertSame ( ' Button Text 4 ' , $ keyboard[ 1 ][ 1 ]-> getText () );
121
+ KeyboardTest:: assertAllButtonPropertiesEqual ([
122
+ [ 'Button Text 1 ' , ' Button Text 2 ' ],
123
+ [ 'Button Text 3 ' , ' Button Text 4 ' ],
124
+ ], ' text ' , $ keyboard );
116
125
}
117
126
118
127
public function testInlineKeyboardAddRows ()
119
128
{
120
- $ keyboard_obj = new InlineKeyboard ([]);
129
+ $ keyboard = new InlineKeyboard ([]);
121
130
122
- $ keyboard_obj ->addRow ($ this ->getRandomButton ('Button Text 1 ' ));
123
- $ keyboard = $ keyboard_obj ->getProperty ('inline_keyboard ' );
124
- self ::assertSame ('Button Text 1 ' , $ keyboard [0 ][0 ]->getText ());
131
+ $ keyboard ->addRow ($ this ->getRandomButton ('Button Text 1 ' ));
132
+ KeyboardTest::assertAllButtonPropertiesEqual ([
133
+ ['Button Text 1 ' ],
134
+ ], 'text ' , $ keyboard );
125
135
126
- $ keyboard_obj ->addRow (
136
+ $ keyboard ->addRow (
127
137
$ this ->getRandomButton ('Button Text 2 ' ),
128
138
$ this ->getRandomButton ('Button Text 3 ' )
129
139
);
130
- $ keyboard = $ keyboard_obj ->getProperty ('inline_keyboard ' );
131
- self ::assertSame ('Button Text 2 ' , $ keyboard [1 ][0 ]->getText ());
132
- self ::assertSame ('Button Text 3 ' , $ keyboard [1 ][1 ]->getText ());
140
+ KeyboardTest::assertAllButtonPropertiesEqual ([
141
+ ['Button Text 1 ' ],
142
+ ['Button Text 2 ' , 'Button Text 3 ' ],
143
+ ], 'text ' , $ keyboard );
144
+
145
+ $ keyboard ->addRow ($ this ->getRandomButton ('Button Text 4 ' ));
146
+ KeyboardTest::assertAllButtonPropertiesEqual ([
147
+ ['Button Text 1 ' ],
148
+ ['Button Text 2 ' , 'Button Text 3 ' ],
149
+ ['Button Text 4 ' ],
150
+ ], 'text ' , $ keyboard );
151
+ }
133
152
134
- $ keyboard_obj ->addRow ($ this ->getRandomButton ('Button Text 4 ' ));
135
- $ keyboard = $ keyboard_obj ->getProperty ('inline_keyboard ' );
136
- self ::assertSame ('Button Text 4 ' , $ keyboard [2 ][0 ]->getText ());
153
+ public function testInlineKeyboardPagination ()
154
+ {
155
+ // Should get '_page_%d' appended to it.
156
+ $ callback_data = 'pagination_callback ' ;
157
+
158
+ // current
159
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 1 , 1 );
160
+ KeyboardTest::assertAllButtonPropertiesEqual ([
161
+ ['· 1 · ' ],
162
+ ], 'text ' , $ keyboard );
163
+ KeyboardTest::assertAllButtonPropertiesEqual ([
164
+ ['pagination_callback_page_1 ' ],
165
+ ], 'callback_data ' , $ keyboard );
166
+
167
+ // Shorter custom callback data.
168
+ $ callback_data = 'p%d ' ;
169
+
170
+ // current, next, last
171
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 1 , 10 );
172
+ KeyboardTest::assertAllButtonPropertiesEqual ([
173
+ ['· 1 · ' , '2 › ' , '10 » ' ],
174
+ ], 'text ' , $ keyboard );
175
+ KeyboardTest::assertAllButtonPropertiesEqual ([
176
+ ['p1 ' , 'p2 ' , 'p10 ' ],
177
+ ], 'callback_data ' , $ keyboard );
178
+
179
+ // first, previous, current, next, last
180
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 5 , 10 );
181
+ KeyboardTest::assertAllButtonPropertiesEqual ([
182
+ ['« 1 ' , '‹ 4 ' , '· 5 · ' , '6 › ' , '10 » ' ],
183
+ ], 'text ' , $ keyboard );
184
+ KeyboardTest::assertAllButtonPropertiesEqual ([
185
+ ['p1 ' , 'p4 ' , 'p5 ' , 'p6 ' , 'p10 ' ],
186
+ ], 'callback_data ' , $ keyboard );
187
+
188
+ // first, previous, current, last
189
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 9 , 10 );
190
+ KeyboardTest::assertAllButtonPropertiesEqual ([
191
+ ['« 1 ' , '‹ 8 ' , '· 9 · ' , '10 » ' ],
192
+ ], 'text ' , $ keyboard );
193
+ KeyboardTest::assertAllButtonPropertiesEqual ([
194
+ ['p1 ' , 'p8 ' , 'p9 ' , 'p10 ' ],
195
+ ], 'callback_data ' , $ keyboard );
196
+
197
+ // first, previous, current
198
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 10 , 10 );
199
+ KeyboardTest::assertAllButtonPropertiesEqual ([
200
+ ['« 1 ' , '‹ 9 ' , '· 10 · ' ],
201
+ ], 'text ' , $ keyboard );
202
+ KeyboardTest::assertAllButtonPropertiesEqual ([
203
+ ['p1 ' , 'p9 ' , 'p10 ' ],
204
+ ], 'callback_data ' , $ keyboard );
205
+
206
+ // custom labels
207
+ // first, previous, current, next, last
208
+ $ keyboard = InlineKeyboard::getPagination ($ callback_data , 5 , 10 , [
209
+ 'first ' => 'first %d ' ,
210
+ 'previous ' => 'previous %d ' ,
211
+ 'current ' => 'cur %d rent ' ,
212
+ 'next ' => '%d next ' ,
213
+ 'last ' => '%d last ' ,
214
+ ]);
215
+ KeyboardTest::assertAllButtonPropertiesEqual ([
216
+ ['first 1 ' , 'previous 4 ' , 'cur 5 rent ' , '6 next ' , '10 last ' ],
217
+ ], 'text ' , $ keyboard );
218
+ KeyboardTest::assertAllButtonPropertiesEqual ([
219
+ ['p1 ' , 'p4 ' , 'p5 ' , 'p6 ' , 'p10 ' ],
220
+ ], 'callback_data ' , $ keyboard );
137
221
}
138
222
}
0 commit comments