You are here

ViewsExposedGroupsInheritedPropertiesTest.php in Views exposed groups 3.0.x

File

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

namespace Drupal\Tests\views_exposed_groups\Functional;


/**
 * Tests a view with exposed groups and autosubmit.
 *
 * @group views_exposed_groups
 */
class ViewsExposedGroupsInheritedPropertiesTest extends ViewsExposedGroupsTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->defaultView
      ->getDisplay('default')
      ->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 form sets values for inherited properties.
   */
  public function testViewsUi() {
    $views_ui_path = '/admin/structure/views/view/' . $this->defaultView->name;
    $this
      ->drupalLogin($this->privilegedUser);
    $this
      ->drupalGet($views_ui_path . '/edit');
    $this
      ->clickExposedFormOptionsLink('Grouped form');
    $edit = [
      'exposed_form_options[reset_button]' => '1',
      'exposed_form_options[autosubmit]' => '1',
      'exposed_form_options[autosubmit_hide]' => '1',
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Apply');

    // Asserts the form options are set.
    $exposed_options_path = 'admin/structure/views/nojs/display/' . $this->defaultView->name . '/default/exposed_form_options';
    $this
      ->drupalGet($exposed_options_path);
    $this
      ->assertFieldByName('exposed_form_options[reset_button]', '1');
    $this
      ->assertFieldByName('exposed_form_options[autosubmit]', '1');
    $this
      ->assertFieldByName('exposed_form_options[autosubmit_hide]', '1');
  }

  /**
   * Asserts that the view itself is displayed correctly.
   *
   * It is not possible to test the actual functionality of the reset
   * and autosubmit functionality.
   */
  public function testView() {
    $view_path = $this->defaultView
      ->getDisplay('page_1')
      ->getOption('path');

    // Bypass the UI for this test.
    $this->defaultView
      ->getDisplay('default')
      ->setOption('exposed_form.options.autosubmit', TRUE)
      ->setOption('exposed_form.options.autosubmit_hide', TRUE)
      ->setOption('exposed_form.options.reset_button', TRUE);
    $this->defaultView
      ->save();
    $this
      ->drupalLogin($this->unprivilegedUser);
    $this
      ->drupalGet($view_path);

    // An apply button exists when Javascript is disabled so assert that this
    // exists for autosubmit.
    $this
      ->assertFieldByXpath('//input[@value="Apply" and @type="submit" and contains(@class, "js-hide")]');

    // Asserts that the reset button exists.
    $this
      ->assertFieldByXpath('//input[@value="Reset" and @type="submit"]');
  }

}

Classes

Namesort descending Description
ViewsExposedGroupsInheritedPropertiesTest Tests a view with exposed groups and autosubmit.