function DevelToolbarTest::testConfigurationForm

Same name in other branches
  1. 4.x tests/src/Functional/DevelToolbarTest.php \Drupal\Tests\devel\Functional\DevelToolbarTest::testConfigurationForm()

Tests configuration form.

File

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

Class

DevelToolbarTest
Tests devel toolbar module functionality.

Namespace

Drupal\Tests\devel\Functional

Code

public function testConfigurationForm() : void {
    // Ensures that the page is accessible only 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 the Devel toolbar local task and content are shown.
    $this->drupalLogin($this->develUser);
    $this->drupalGet('admin/config/development/devel/toolbar');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->elementExists('xpath', '//h2[text()="Primary tabs"]/following-sibling::ul//a[contains(text(), "Toolbar Settings")]');
    $this->assertSession()
        ->elementExists('xpath', '//fieldset[@id="edit-toolbar-items--wrapper"]');
    $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->submitForm($edit, '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);
}