function PagerExampleTest::testPagerExamplePage

Same name in other branches
  1. 3.x modules/pager_example/tests/src/Functional/PagerExampleTest.php \Drupal\Tests\pager_example\Functional\PagerExampleTest::testPagerExamplePage()

Confirms nodes paging works correctly on page "pager_example".

File

modules/pager_example/tests/src/Functional/PagerExampleTest.php, line 39

Class

PagerExampleTest
Tests paging.

Namespace

Drupal\Tests\pager_example\Functional

Code

public function testPagerExamplePage() {
    $assert = $this->assertSession();
    $nodes = [];
    $nodes[] = $this->drupalCreateNode();
    $this->drupalGet('examples/pager-example');
    $assert->linkNotExists('Next');
    $assert->linkNotExists('Previous');
    // Create 5 new nodes.
    for ($i = 1; $i <= 5; $i++) {
        $nodes[] = $this->drupalCreateNode([
            'title' => "Node number {$i}",
        ]);
    }
    // The pager pages are cached, so flush to see the 5 more nodes.
    drupal_flush_all_caches();
    // Check 'Next' link on first page.
    $this->drupalGet('examples/pager-example');
    $assert->statusCodeEquals(200);
    $assert->linkByHrefExists('?page=1');
    $assert->pageTextContains($nodes[5]->getTitle());
    // Check the last page.
    $this->drupalGet('examples/pager-example', [
        'query' => [
            'page' => 2,
        ],
    ]);
    $assert->statusCodeEquals(200);
    $assert->linkNotExists('Next');
    $assert->linkByHrefExists('?page=1');
    $assert->pageTextContains($nodes[1]->getTitle());
}