You are here

views_exposed_groups_inherit.test in Views exposed groups 7.2

ViewsExposedGroupsInheritedPropertiesTest.

File

tests/views_exposed_groups_inherit.test
View source
<?php

/**
 * @file
 * ViewsExposedGroupsInheritedPropertiesTest.
 */

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

  /**
   * Describes the test case.
   */
  public static function getInfo() {
    return [
      'name' => 'Views Exposed Groups Inherited Properties Test',
      'description' => 'Tests a view with inherited properties from the base class.',
      'group' => 'Views Exposed Groups',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function setUp(array $modules = []) {
    parent::setUp($modules);
    $this->defaultView
      ->set_display('default');
    $this->defaultView->display['default']->display_options['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',
          ],
        ],
      ],
    ];
    views_save_view($this->defaultView);
  }

  /**
   * 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
      ->drupalPost(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
      ->get_path();

    // Bypass the UI for this test.
    $this->defaultView
      ->set_display('default');
    $this->defaultView->display['default']->display_options['exposed_form']['options']['autosubmit'] = TRUE;
    $this->defaultView->disabled['default']->display_options['exposed_form']['options']['autosubmit_hide'] = TRUE;
    $this->defaultView->display['default']->display_options['exposed_form']['options']['reset_button'] = TRUE;
    views_save_view($this->defaultView);
    $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.