You are here

public function DevelStateEditorTest::testStateListing in Devel 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/DevelStateEditorTest.php \Drupal\Tests\devel\Functional\DevelStateEditorTest::testStateListing()
  2. 8.2 tests/src/Functional/DevelStateEditorTest.php \Drupal\Tests\devel\Functional\DevelStateEditorTest::testStateListing()
  3. 4.x tests/src/Functional/DevelStateEditorTest.php \Drupal\Tests\devel\Functional\DevelStateEditorTest::testStateListing()

Tests state listing.

File

tests/src/Functional/DevelStateEditorTest.php, line 73

Class

DevelStateEditorTest
Tests devel state editor.

Namespace

Drupal\Tests\devel\Functional

Code

public function testStateListing() {
  $table_selector = 'table.devel-state-list';

  // Ensure that state listing page is accessible only by users with the
  // adequate permissions.
  $this
    ->drupalGet('devel/state');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalLogin($this->develUser);
  $this
    ->drupalGet('devel/state');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('State editor');

  // Ensure that the state variables table is visible.
  $table = $this
    ->assertSession()
    ->elementExists('css', $table_selector);

  // Ensure that all state variables are listed in the table.
  $states = \Drupal::keyValue('state')
    ->getAll();
  $rows = $table
    ->findAll('css', 'tbody tr');
  $this
    ->assertEquals(count($rows), count($states), 'All states are listed in the table.');

  // Ensure that the added state variables are listed in the table.
  $this->state
    ->set('devel.simple', 'Hello!');
  $this
    ->drupalGet('devel/state');
  $table = $this
    ->assertSession()
    ->elementExists('css', $table_selector);
  $this
    ->assertSession()
    ->elementExists('css', sprintf('tbody td:contains("%s")', 'devel.simple'), $table);

  // Ensure that the operations column and the actions buttons are not
  // available for user without 'administer site configuration' permission.
  $headers = $table
    ->findAll('css', 'thead th');
  $this
    ->assertEquals(count($headers), 2, 'Correct number of table header cells found.');
  $this
    ->assertElementsTextEquals($headers, [
    'Name',
    'Value',
  ]);
  $this
    ->assertSession()
    ->elementNotExists('css', 'ul.dropbutton li a', $table);

  // Ensure that the operations column and the actions buttons are
  // available for user with 'administer site configuration' permission.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('devel/state');
  $table = $this
    ->assertSession()
    ->elementExists('css', $table_selector);
  $headers = $table
    ->findAll('css', 'thead th');
  $this
    ->assertEquals(count($headers), 3, 'Correct number of table header cells found.');
  $this
    ->assertElementsTextEquals($headers, [
    'Name',
    'Value',
    'Operations',
  ]);
  $this
    ->assertSession()
    ->elementExists('css', 'ul.dropbutton li a', $table);

  // Test that the edit button works properly.
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}