getPagination(5);
$output = LinkPager::widget([
'pagination' => $pagination,
'disableCurrentPageButton' => false,
]);
$this->assertContains('6', $output);
$output = LinkPager::widget([
'pagination' => $pagination,
'disableCurrentPageButton' => true,
]);
$this->assertContains('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->assertContains(
'',
$output
);
$this->assertContains(
'',
$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()
{
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;
}
}