You are here

public function DevelToolbarTest::testConfigurationForm in Devel 8

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

Tests configuration form.

File

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

Class

DevelToolbarTest
Tests devel toolbar module functionality.

Namespace

Drupal\Tests\devel\Functional

Code

public function testConfigurationForm() {

  // Ensures that the page is accessible ony to users with the adequate
  // permissions.
  $this
    ->drupalGet('admin/config/development/devel/toolbar');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Ensures that the config page is accessible for users with the adequate
  // permissions and exists the Devel toolbar local task.
  $this
    ->drupalLogin($this->develUser);
  $this
    ->drupalGet('admin/config/development/devel/toolbar');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementExists('css', '.tabs .primary a:contains("Toolbar Settings")');
  $this
    ->assertSession()
    ->pageTextContains('Devel Toolbar Settings');

  // Ensures and that all devel menu links are listed in the configuration
  // page.
  foreach ($this
    ->getMenuLinkInfos() as $link) {
    $this
      ->assertSession()
      ->fieldExists(sprintf('toolbar_items[%s]', $link['id']));
  }

  // Ensures and that the default configuration items are selected by
  // default.
  foreach ($this->defaultToolbarItems as $item) {
    $this
      ->assertSession()
      ->checkboxChecked(sprintf('toolbar_items[%s]', $item));
  }

  // Ensures that the configuration save works as expected.
  $edit = [
    'toolbar_items[devel.event_info]' => 'devel.event_info',
    'toolbar_items[devel.theme_registry]' => 'devel.theme_registry',
  ];
  $this
    ->drupalPostForm('admin/config/development/devel/toolbar', $edit, t('Save configuration'));
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');
  $expected_items = array_merge($this->defaultToolbarItems, [
    'devel.event_info',
    'devel.theme_registry',
  ]);
  sort($expected_items);
  $config_items = \Drupal::config('devel.toolbar.settings')
    ->get('toolbar_items');
  sort($config_items);
  $this
    ->assertEquals($expected_items, $config_items);
}