You are here

public function ExposedFormTest::testExposedBlock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Plugin/ExposedFormTest.php \Drupal\views\Tests\Plugin\ExposedFormTest::testExposedBlock()

Tests the exposed block functionality.

File

core/modules/views/src/Tests/Plugin/ExposedFormTest.php, line 153
Contains \Drupal\views\Tests\Plugin\ExposedFormTest.

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\views\Tests\Plugin

Code

public function testExposedBlock() {
  $view = Views::getView('test_exposed_block');
  $view
    ->setDisplay('page_1');
  $block = $this
    ->drupalPlaceBlock('views_exposed_filter_block:test_exposed_block-page_1');
  $this
    ->drupalGet('test_exposed_block');

  // Test there is an exposed form in a block.
  $xpath = $this
    ->buildXPathQuery('//div[@id=:id]/form/@id', array(
    ':id' => Html::getUniqueId('block-' . $block
      ->id()),
  ));
  $this
    ->assertFieldByXpath($xpath, $this
    ->getExpectedExposedFormId($view), 'Expected form found in views block.');

  // Test there is not an exposed form in the view page content area.
  $xpath = $this
    ->buildXPathQuery('//div[@class="view-content"]/form/@id', array(
    ':id' => Html::getUniqueId('block-' . $block
      ->id()),
  ));
  $this
    ->assertNoFieldByXpath($xpath, $this
    ->getExpectedExposedFormId($view), 'No exposed form found in views content region.');

  // Test there is only one views exposed form on the page.
  $elements = $this
    ->xpath('//form[@id=:id]', array(
    ':id' => $this
      ->getExpectedExposedFormId($view),
  ));
  $this
    ->assertEqual(count($elements), 1, 'One exposed form block found.');
}