1 views_exposed_form.test ViewsExposedFormTest::testExposedAdminUi()

Tests the admin interface of exposed filter and sort items.

File

core/modules/views/tests/views_exposed_form.test, line 90
Definition of ViewsExposedFormTest.

Class

ViewsExposedFormTest
Tests exposed forms.

Code

function testExposedAdminUi() {
  $admin_user = $this->backdropCreateUser(array('administer views', 'administer site configuration'));
  $this->backdropLogin($admin_user);
  menu_rebuild();
  $edit = array();

  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
  // Be sure that the button is called exposed.
  $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter'));

  // The first time the filter UI is displayed, the operator and the
  // value forms should be shown.
  $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
  $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
  $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
  $this->assertFieldById('edit-options-value-post', '', 'Checkbox for Post exists');

  // Click the Expose filter button.
  $this->backdropPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
  // Check the label of the expose button.
  $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
  // Check the label of the grouped exposed button
  $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));

  // After Expose the filter, Operator and Value should be still here
  $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
  $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
  $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
  $this->assertFieldById('edit-options-value-post', '', 'Checkbox for Post exists');

  // Check the validations of the filter handler.
  $edit = array();
  $edit['options[expose][identifier]'] = '';
  $this->backdropPost(NULL, $edit, t('Apply'));
  $this->assertText(t('The identifier is required if the filter is exposed.'));

  $edit = array();
  $edit['options[expose][identifier]'] = 'value';
  $this->backdropPost(NULL, $edit, t('Apply'));
  $this->assertText(t('This identifier is not allowed.'));

  // Now check the sort criteria.
  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created');
  $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose sort'));
  $this->assertNoFieldById('edit-options-expose-label', '', t('Make sure no label field is shown'));

  // Click the Grouped Filters button.
  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
  $this->backdropPost(NULL, array(), t('Grouped filters'));

  // After click on 'Grouped Filters' standard operator and value should not be displayed
  $this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
  $this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
  $this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
  $this->assertNoFieldById('edit-options-value-post', '', 'Checkbox for Post not exists');


  // Check that after click on 'Grouped Filters', a new button is shown to
  // add more items to the list.
  $this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));

  // Create a grouped filter
  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
  $edit = array();
  $edit["options[group_info][group_items][1][title]"] = 'Is Post';
  $edit["options[group_info][group_items][1][value][post]"] = 'post';

  $edit["options[group_info][group_items][2][title]"] = 'Is Page';
  $edit["options[group_info][group_items][2][value][page]"] = TRUE;

  $edit["options[group_info][group_items][3][title]"] = 'Is Page and Post';
  $edit["options[group_info][group_items][3][value][post]"] = TRUE;
  $edit["options[group_info][group_items][3][value][page]"] = TRUE;
  $this->backdropPost(NULL, $edit, t('Apply'));

  // Validate that all the titles are defined for each group
  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
  $edit = array();
  $edit["options[group_info][group_items][1][title]"] = 'Is Post';
  $edit["options[group_info][group_items][1][value][post]"] = TRUE;

  // This should trigger an error
  $edit["options[group_info][group_items][2][title]"] = '';
  $edit["options[group_info][group_items][2][value][page]"] = TRUE;

  $edit["options[group_info][group_items][3][title]"] = 'Is Page and Post';
  $edit["options[group_info][group_items][3][value][post]"] = TRUE;
  $edit["options[group_info][group_items][3][value][page]"] = TRUE;
  $this->backdropPost(NULL, $edit, t('Apply'));
  $this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title'));

  // Un-Expose the filter
  $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
  $this->backdropPost(NULL, array(), t('Hide filter'));

  // After Un-Expose the filter, Operator and Value should be shown again
  $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
  $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter');
  $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter');
  $this->assertFieldById('edit-options-value-post', '', 'Checkbox for Post exists after hide filter');

  // Click the Expose sort button.
  $edit = array();
  $this->backdropPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
  // Check the label of the expose button.
  $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
  $this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
}