home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (views_exposed_form.test)

This example Drupal source code file (views_exposed_form.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

account, admin_user, array, edit, expected_label, exposed, exposed_form, function, identifier, is, php, public, shown, true

The views_exposed_form.test Drupal example source code

<?php
// $Id: views_exposed_form.test,v 1.1.2.6 2010/11/25 20:07:44 dereine Exp $
/**
 * @file
 * Test exposed forms.
 */
class ViewsExposedFormTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Exposed forms',
      'description' => 'Test exosed forms functionality.',
      'group' => 'Views Plugins',
    );
  }

  public function setUp() {
    parent::setUp('views_ui');
    module_enable(array('views_ui'));
    // @TODO Figure out why it's required to clear the cache here.
    views_module_include('views_default.inc', TRUE);
    views_get_all_views(TRUE);
    menu_rebuild();
  }

  /**
   * Tests, whether and how the reset button can be renamed.
   */
  public function testRenameResetButton() {
    $account = $this->drupalCreateUser();
    $this->drupalLogin($account);
    // Create some random nodes.
    for ($i = 0; $i < 5; $i++) {
      $this->drupalCreateNode();
    }
    // Look at the page and check the label "reset".
    $this->drupalGet('test_rename_reset_button');
    // Rename the label of the 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();

    // Look whether ther reset button label changed.
    $this->drupalGet('test_rename_reset_button');

    $this->helperButtonHasLabel('edit-reset', $expected_label);
  }

  /**
   * Test the admin interface of exposed filter and sort items.
   */
  function testExposedAdminUi() {
    $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
    $this->drupalLogin($admin_user);
    menu_rebuild();
    $edit = array();

    $this->drupalGet('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'));

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

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

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

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

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_exposed_form.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.