X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FFunctional%2FHandler%2FAreaTest.php;fp=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FFunctional%2FHandler%2FAreaTest.php;h=d631373d23ef00921e9823ad6e7d147c2a477e2e;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views/tests/src/Functional/Handler/AreaTest.php b/web/core/modules/views/tests/src/Functional/Handler/AreaTest.php new file mode 100644 index 000000000..d631373d2 --- /dev/null +++ b/web/core/modules/views/tests/src/Functional/Handler/AreaTest.php @@ -0,0 +1,217 @@ +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, '