public function BrowserTestBaseTest::testVarDump in Drupal 10
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testVarDump()
Tests the dump() function provided by the var-dumper Symfony component.
File
- core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php, line 710
Class
- BrowserTestBaseTest
- Tests BrowserTestBase functionality.
Namespace
Drupal\FunctionalTestsCode
public function testVarDump() {
// Append the stream capturer to the STDOUT stream, so that we can test the
// dump() output and also prevent it from actually outputting in this
// particular test.
stream_filter_register("capture", StreamCapturer::class);
stream_filter_append(STDOUT, "capture");
// Dump some variables to check that dump() in test code produces output
// on the command line that is running the test.
$role = Role::load('authenticated');
dump($role);
dump($role
->id());
$this
->assertStringContainsString('Drupal\\user\\Entity\\Role', StreamCapturer::$cache);
$this
->assertStringContainsString('authenticated', StreamCapturer::$cache);
// Visit a Drupal page with call to the dump() function to check that dump()
// in site code produces output in the requested web page's HTML.
$body = $this
->drupalGet('test-page-var-dump');
$this
->assertSession()
->statusCodeEquals(200);
// It is too strict to assert all properties of the Role and it is easy to
// break if one of these properties gets removed or gets a new default
// value. It should be sufficient to test just a couple of properties.
$this
->assertStringContainsString('<span class=sf-dump-note>', $body);
$this
->assertStringContainsString(' #<span class=sf-dump-protected title="Protected property">id</span>: "<span class=sf-dump-str title="9 characters">test_role</span>"', $body);
$this
->assertStringContainsString(' #<span class=sf-dump-protected title="Protected property">label</span>: "<span class=sf-dump-str title="9 characters">Test role</span>"', $body);
$this
->assertStringContainsString(' #<span class=sf-dump-protected title="Protected property">permissions</span>: []', $body);
$this
->assertStringContainsString(' #<span class=sf-dump-protected title="Protected property">uuid</span>: "', $body);
$this
->assertStringContainsString('</samp>}', $body);
}