function DevelDumperTest::testDumpersConfiguration

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

Test dumpers configuration page.

File

tests/src/Functional/DevelDumperTest.php, line 30

Class

DevelDumperTest
Tests pluggable dumper feature.

Namespace

Drupal\Tests\devel\Functional

Code

public function testDumpersConfiguration() : void {
    $this->drupalGet('admin/config/development/devel');
    // Ensures that the dumper input is present on the config page.
    $this->assertSession()
        ->fieldExists('dumper');
    // No need to ensure that the 'default' dumper is enabled by default via
    // "checkboxChecked('edit-dumper-default')" since devel_install does dynamic
    // default.
    // Ensures that all dumpers (both those declared by devel and by other
    // modules) are present on the config page and that only the available
    // dumpers are selectable.
    $dumpers = [
        'var_dumper' => 'Symfony var-dumper',
        'available_test_dumper' => 'Available test dumper',
        'not_available_test_dumper' => 'Not available test dumper',
    ];
    $available_dumpers = [
        'default',
        'var_dumper',
        'available_test_dumper',
    ];
    foreach ($dumpers as $dumper => $label) {
        // Check that a radio option exists for the specified dumper.
        $this->assertSession()
            ->elementExists('xpath', '//input[@type="radio" and @name="dumper" and @value="' . $dumper . '"]');
        $this->assertSession()
            ->pageTextContains($label);
        // Check that the available dumpers are enabled and the non-available
        // dumpers are not enabled.
        if (in_array($dumper, $available_dumpers)) {
            $this->assertSession()
                ->elementExists('xpath', '//input[@name="dumper" and not(@disabled="disabled") and @value="' . $dumper . '"]');
        }
        else {
            $this->assertSession()
                ->elementExists('xpath', '//input[@name="dumper" and @disabled="disabled" and @value="' . $dumper . '"]');
        }
    }
    // Ensures that saving of the dumpers configuration works as expected.
    $edit = [
        'dumper' => 'var_dumper',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()
        ->pageTextContains('The configuration options have been saved.');
    $this->assertSession()
        ->checkboxChecked('Symfony var-dumper');
    $config = \Drupal::config('devel.settings')->get('devel_dumper');
    $this->assertEquals('var_dumper', $config, 'The configuration options have been properly saved');
}