function WebAssertTest::testEscapingAssertions
Same name in this branch
- 11.x core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testEscapingAssertions()
Same name in other branches
- 10 core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testEscapingAssertions()
- 10 core/tests/Drupal/Tests/Core/Test/WebAssertTest.php \Drupal\Tests\Core\Test\WebAssertTest::testEscapingAssertions()
Tests assertEscaped() and assertUnescaped().
@covers ::assertNoEscaped @covers ::assertEscaped
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ WebAssertTest.php, line 424
Class
- WebAssertTest
- Tests WebAssert functionality.
Namespace
Drupal\Tests\Core\TestCode
public function testEscapingAssertions() : void {
$assert = $this->assertSession();
$this->visit('', '<div class="escaped">Escaped: <"'&></div>');
$assert->assertNoEscaped('<div class="escaped">');
$assert->responseContains('<div class="escaped">');
$assert->assertEscaped('Escaped: <"\'&>');
$this->visit('', '<div class="escaped"><script>alert('XSS');alert("XSS");</script></div>');
$assert->assertNoEscaped('<div class="escaped">');
$assert->responseContains('<div class="escaped">');
$assert->assertEscaped("<script>alert('XSS');alert(\"XSS\");</script>");
$this->visit('', <<<HTML
<div class="unescaped"><script>alert('Marked safe');alert("Marked safe");</script></div>
HTML
);
$this->session
->visit('');
$assert->assertNoEscaped('<div class="unescaped">');
$assert->responseContains('<div class="unescaped">');
$assert->responseContains("<script>alert('Marked safe');alert(\"Marked safe\");</script>");
$assert->assertNoEscaped("<script>alert('Marked safe');alert(\"Marked safe\");</script>");
$this->addToAssertionCount(10);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.