You are here

public function ConfigEntityListTest::testPager in Drupal 8

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

Test paging.

File

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

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
    ->assertRaw('Test config entity 50', 'Config entity 50 is shown.');
  $this
    ->assertNoRaw('Test config entity 51', 'Config entity 51 is on the next page.');

  // Browse to the next page.
  $this
    ->clickLink(t('Page 2'));
  $this
    ->assertNoRaw('Test config entity 50', 'Test config entity 50 is on the previous page.');
  $this
    ->assertRaw('dotted.default', 'Default config entity appears on page 2.');
  $this
    ->assertRaw('Test config entity 51', 'Test config entity 51 is on page 2.');
}