PagerExampleTest.php in Examples for Developers 8
File
pager_example/tests/src/Functional/PagerExampleTest.php
View source
<?php
namespace Drupal\Tests\pager_example\Functional;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
class PagerExampleTest extends ExamplesBrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'pager_example',
'node',
];
protected function setUp() {
parent::setUp();
$normalUser = $this
->drupalCreateUser();
$this
->drupalLogin($normalUser);
}
public function testPagerExamplePage() {
$assert = $this
->assertSession();
$nodes = [];
$nodes[] = $this
->drupalCreateNode();
$this
->drupalGet('examples/pager-example');
$assert
->linkNotExists('Next');
$assert
->linkNotExists('Previous');
for ($i = 1; $i <= 5; $i++) {
$nodes[] = $this
->drupalCreateNode([
'title' => "Node number {$i}",
]);
}
drupal_flush_all_caches();
$this
->drupalGet('examples/pager-example');
$assert
->statusCodeEquals(200);
$assert
->linkByHrefExists('?page=1');
$assert
->pageTextContains($nodes[5]
->getTitle());
$this
->drupalGet('examples/pager-example', [
'query' => [
'page' => 2,
],
]);
$assert
->statusCodeEquals(200);
$assert
->linkNotExists('Next');
$assert
->linkByHrefExists('?page=1');
$assert
->pageTextContains($nodes[1]
->getTitle());
}
}