View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
class DevelDumperTest extends BrowserTestBase {
public static $modules = [
'devel',
'devel_dumper_test',
];
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access devel information',
]);
$this
->drupalLogin($admin_user);
}
public function testDumpersConfiguration() {
$this
->drupalGet('admin/config/development/devel');
$this
->assertSession()
->fieldExists('dumper');
$this
->assertSession()
->checkboxChecked('edit-dumper-default');
$dumpers = [
'default',
'drupal_variable',
'firephp',
'chromephp',
'var_dumper',
];
$available_dumpers = [
'default',
'drupal_variable',
'var_dumper',
];
foreach ($dumpers as $dumper) {
$this
->assertFieldByXPath('//input[@type="radio" and @name="dumper"]', $dumper);
if (in_array($dumper, $available_dumpers)) {
$this
->assertFieldByXPath('//input[@name="dumper" and not(@disabled="disabled")]', $dumper);
}
else {
$this
->assertFieldByXPath('//input[@name="dumper" and @disabled="disabled"]', $dumper);
}
}
$this
->assertFieldByXPath('//input[@name="dumper"]', 'available_test_dumper');
$this
->assertSession()
->pageTextContains('Available test dumper.');
$this
->assertSession()
->pageTextContains('Drupal dumper for testing purposes (available).');
$this
->assertFieldByXPath('//input[@name="dumper" and not(@disabled="disabled")]', 'available_test_dumper', 'Available dumper input not is disabled.');
$this
->assertFieldByXPath('//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
->assertFieldByXPath('//input[@name="dumper" and @disabled="disabled"]', 'not_available_test_dumper', 'Non available dumper input is disabled.');
$edit = [
'dumper' => 'drupal_variable',
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains(t('The configuration options have been saved.'));
$config = \Drupal::config('devel.settings')
->get('devel_dumper');
$this
->assertEquals('drupal_variable', $config, 'The configuration options have been properly saved');
\Drupal::service('module_installer')
->install([
'kint',
]);
$this
->drupalGet('admin/config/development/devel');
$this
->assertFieldByXPath('//input[@name="dumper"]', 'kint');
$edit = [
'dumper' => 'kint',
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains(t('The configuration options have been saved.'));
$config = \Drupal::config('devel.settings')
->get('devel_dumper');
$this
->assertEquals('kint', $config, 'The configuration options have been properly saved');
\Drupal::service('module_installer')
->uninstall([
'kint',
]);
$this
->drupalGet('admin/config/development/devel');
$this
->assertNoFieldByXPath('//input[@name="dumper"]', 'kint');
$this
->assertSession()
->checkboxChecked('edit-dumper-default');
}
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.');
$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.');
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.');
}
}