You are here

function DevelDumperTest::testDumpersOutput in Devel 8

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

Test variable is dumped in page.

File

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

Class

DevelDumperTest
Tests pluggable dumper feature.

Namespace

Drupal\Tests\devel\Functional

Code

function testDumpersOutput() {
  $edit = [
    'dumper' => 'available_test_dumper',
  ];
  $this
    ->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
  $this
    ->assertSession()
    ->pageTextContains(t('The configuration options have been saved.'));
  $this
    ->drupalGet('devel_dumper_test/dump');
  $elements = $this
    ->xpath('//body/pre[contains(text(), :message)]', [
    ':message' => 'AvailableTestDumper::dump() Test output',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Dumped message is present.');
  $this
    ->drupalGet('devel_dumper_test/message');
  $elements = $this
    ->xpath('//div[contains(@class, "messages")]/pre[contains(text(), :message)]', [
    ':message' => 'AvailableTestDumper::export() Test output',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Dumped message is present.');
  $this
    ->drupalGet('devel_dumper_test/export');
  $elements = $this
    ->xpath('//div[@class="layout-content"]//pre[contains(text(), :message)]', [
    ':message' => 'AvailableTestDumper::export() Test output',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Dumped message is present.');
  $this
    ->drupalGet('devel_dumper_test/export_renderable');
  $elements = $this
    ->xpath('//div[@class="layout-content"]//pre[contains(text(), :message)]', [
    ':message' => 'AvailableTestDumper::exportAsRenderable() Test output',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Dumped message is present.');

  // Ensures that plugins can add libraries to the page when the
  // ::exportAsRenderable() method is used.
  $this
    ->assertSession()
    ->responseContains('devel_dumper_test/css/devel_dumper_test.css');
  $this
    ->assertSession()
    ->responseContains('devel_dumper_test/js/devel_dumper_test.js');
  $debug_filename = file_directory_temp() . '/drupal_debug.txt';
  $this
    ->drupalGet('devel_dumper_test/debug');
  $file_content = file_get_contents($debug_filename);
  $expected = <<<EOF
<pre>AvailableTestDumper::export() Test output</pre>

EOF;
  $this
    ->assertEquals($file_content, $expected, 'Dumped message is present.');

  // Ensures that the DevelDumperManager::debug() is not access checked and
  // that the dump is written in the debug file even if the user has not the
  // 'access devel information' permission.
  file_put_contents($debug_filename, '');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('devel_dumper_test/debug');
  $file_content = file_get_contents($debug_filename);
  $expected = <<<EOF
<pre>AvailableTestDumper::export() Test output</pre>

EOF;
  $this
    ->assertEquals($file_content, $expected, 'Dumped message is present.');
}