@@ -50,9 +50,9 @@ public function testValidConstructor()
5050 $ this ->assertArrayHasKey ('items ' , $ data );
5151 $ this ->assertCount ($ this ->items_per_page , $ data ['items ' ]);
5252 $ this ->assertArrayHasKey ('keyboard ' , $ data );
53- $ this ->assertArrayHasKey (1 , $ data ['keyboard ' ][0 ]);
54- $ this ->assertArrayHasKey ('text ' , $ data ['keyboard ' ][0 ][1 ]);
55- $ this ->assertStringStartsWith ($ this ->command , $ data ['keyboard ' ][0 ][1 ]['callback_data ' ]);
53+ $ this ->assertArrayHasKey (0 , $ data ['keyboard ' ][0 ]);
54+ $ this ->assertArrayHasKey ('text ' , $ data ['keyboard ' ][0 ][0 ]);
55+ $ this ->assertStringStartsWith (" command= { $ this ->command }" , $ data ['keyboard ' ][0 ][0 ]['callback_data ' ]);
5656 }
5757
5858 /**
@@ -75,6 +75,20 @@ public function testEmptyItemsConstructor()
7575 $ ikp ->getPagination ();
7676 }
7777
78+ public function testCallbackDataParser ()
79+ {
80+ $ ikp = new InlineKeyboardPagination ($ this ->items , $ this ->command , $ this ->selected_page , $ this ->items_per_page );
81+ $ data = $ ikp ->getPagination ();
82+
83+ $ callback_data = $ ikp ::getParametersFromCallbackData ($ data ['keyboard ' ][0 ][0 ]['callback_data ' ]);
84+
85+ self ::assertSame ([
86+ 'command ' => $ this ->command ,
87+ 'currentPage ' => "$ this ->selected_page " ,
88+ 'nextPage ' => '1 ' , // because we're getting the button at position 0, which is page 1
89+ ], $ callback_data );
90+ }
91+
7892 public function testValidPagination ()
7993 {
8094 $ ikp = new InlineKeyboardPagination ($ this ->items , $ this ->command , $ this ->selected_page , $ this ->items_per_page );
@@ -105,6 +119,54 @@ public function testSetMaxButtons()
105119 self ::assertTrue (true );
106120 }
107121
122+ public function testForceButtonsCount ()
123+ {
124+ $ cbdata = 'command=%s¤tPage=%d&nextPage=%d ' ;
125+ $ command = 'cbdata ' ;
126+ $ ikp = new InlineKeyboardPagination (range (1 , 10 ), $ command , 1 , 1 );
127+
128+ // testing with 8 flexible buttons
129+ $ ikp ->setMaxButtons (8 , false );
130+
131+ self ::assertAllButtonPropertiesEqual ([
132+ ['· 1 · ' , '2 ' , '3 ' , '4 › ' , '5 › ' , '6 › ' , '7 › ' , '10 » ' ],
133+ ], 'text ' , $ ikp ->getPagination (1 )['keyboard ' ]);
134+
135+ self ::assertAllButtonPropertiesEqual ([
136+ ['« 1 ' , '‹ 4 ' , '· 5 · ' , '6 › ' , '10 » ' ],
137+ ], 'text ' , $ ikp ->getPagination (5 )['keyboard ' ]);
138+
139+ // testing with 8 fixed buttons
140+ $ ikp ->setMaxButtons (8 , true );
141+
142+ self ::assertAllButtonPropertiesEqual ([
143+ ['· 1 · ' , '2 ' , '3 ' , '4 › ' , '5 › ' , '6 › ' , '7 › ' , '10 » ' ],
144+ ], 'text ' , $ ikp ->getPagination (1 )['keyboard ' ]);
145+
146+ self ::assertAllButtonPropertiesEqual ([
147+ ['· 1 · ' , '2 ' , '3 ' , '4 › ' , '5 › ' , '6 › ' , '7 › ' , '10 » ' ],
148+ ], 'text ' , $ ikp ->getPagination (1 )['keyboard ' ]);
149+
150+ self ::assertAllButtonPropertiesEqual ([
151+ ['« 1 ' , '‹ 2 ' , '‹ 3 ' , '‹ 4 ' , '· 5 · ' , '6 › ' , '7 › ' , '10 » ' ],
152+ ], 'text ' , $ ikp ->getPagination (5 )['keyboard ' ]);
153+
154+ // testing with 7 fixed buttons
155+ $ ikp ->setMaxButtons (7 , true );
156+
157+ self ::assertAllButtonPropertiesEqual ([
158+ ['· 1 · ' , '2 ' , '3 ' , '4 › ' , '5 › ' , '6 › ' , '10 » ' ],
159+ ], 'text ' , $ ikp ->getPagination (1 )['keyboard ' ]);
160+
161+ self ::assertAllButtonPropertiesEqual ([
162+ ['« 1 ' , '‹ 3 ' , '‹ 4 ' , '· 5 · ' , '6 › ' , '7 › ' , '10 » ' ],
163+ ], 'text ' , $ ikp ->getPagination (5 )['keyboard ' ]);
164+
165+ self ::assertAllButtonPropertiesEqual ([
166+ ['« 1 ' , '‹ 5 ' , '‹ 6 ' , '‹ 7 ' , '8 ' , '9 ' , '· 10 · ' ],
167+ ], 'text ' , $ ikp ->getPagination (10 )['keyboard ' ]);
168+ }
169+
108170 /**
109171 * @expectedException \TelegramBot\InlineKeyboardPagination\Exceptions\InlineKeyboardPaginationException
110172 * @expectedExceptionMessage Invalid max buttons, must be between 5 and 8.
@@ -145,7 +207,7 @@ public function testInvalidItemsPerPage()
145207
146208 public function testButtonLabels ()
147209 {
148- $ cbdata = '%s? currentPage=%d&nextPage=%d ' ;
210+ $ cbdata = 'command=%s& currentPage=%d&nextPage=%d ' ;
149211 $ command = 'cbdata ' ;
150212 $ ikp1 = new InlineKeyboardPagination (range (1 , 1 ), $ command , 1 , $ this ->items_per_page );
151213 $ ikp10 = new InlineKeyboardPagination (range (1 , $ this ->items_per_page * 10 ), $ command , 1 , $ this ->items_per_page );
0 commit comments