function ClaroTest::testPagerAttribute

Same name in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Theme/ClaroTest.php \Drupal\FunctionalTests\Theme\ClaroTest::testPagerAttribute()

Tests pager attribute is present using pager_test.

File

core/tests/Drupal/FunctionalTests/Theme/ClaroTest.php, line 81

Class

ClaroTest
Tests the Claro theme.

Namespace

Drupal\FunctionalTests\Theme

Code

public function testPagerAttribute() : void {
    // Insert 300 log messages.
    $logger = $this->container
        ->get('logger.factory')
        ->get('pager_test');
    for ($i = 0; $i < 300; $i++) {
        $logger->debug($this->randomString());
    }
    $this->drupalLogin($this->drupalCreateUser([
        'access site reports',
    ]));
    $this->drupalGet('admin/reports/dblog', [
        'query' => [
            'page' => 1,
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    $elements = $this->xpath('//ul[contains(@class, :class)]/li', [
        ':class' => 'pager__items',
    ]);
    $this->assertNotEmpty($elements, 'Pager found.');
    // Check all links for pager-test attribute.
    foreach ($elements as $page => $element) {
        $link = $element->find('css', 'a');
        $this->assertNotEmpty($link, "Link to page {$page} found.");
        $this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test');
        $this->assertTrue($link->hasClass('lizards'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.