6767fffe3caa6d56a3f5e2cd0fe8759138893280
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Plugin / ExposedFormRenderTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Plugin;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views\Views;
8
9 /**
10  * Tests the exposed form markup.
11  *
12  * @group views
13  * @see \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
14  */
15 class ExposedFormRenderTest extends ViewsKernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $testViews = ['test_exposed_form_buttons'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public static $modules = ['node'];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp($import_test_views = TRUE) {
31     parent::setUp();
32     $this->installEntitySchema('node');
33   }
34
35   /**
36    * Tests the exposed form markup.
37    */
38   public function testExposedFormRender() {
39     $view = Views::getView('test_exposed_form_buttons');
40     $this->executeView($view);
41     $exposed_form = $view->display_handler->getPlugin('exposed_form');
42     $output = $exposed_form->renderExposedForm();
43     $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
44
45     $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.');
46
47     $view->setDisplay('page_1');
48     $expected_action = $view->display_handler->getUrlInfo()->toString();
49     $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
50     // Make sure the description is shown.
51     $result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]);
52     $this->assertEqual(count($result), 1, 'Filter description was found.');
53   }
54
55 }