You are here

public function DevelDumperTest::testDumpersConfiguration in Devel 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/DevelDumperTest.php \Drupal\Tests\devel\Functional\DevelDumperTest::testDumpersConfiguration()
  2. 8 tests/src/Functional/DevelDumperTest.php \Drupal\Tests\devel\Functional\DevelDumperTest::testDumpersConfiguration()
  3. 8.2 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() {
  $this
    ->drupalGet('admin/config/development/devel');

  // Ensures that the dumper input is present on the config page.
  $this
    ->assertSession()
    ->fieldExists('dumper');

  // Ensures that the 'default' dumper is enabled by default.
  $this
    ->assertSession()
    ->checkboxChecked('edit-dumper-default');

  // Ensures that all dumpers declared by devel are present on the config page
  // and that only the available dumpers are selectable.
  $dumpers = [
    'default',
    'var_dumper',
  ];
  $available_dumpers = [
    'default',
    'var_dumper',
  ];
  foreach ($dumpers as $dumper) {
    $this
      ->assertFieldsByValue($this
      ->xpath('//input[@type="radio" and @name="dumper"]'), $dumper);
    if (in_array($dumper, $available_dumpers)) {
      $this
        ->assertFieldsByValue($this
        ->xpath('//input[@name="dumper" and not(@disabled="disabled")]'), $dumper);
    }
    else {
      $this
        ->assertFieldsByValue($this
        ->xpath('//input[@name="dumper" and @disabled="disabled"]'), $dumper);
    }
  }

  // Ensures that dumper plugins declared by other modules are present on the
  // config page and that only the available dumpers are selectable.
  $this
    ->assertFieldsByValue($this
    ->xpath('//input[@name="dumper"]'), 'available_test_dumper');
  $this
    ->assertSession()
    ->pageTextContains('Available test dumper.');
  $this
    ->assertSession()
    ->pageTextContains('Drupal dumper for testing purposes (available).');
  $this
    ->assertFieldsByValue($this
    ->xpath('//input[@name="dumper" and not(@disabled="disabled")]'), 'available_test_dumper', 'Available dumper input not is disabled.');
  $this
    ->assertFieldsByValue($this
    ->xpath('//input[@name="dumper"]'), 'not_available_test_dumper');
  $this
    ->assertSession()
    ->pageTextContains('Not available test dumper.');
  $this
    ->assertSession()
    ->pageTextContains('Drupal dumper for testing purposes (not available).Not available. You may need to install external dependencies for use this plugin.');
  $this
    ->assertFieldsByValue($this
    ->xpath('//input[@name="dumper" and @disabled="disabled"]'), 'not_available_test_dumper', 'Non available dumper input is disabled.');

  // Ensures that saving of the dumpers configuration works as expected.
  $edit = [
    'dumper' => 'var_dumper',
  ];
  $this
    ->drupalPostForm('admin/config/development/devel', $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');
}