getPagination(5); $output = LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel' => true, 'lastPageLabel' => true, ]); $this->assertStringContainsString('
  • 1
  • ', $output); $this->assertStringContainsString('
  • 25
  • ', $output); $output = LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel' => 'First', 'lastPageLabel' => 'Last', ]); $this->assertStringContainsString('
  • First
  • ', $output); $this->assertStringContainsString('
  • Last
  • ', $output); $output = LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel' => false, 'lastPageLabel' => false, ]); $this->assertStringNotContainsString('
  • ', $output); $this->assertStringNotContainsString('
  • ', $output); } public function testDisabledPageElementOptions() { $output = LinkPager::widget([ 'pagination' => $this->getPagination(0), 'disabledListItemSubTagOptions' => ['class' => ['foo-bar']], ]); $this->assertStringContainsString('
  • 6
  • ', $output); $output = LinkPager::widget([ 'pagination' => $pagination, 'disableCurrentPageButton' => true, ]); $this->assertStringContainsString('
  • 6
  • ', $output); } public function testOptionsWithTagOption() { LinkPager::$counter = 0; $output = LinkPager::widget([ 'pagination' => $this->getPagination(5), 'options' => [ 'tag' => 'div', ], ]); $this->assertTrue(StringHelper::startsWith($output, '
    ')); $this->assertTrue(StringHelper::endsWith($output, '
    ')); } public function testLinkWrapOptions() { $output = LinkPager::widget([ 'pagination' => $this->getPagination(1), 'linkContainerOptions' => [ 'tag' => 'div', 'class' => 'my-class', ], ]); $this->assertStringContainsString( '
    3
    ', $output ); $this->assertStringContainsString( '
    2
    ', $output ); } /** * @see https://github.com/yiisoft/yii2/issues/15536 */ public function testShouldTriggerInitEvent() { $initTriggered = false; LinkPager::widget([ 'pagination' => $this->getPagination(1), 'on init' => function () use (&$initTriggered) { $initTriggered = true; } ]); $this->assertTrue($initTriggered); } protected function setUp(): void { parent::setUp(); $this->mockWebApplication([ 'components' => [ 'urlManager' => [ 'scriptUrl' => '/', ], ], ]); } /** * Get pagination. * @param int $page * @return Pagination */ private function getPagination($page) { $pagination = new Pagination(); $pagination->setPage($page); $pagination->totalCount = 500; $pagination->route = 'test'; return $pagination; } }