class ViewsEscapingTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Functional/ViewsEscapingTest.php \Drupal\Tests\views\Functional\ViewsEscapingTest
- 10 core/modules/views/tests/src/Functional/ViewsEscapingTest.php \Drupal\Tests\views\Functional\ViewsEscapingTest
- 8.9.x core/modules/views/tests/src/Functional/ViewsEscapingTest.php \Drupal\Tests\views\Functional\ViewsEscapingTest
Tests output of Views.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\Functional\ViewsEscapingTest extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ViewsEscapingTest
File
-
core/
modules/ views/ tests/ src/ Functional/ ViewsEscapingTest.php, line 10
Namespace
Drupal\Tests\views\FunctionalView source
class ViewsEscapingTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_page_display',
'test_field_header',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*
* We need theme_test for testing against test_basetheme and test_subtheme.
*
* @var array
*
* {@inheritdoc}
*/
protected static $modules = [
'views',
'theme_test',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp(TRUE, $modules);
$this->enableViewsTestModule();
}
/**
* Tests for incorrectly escaped markup in the views-view-fields.html.twig.
*/
public function testViewsViewFieldsEscaping() {
// Test with system theme using theme function.
$this->drupalGet('test_page_display_200');
// Assert that there are no escaped '<'s characters.
$this->assertSession()
->assertNoEscaped('<');
// Install theme to test with template system.
\Drupal::service('theme_installer')->install([
'views_test_theme',
]);
// Make base theme default then test for hook invocations.
$this->config('system.theme')
->set('default', 'views_test_theme')
->save();
$this->assertEquals('views_test_theme', $this->config('system.theme')
->get('default'));
$this->drupalGet('test_page_display_200');
// Assert that we are using the correct template.
$this->assertSession()
->pageTextContains('force');
// Assert that there are no escaped '<'s characters.
$this->assertSession()
->assertNoEscaped('<');
}
/**
* Tests for incorrectly escaped markup in a header label on a display table.
*/
public function testViewsFieldHeaderEscaping() {
// Test with a field header label having an html element wrapper.
$this->drupalGet('test_field_header');
// Assert that there are no escaped '<'s characters.
$this->assertSession()
->assertNoEscaped('<');
// Test with a field header label having a XSS test as a wrapper.
$this->drupalGet('test_field_header_xss');
// Assert that harmful tags are escaped in header label.
$this->assertSession()
->responseNotContains('<script>alert("XSS")</script>');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.