You are here

public function ConfigEntityListTest::testPager in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/config/tests/src/Functional/ConfigEntityListTest.php \Drupal\Tests\config\Functional\ConfigEntityListTest::testPager()

Tests paging.

File

core/modules/config/tests/src/Functional/ConfigEntityListTest.php, line 255

Class

ConfigEntityListTest
Tests the listing of configuration entities.

Namespace

Drupal\Tests\config\Functional

Code

public function testPager() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer site configuration',
  ]));
  $storage = \Drupal::service('entity_type.manager')
    ->getListBuilder('config_test')
    ->getStorage();

  // Create 51 test entities.
  for ($i = 1; $i < 52; $i++) {
    $storage
      ->create([
      'id' => str_pad($i, 2, '0', STR_PAD_LEFT),
      'label' => 'Test config entity ' . $i,
      'weight' => $i,
      'protected_property' => $i,
    ])
      ->save();
  }

  // Load the listing page.
  $this
    ->drupalGet('admin/structure/config_test');

  // Item 51 should not be present.
  $this
    ->assertSession()
    ->pageTextContains('Test config entity 50');
  $this
    ->assertSession()
    ->responseNotContains('Test config entity 51');

  // Browse to the next page, test config entity 51 is on page 2.
  $this
    ->clickLink('Page 2');
  $this
    ->assertSession()
    ->responseNotContains('Test config entity 50');
  $this
    ->assertSession()
    ->responseContains('dotted.default');
  $this
    ->assertSession()
    ->pageTextContains('Test config entity 51');
}