You are here

ViewsExposedGroupsExposedOperatorTest.php in Views exposed groups 3.0.x

File

tests/src/Functional/ViewsExposedGroupsExposedOperatorTest.php
View source
<?php

namespace Drupal\Tests\views_exposed_groups\Functional;


/**
 * Tests a view with exposed groups that also has exposed operators.
 *
 * @group views_exposed_groups
 */
class ViewsExposedGroupsExposedOperatorTest extends ViewsExposedGroupsTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->defaultView
      ->getDisplay('default')
      ->setOption('filters.title.expose.use_operator', TRUE)
      ->setOption('exposed_form', [
      'type' => 'views_exposed_groups',
      'options' => [
        'views_exposed_groups' => [
          'groups' => "Default\nAdvanced",
          'format_groups' => 'fieldsets',
          'vertical_tabs_summary' => '0',
          'group-title' => [
            'group' => '0',
            'filter_name' => 'title',
            'weight' => '-4',
          ],
          'group-nid' => [
            'group' => '1',
            'filter_name' => 'nid',
            'weight' => '-3',
          ],
          'group-uid' => [
            'group' => 'no-group',
            'filter_name' => 'uid',
            'weight' => '0',
          ],
        ],
      ],
    ]);
    $this->defaultView
      ->save();
  }

  /**
   * Asserts that a filter with an exposed operator behaves correctly.
   */
  public function testExposedOperator() {
    $view_path = $this->defaultView
      ->getDisplay('page_1')
      ->getOption('path');
    $this
      ->drupalLogin($this->unprivilegedUser);
    $this
      ->drupalGet($view_path);

    // Asserts that the exposed filter with an exposed operator exists.
    $this
      ->assertFieldByName('title_op');
    $this
      ->assertFieldByName('title');
    $fieldset_legend = $this
      ->xpath('//fieldset/legend/span[text()="Title"]');
    $this
      ->assertEqual(1, count($fieldset_legend), 'Found the exposed filter label as the fieldset legend.');
  }

}

Classes

Namesort descending Description
ViewsExposedGroupsExposedOperatorTest Tests a view with exposed groups that also has exposed operators.