enableViewsTestModule(); } protected function viewsData() { $data = parent::viewsData(); $data['views']['test_example'] = [ 'title' => 'Test Example area', 'help' => 'A area handler which just exists for tests.', 'area' => [ 'id' => 'test_example', ], ]; return $data; } /** * Tests the generic UI of a area handler. */ public function testUI() { $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']); $this->drupalLogin($admin_user); $types = ['header', 'footer', 'empty']; $labels = []; foreach ($types as $type) { $edit_path = 'admin/structure/views/nojs/handler/test_example_area/default/' . $type . '/test_example'; // First setup an empty label. $this->drupalPostForm($edit_path, [], t('Apply')); $this->assertText('Test Example area'); // Then setup a no empty label. $labels[$type] = $this->randomMachineName(); $this->drupalPostForm($edit_path, ['options[admin_label]' => $labels[$type]], t('Apply')); // Make sure that the new label appears on the site. $this->assertText($labels[$type]); // Test that the settings (empty/admin_label) are accessible. $this->drupalGet($edit_path); $this->assertField('options[admin_label]'); if ($type !== 'empty') { $this->assertField('options[empty]'); } } } /** * Tests the rendering of an area. */ public function testRenderArea() { $view = Views::getView('test_example_area'); $view->initHandlers(); // Insert a random string with XSS injection in the test area plugin. // Ensure that the string is rendered for the header, footer, and empty // text with the markup properly escaped. $header_string = '
' . $this->randomMachineName() . '
'; $footer_string = '' . $this->randomMachineName() . '
'; $empty_string = '' . $this->randomMachineName() . '
'; $view->header['test_example']->options['string'] = $header_string; $view->header['test_example']->options['empty'] = TRUE; $view->footer['test_example']->options['string'] = $footer_string; $view->footer['test_example']->options['empty'] = TRUE; $view->empty['test_example']->options['string'] = $empty_string; // Check whether the strings exist in the output and are sanitized. $output = $view->preview(); $output = $this->container->get('renderer')->renderRoot($output); $this->assertTrue(strpos($output, Xss::filterAdmin($header_string)) !== FALSE, 'Views header exists in the output and is sanitized'); $this->assertTrue(strpos($output, Xss::filterAdmin($footer_string)) !== FALSE, 'Views footer exists in the output and is sanitized'); $this->assertTrue(strpos($output, Xss::filterAdmin($empty_string)) !== FALSE, 'Views empty exists in the output and is sanitized'); $this->assertTrue(strpos($output, '