- <?php
- * @file
- * Definition of ViewsExposedFormTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Tests exposed forms.
- */
- class ViewsExposedFormTest extends ViewsSqlTest {
-
- * Tests, whether and how the reset button can be renamed.
- */
- public function testRenameResetButton() {
- $account = $this->backdropCreateUser();
- $this->backdropLogin($account);
-
- for ($i = 0; $i < 5; $i++) {
- $this->backdropCreateNode();
- }
-
- $this->backdropGet('test_rename_reset_button');
-
- $view = views_get_view('test_rename_reset_button');
- $view->set_display('default');
-
- $exposed_form = $view->display_handler->get_option('exposed_form');
- $exposed_form['options']['reset_button_label'] = $expected_label = $this->randomName();
- $exposed_form['options']['reset_button'] = TRUE;
- $view->display_handler->set_option('exposed_form', $exposed_form);
- $view->save();
-
- views_invalidate_cache();
-
-
- $this->backdropGet('test_rename_reset_button');
-
- $this->helperButtonHasLabel('edit-reset', $expected_label);
- }
-
-
- * Test remembering exposed filters.
- */
- function testExposedRemember() {
- $admin_user = $this->backdropCreateUser(array('administer views', 'administer site configuration'));
- $this->backdropLogin($admin_user);
-
-
- $query = array(
- 'type' => 'page',
- );
- $this->backdropGet('test_exposed_remember');
- $this->assertFieldByName('type', 'All', 'Filter is set to the default with no query string.');
- $this->backdropGet('test_exposed_remember', array('query' => $query));
- $this->assertFieldByName('type', 'page', 'Filter is set when visiting by query string.');
- $this->backdropGet('test_exposed_remember');
- $this->assertFieldByName('type', 'page', 'Filter is remembered when the query string is removed.');
-
-
- $query = array(
- 'type' => 'page',
- 'op' => 'Reset',
- );
- $this->backdropGet('test_exposed_remember', array('query' => $query));
- $this->assertFieldByName('type', 'All', 'Filter is reset to default using Reset button.');
-
-
- $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_remember/default/filter/type');
- $edit = array(
- 'options[expose][remember]' => FALSE,
- );
- $this->backdropPost(NULL, $edit, t('Apply'));
- $this->backdropPost(NULL, array(), t('Save'));
-
-
- $query = array(
- 'type' => 'page',
- );
- $this->backdropGet('test_exposed_remember', array('query' => $query));
- $this->assertFieldByName('type', 'page', 'Filter is set when visiting by query string.');
- $this->backdropGet('test_exposed_remember');
- $this->assertFieldByName('type', 'All', 'Filter is set to the default with no query string.');
- }
-
-
- * Tests the admin interface of exposed filter and sort items.
- */
- 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');
-
- $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter'));
-
-
-
- $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');
-
-
- $this->backdropPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
-
- $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
-
- $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
-
-
- $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');
-
-
- $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.'));
-
-
- $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'));
-
-
- $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
- $this->backdropPost(NULL, array(), t('Grouped filters'));
-
-
- $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');
-
-
-
-
- $this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
-
-
- $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'));
-
-
- $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;
-
-
- $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'));
-
-
- $this->backdropGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
- $this->backdropPost(NULL, array(), t('Hide filter'));
-
-
- $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');
-
-
- $edit = array();
- $this->backdropPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
-
- $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
- $this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
- }
- }