You are here

google_appliance.test in Google Search Appliance 7

Implements automated simpletest routines for integration testing of the Google Appliance module.

File

testing/google_appliance.test
View source
<?php

/**
 * @file
 * Implements automated simpletest routines for integration testing of the Google
 * Appliance module.
 */

/**
 * test the hostname settings validator
 */
class GoogleApplianceSettingsValidateHostname extends DrupalWebTestCase {
  protected $search_user;
  public static function getInfo() {
    return array(
      'name' => 'Settings: Hostname',
      'description' => 'Ensure that the admin settings form validation catches bad-fomrmat hostname input and passes good input.',
      'group' => 'Google Appliance',
    );
  }
  public function setUp() {
    parent::setUp('google_appliance');

    // enables the module in test instance
    // create and log in user
    $this->search_user = $this
      ->drupalCreateUser(array(
      'administer_google_appliance',
      // admin perm
      'access_google_appliance_content',
    ));
    $this
      ->drupalLogin($this->search_user);

    // assert that we have access to the settings form
    $this
      ->assertResponse(200, t('Test administrator was allowed access to settings form.'));
  }
  public function testCase() {
    $settings = array(
      'hostname' => 'bad^*format.09menbdy',
      // bad setting
      'collection' => 'default_collection',
      'frontend' => 'default_frontend',
      'timeout' => 3,
      'autofilter' => '1',
      'query_inspection' => FALSE,
      'search_title' => $this
        ->randomName(),
      'results_per_page' => 16,
    );
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure that we see the error message
    $this
      ->assertText(t('GSA Host name must be a valid-format URL or IPv4 address'), t('<b>{MTP:2.2.1.5}</b> Found error message for invalid-format hostname (successful catch).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));
  }

}

/**
 * test the timeout settings validator
 */
class GoogleApplianceSettingsValidateTimeout extends DrupalWebTestCase {
  protected $search_user;
  public static function getInfo() {
    return array(
      'name' => 'Settings: Timeout',
      'description' => 'Ensure that the admin settings form validation implements boundaries and restrictions on timeout properly.',
      'group' => 'Google Appliance',
    );
  }
  public function setUp() {
    parent::setUp('google_appliance');

    // enables the module in test instance
    // create and log in user
    $this->search_user = $this
      ->drupalCreateUser(array(
      'administer_google_appliance',
      // admin perm
      'access_google_appliance_content',
    ));
    $this
      ->drupalLogin($this->search_user);

    // assert that we have access to the settings form
    $this
      ->assertResponse(200, t('Test administrator was allowed access to settings form.'));
  }
  public function testCase() {
    $settings = array(
      'hostname' => 'http://www.mygooglebox.net',
      'collection' => 'default_collection',
      'frontend' => 'default_frontend',
      'timeout' => '55kdsjeumnd90',
      // bad
      'autofilter' => '1',
      'query_inspection' => FALSE,
      'search_title' => $this
        ->randomName(),
      'results_per_page' => 16,
    );

    // non-numeric
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure that we see the error message
    $this
      ->assertText(t('Search Timeout should be an integer from'), t('<b>{MTP:2.2.2.5}</b> Found error message for invalid-format timeout (successful catch: non-numeric input).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));

    // below lower boundary
    $settings['timeout'] = 2;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure that we see the error message
    $this
      ->assertText(t('Search Timeout should be an integer from'), t('<b>{MTP:2.2.2.6}</b> Found error message for out of range timeout (successful catch: below lower boundary).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));

    // above upper boundary
    $settings['timeout'] = 31;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
    $this
      ->assertText(t('Search Timeout should be an integer from'), t('<b>{MTP:2.2.2.7}</b> Found error message for out of range timeout (successful catch: above upper boundary).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));

    // at lower boundary
    $settings['timeout'] = 3;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved'), t('<b>{MTP:2.2.2.8}</b> Successful save message found for timeout at lower boundary (successful pass).'));

    // at upper boundary
    $settings['timeout'] = 30;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved'), t('<b>{MTP:2.2.2.9}</b> Successful save message found for timeout at upper boundary (successful pass).'));
  }

}

/**
 * test results per page settings validator
 */
class GoogleApplianceSettingsValidateResultsPerPage extends DrupalWebTestCase {
  protected $search_user;
  public static function getInfo() {
    return array(
      'name' => 'Settings: Results per Page',
      'description' => 'Ensure that the admin settings form implements restrictions on results per page setting properly.',
      'group' => 'Google Appliance',
    );
  }
  public function setUp() {
    parent::setUp('google_appliance');

    // enables the module in test instance
    // create and log in user
    $this->search_user = $this
      ->drupalCreateUser(array(
      'administer_google_appliance',
      // admin perm
      'access_google_appliance_content',
    ));
    $this
      ->drupalLogin($this->search_user);

    // assert that we have access to the settings form
    $this
      ->assertResponse(200, t('Test administrator was allowed access to settings form.'));
  }
  public function testCase() {
    $settings = array(
      'hostname' => 'http://www.mygooglebox.net',
      'collection' => 'default_collection',
      'frontend' => 'default_frontend',
      'timeout' => 10,
      'autofilter' => '1',
      'query_inspection' => FALSE,
      'search_title' => $this
        ->randomName(),
      'results_per_page' => 'dfsjef',
    );

    // non-numeric
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure that we see the error message
    $this
      ->assertText(t('Results per page should be an integer from'), t('<b>{MTP:2.3.1.5}</b> Found error message invalid-format in results per page (successful catch: non-numeric input).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));

    // below minimum
    $settings['results_per_page'] = 0;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure we see the error message
    $this
      ->assertText(t('Results per page should be an integer from'), t('<b>{MTP:2.3.1.6}</b> Found error message for out of range results per page (successful catch: below minimum).'));

    // ensure we don't see the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (successful catch).'));

    // above maximum
    $settings['results_per_page'] = 1001;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // ensure we see the error message
    $this
      ->assertText(t('Results per page should be an integer from'), t('<b>{MTP:2.3.1.7}</b> Found error message for out of range results per page (successful catch: above maximum).'));

    // ensure that we don't have the success message
    $this
      ->assertNoText(t('The configuration options have been saved'), t('Successful save message not found (intended fail).'));

    // at upper boundary
    $settings['results_per_page'] = 1000;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved'), t('<b>{MTP:2.3.1.8}</b> Successful save message found for results per page at upper boundary (successful pass).'));

    // at lower boundary
    $settings['results_per_page'] = 1;
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved'), t('<b>{MTP:2.3.1.8}</b> Successful save message found for results per page at lower boundary (successful pass).'));
  }

}

/**
 * test that known-good settings produce a settings save
 */
class GoogleApplianceSettingsSave extends DrupalWebTestCase {
  protected $search_user;
  public static function getInfo() {
    return array(
      'name' => 'Settings: Save',
      'description' => 'Ensure that the admin settings form produces a success message upon save with good settings.',
      'group' => 'Google Appliance',
    );
  }
  public function setUp() {
    parent::setUp('google_appliance');

    // enables the module in test instance
    // create and log in user
    $this->search_user = $this
      ->drupalCreateUser(array(
      'administer_google_appliance',
      // admin perm
      'access_google_appliance_content',
    ));
    $this
      ->drupalLogin($this->search_user);

    // assert that we have access to the settings form
    $this
      ->assertResponse(200, t('Test administrator was allowed access to settings form.'));
  }
  public function testCase() {

    // create the known-good settings
    $settings = array(
      'hostname' => 'http://www.mygsa.net',
      'collection' => 'default_collection',
      'frontend' => 'default_frontend',
      'timeout' => 10,
      'autofilter' => '1',
      'query_inspection' => FALSE,
      'search_title' => $this
        ->randomName(),
      'results_per_page' => 16,
    );
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // look for success message
    $this
      ->assertText(t('The configuration options have been saved'), t('<b>{MTP:2.2.3.5}</b> Successful save message found after save attempt with good settings (successful pass).'));
  }

}

/** END admin settings tests **/

/**
 * Search Block availability: test the interaction for appearance of the block
 * search form via blocks administration, then be sure submission of that form
 * redirect to the results page.
 */
class GoogleApplianceSearchBlockAvailability extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Block: Search Form',
      'description' => 'Check if the search form block is available, and submission performs correct redirect.',
      'group' => 'Google Appliance',
    );
  }
  function setUp() {
    parent::setUp('google_appliance');

    // Create and login user
    $admin_user = $this
      ->drupalCreateUser(array(
      'administer blocks',
      'access_google_appliance_content',
    ));
    $this
      ->drupalLogin($admin_user);
  }

  // blocks admin interaction test
  function testCase_BlockAdmin() {

    // set block title to confirm that the interface is availble.
    $this
      ->drupalPost('admin/structure/block/manage/google_appliance/ga_block_search_form/configure', array(
      'title' => $this
        ->randomName(8),
    ), t('Save block'));

    // confirm block settings update
    $this
      ->assertText(t('The block configuration has been saved.'), t('<b>{MTP:2.3.2.5}</b> Block configuration set (successful interaction: block title set).'));

    // Set the block to a region to confirm block is availble.
    $edit = array();
    $edit['blocks[google_appliance_ga_block_search_form][region]'] = 'footer';
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
    $this
      ->assertText(t('The block settings have been updated.'), t('<b>{MTP:2.3.2.6}</b> Block successfully moved to footer region (successful interaction: block region assignment).'));
  }

  // submit-redirect test
  function testCase_BlockFormSubmitRedirect() {

    // hide the core search form from the front page
    $edit = array(
      'pages' => 'search',
    );
    $this
      ->drupalPost('admin/structure/block/manage/search/form/configure', $edit, t('Save block'));

    // put our search form on the frontpage in 'content' so soemthing is on the frontpage
    $edit = array();
    $edit['blocks[google_appliance_ga_block_search_form][region]'] = 'content';
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

    // go to the front page and submit the search form
    $terms = array(
      'search_keys' => 'test search',
    );
    $this
      ->drupalPost('node', $terms, t('Search'));

    // confirm that the user is redirected to the results apge
    $this
      ->assertEqual($this
      ->getUrl(), url('gsearch/' . $terms['search_keys'], array(
      'absolute' => TRUE,
    )), t('<b>{MTP:2.3.2.7}</b> Block Search Form sumbission redirected to correct url (successful interaction: block search form works as expected).'));
  }

}

/**
 * Results page search form: test that we get a blank page with the results page
 * search form, and any possible errors are hidden, then test that submitting a search
 * redirects back to the same page with terms in the form. Also tests effects of Page title
 * from module settings.
 */
class GoogleApplianceResultsPageSearchForm extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Results Page Search Form',
      'description' => 'Check that the results page search form is available, and that submissions
      redirect to back to the results page. The post-submission state is examined to be sure that the search keys are in the form field and we get a "No Results" message (connection isn\'t established as part of the test).',
      'group' => 'Google Appliance',
    );
  }
  function setUp() {
    parent::setUp('google_appliance');

    // Create and login user
    $search_user = $this
      ->drupalCreateUser(array(
      'access_google_appliance_content',
      'administer_google_appliance',
    ));
    $this
      ->drupalLogin($search_user);
  }
  public function testCase() {

    // go to settings and change the results page title
    $settings = array(
      'hostname' => 'http://www.mygsa.net',
      'collection' => 'default_collection',
      'frontend' => 'default_frontend',
      'timeout' => 10,
      'autofilter' => '1',
      'query_inspection' => FALSE,
      'search_title' => $this
        ->randomName(16),
      'results_per_page' => 16,
    );
    $this
      ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));

    // look for success message
    $this
      ->assertText(t('The configuration options have been saved'), t('Successful module settings save (changed the search title).'));

    // go to the results page
    $this
      ->drupalGet('gsearch');
    $this
      ->assertResponse(200, t('<b>{MTP:2.3.3.5}</b> Successfully went to the results page without a query (successful interaction: pre-search form state).'));

    // we should have the form
    $this
      ->assertFieldById('edit-search-keys', '', t('<b>{MTP:2.3.3.6}</b> Found the results page search form with empty field (expected behavior: pre-query search form state).'));

    // we should have the prompt
    $this
      ->assertText(t('Enter the terms you wish to search for.'), t('<b>{MTP:2.2.6.7}</b> Search prompt found on pre-serach state of results page (expected behavior).'));

    // we should not have any results text ... no results error messages begin
    // with the 'Search Results' heading
    $this
      ->assertNoText(t('Search Results'), t('<b>{MTP:2.3.3.8}</b> Pre-search page state does not include results messages (expected behavior).'));

    // submit the search form
    $terms = array(
      'search_keys' => $this
        ->randomName(8),
    );
    $this
      ->drupalPost('gsearch', $terms, t('Search'));

    // confirm that the user is redirected to the results page
    $this
      ->assertEqual($this
      ->getUrl(), url('gsearch/' . $terms['search_keys'], array(
      'absolute' => TRUE,
    )), t('<b>{MTP:2.3.3.9}</b> Results Page Search Form sumbission redirected to correct url (successful interaction).'));

    // check that we have the search query in the search keys field
    $this
      ->assertFieldByName('search_keys', $terms['search_keys'], t('<b>{MTP:2.3.3.10}</b> Found the results page search form with the search query in the search keys field (successful interaction).'));

    // ensure that we now have "No Results" text.
    $this
      ->assertText(t('No Results'), t('Post-search page state includes results messages (successful interaction).'));
  }

}

/**
 * Results page effects of module settings: verifies search interface settings and that
 * the connection provided in the test settings file produces search results. Highly dependent
 * upon good settings and a strategic choice of search query in the input file.
 */
class GoogleApplianceResultsDisplaySettingsCheck extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Results Page Settings',
      'description' => 'Check that module settings manifest in changes to the results page. <b>You must provide connection settings in a file</b> in the /testing directory within the module in
      order for real searches to execute. See the example file {module_directory}/google_appliance/testing/test-settings.example.inc for more info. Not providing the file simply aborts the tests requiring a connection to your device.',
      'group' => 'Google Appliance',
    );
  }
  function setUp() {
    parent::setUp('google_appliance');

    // Create and login user
    $search_user = $this
      ->drupalCreateUser(array(
      'access_google_appliance_content',
      'administer_google_appliance',
    ));
    $this
      ->drupalLogin($search_user);
  }
  public function testCase() {
    $testing_dir = drupal_get_path('module', 'google_appliance') . '/testing';
    $settings_fn = $testing_dir . '/test-settings.inc';
    $example_settings_fn = $testing_dir . '/test-settings.example.inc';
    if (file_exists($settings_fn)) {

      // grab the $file_spec array to config the module's connection settings
      include_once $settings_fn;

      // use those settings
      $settings = array(
        // define good settings
        'hostname' => $file_spec['hostname'],
        'collection' => $file_spec['collection'],
        'frontend' => $file_spec['frontend'],
        'timeout' => 10,
        'autofilter' => '1',
        'query_inspection' => FALSE,
        'search_title' => $this
          ->randomName(16),
        'results_per_page' => 16,
      );
      $this
        ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
      $this
        ->assertText(t('The configuration options have been saved'), t('Successful module settings save .'));

      // submit the search specified in $file_spec via URL (form submission already tested)
      $this
        ->drupalGet('gsearch/' . $file_spec['query']);

      // make sure we get a response, and that it is not an error message
      $this
        ->assertResponse(200);
      $this
        ->assertNoText(t('No Results'), t('<b>{MTP:2.3.4.5}</b> Search via URL succeeded, and produced a results listing (successful interaction: search workflow).'));

      // make sure the page title text is what we have in module settings
      $this
        ->assertText($settings['search_title'], t('<b>{MTP:2.3.4.6}</b> Found the search title from module settings on the page (successful manipulation: search title).'));

      // verify that the result index of last result on the page doesn't exceed
      // the results_per_page setting
      $this
        ->assertNoRaw('<li class="search-result search-google-appliance-result" id="result-' . ((int) $settings['results_per_page'] + 1) . '">', t('<b>{MTP:2.3.4.7}</b> The number of results on the page does not exceed results per page setting: @num (successful manipuliation: results per page)', array(
        '@num' => $settings['results_per_page'],
      )));

      // change the results per page count to 1 to verify that we have an exact match
      // for the results per page setting (the previous test just verifies that we didn't
      // exceed the count; this test MATCHES the count).
      $settings['results_per_page'] = 1;
      $this
        ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
      $this
        ->assertText(t('The configuration options have been saved'), t('Successful module settings save.'));
      $this
        ->drupalGet('gsearch/' . $file_spec['query']);

      // search via URL again
      $this
        ->assertRaw('<li class="search-result google-appliance-result" id="result-1">', t('<b>{MTP:2.3.4.8}</b> The number of results on the page exactly matches module setting: @num (successful manipulation: results per page)', array(
        '@num' => $settings['results_per_page'],
      )));

      // query inspection is left to manual testing
      // autofiltering effects are subjective, so manual test
    }
    else {
      $this
        ->error('Test settings file not found, aborting test. See ' . $example_settings_fn . ' for more information.');
    }
  }

}

/**
 * Results page elements: verifies elements that should appear on the results page,
 * and tests the functionality of the sort headers and pager
 */
class GoogleApplianceResultsPageFunctions extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Results Page Functions',
      'description' => 'Checks that the results page default templates provide feedback as expected, and that sorting and paging actually works. <b>You must provide connection settings in a file</b> in the /testing directory within the module in
      order for real searches to execute. See the example file {module_directory}/google_appliance/testing/test-settings.example.inc for more info. Not providing the file simply aborts the tests require a connection to your device.',
      'group' => 'Google Appliance',
    );
  }
  function setUp() {
    parent::setUp('google_appliance');

    // Create and login user
    $search_user = $this
      ->drupalCreateUser(array(
      'access_google_appliance_content',
      'administer_google_appliance',
    ));
    $this
      ->drupalLogin($search_user);
  }
  public function testCase() {
    $testing_dir = drupal_get_path('module', 'google_appliance') . '/testing';
    $settings_fn = $testing_dir . '/test-settings.inc';
    $example_settings_fn = $testing_dir . '/test-settings.example.inc';
    if (file_exists($settings_fn)) {

      // grab the $file_spec array to config the module's connection settings
      include_once $settings_fn;

      // use those settings
      $settings = array(
        // define good settings
        'hostname' => $file_spec['hostname'],
        'collection' => $file_spec['collection'],
        'frontend' => $file_spec['frontend'],
        'timeout' => 10,
        'autofilter' => '1',
        'query_inspection' => FALSE,
        'search_title' => $this
          ->randomName(16),
        'results_per_page' => 16,
      );
      $this
        ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
      $this
        ->assertText(t('The configuration options have been saved'), t('Successful module settings save .'));

      // submit the search specified in $file_spec via URL (form submission already tested)
      $this
        ->drupalGet('gsearch/' . $file_spec['query']);

      // make sure we get a response, and that it is not an error message
      $this
        ->assertResponse(200);
      $this
        ->assertNoText(t('No Results'), t('<b>{MTP:2.3.5.5}</b> Search via URL succeeded, and produced a results listing (successful interaction: search via URL.'));

      // verify that we have search stats report correctly
      $expectation = 'Showing results 1 - ' . $settings['results_per_page'] . ' for <em class="placeholder">' . $file_spec['query'] . '</em>';
      $this
        ->assertRaw($expectation, t('<b>{MTP:2.3.5.6}</b> Found search stats on page (successful interaction).'));

      // verify that sort headers display correctly
      // default state is "Relevance" not linked and "Date" linked
      $this
        ->assertText(t('Relevance'), t('<b>{MTP:2.3.5.7}</b> Relevance is current sort on results page (expected behavior)'));
      $this
        ->assertNoLink(t('Relevance'), t('Relevance sort heading is not linked (success).'));
      $this
        ->assertLink(t('Date'), 0, t('<b>{MTP:2.3.5.8}</b> Date sorter is linked (expected behavior).'));

      // verify that we have the pager, and that page 1 is marked current
      $this
        ->assertRaw('<ul class="pager">', t('<b>{MTP:2.3.5.9}</b> Pager found on results page (expected behavior)'));
      $this
        ->assertRaw('<li class="pager-current first">1</li>', t('<b>{MTP:2.3.5.10}</b> The first page in the pager list is marked current and not linked (expected behavior).'));

      //  verify paging function
      $this
        ->clickLink(t('2'), 0);
      $this
        ->assertNoText(t('No Results'), t('<b>{MTP:2.3.5.11}</b> Click on paging link produced next page of results (successful interaction).'));

      // verify that we have the pager, and that page 2 is marked current
      $this
        ->assertRaw('<ul class="pager">', t('Pager found on results page (success)'));
      $this
        ->assertRaw('<li class="pager-current">2</li>', t('<b>{MTP:2.3.5.12}</b> The second page in the pager list is marked current and not linked (successful interaction).'));

      // verify sorting function
      $this
        ->clickLink(t('Date'), 0);
      $this
        ->assertNoText(t('No Results'), t('Click on sorting link produced results page (success).'));
      $expectation = url('gsearch/' . $file_spec['query'], array(
        'absolute' => TRUE,
      )) . '/date?page=1';
      $result = $this
        ->getUrl();
      $this
        ->assertEqual($result, $expectation, t('<b>{MTP:2.3.5.13}</b> Sorting redirected to correct url [' . $result . '] (successful interaction).'));
      $this
        ->assertNoLink(t('Date'), t('<b>MTP:2.3.5.14}</b> Date is now the current sort and unlinked (success).'));
      $this
        ->clickLink(t('Relevance'), 1);

      // bottom bar (second) link
      $this
        ->assertNoText(t('No Results'), t('Click on sorting link produced results page (success).'));
      $this
        ->assertNoLink(t('Relevance'), t('Relevance is now the current sort and unlinked (success).'));
      $expectation = url('gsearch/' . $file_spec['query'], array(
        'absolute' => TRUE,
      )) . '/rel?page=1';
      $result = $this
        ->getUrl();
      $this
        ->assertEqual($result, $expectation, t('<b>{MTP:2.3.5.15}</b> Sorting redirected to correct url [' . $expectation . ' ?= ' . $result . '] (successful interaction).'));
    }
    else {
      $this
        ->error('Test settings file not found, aborting test. See ' . $example_settings_fn . ' for more information.');
    }
  }

}

/**
 * Block related searches: test that the block is available and displays as expected.
 */
class GoogleApplianceRelatedSearchesBlock extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Block: Related Searches',
      'description' => 'Checks that the related searches block is available and shows up on the results page. <b>You must provide connection settings in a file</b> in the /testing directory within the module in
      order for real searches to execute. See the example file {module_directory}/google_appliance/testing/test-settings.example.inc for more info. Not providing the file simply aborts the tests require a connection to your device.',
      'group' => 'Google Appliance',
    );
  }
  function setUp() {
    parent::setUp('google_appliance');

    // Create and login user
    $search_user = $this
      ->drupalCreateUser(array(
      'access_google_appliance_content',
      'administer_google_appliance',
      'administer blocks',
    ));
    $this
      ->drupalLogin($search_user);
  }
  public function testCase() {

    // set block title to confirm that the interface is available.
    $block_title = $this
      ->randomName(16);
    $this
      ->drupalPost('admin/structure/block/manage/google_appliance/ga_related_searches/configure', array(
      'title' => $block_title,
    ), t('Save block'));

    // confirm block settings update
    $this
      ->assertText(t('The block configuration has been saved.'), t('<b>{MTP:2.3.6.5}</b> Block title set (successful interaction).'));

    // Set the block to a region to confirm block is available.
    $edit = array();
    $edit['blocks[google_appliance_ga_related_searches][region]'] = 'content';
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
    $this
      ->assertText(t('The block settings have been updated.'), t('<b>{MTP:2.3.6.6}</b> Block successfully moved to footer region (successful interaction).'));

    // configure the module to connect
    $testing_dir = drupal_get_path('module', 'google_appliance') . '/testing';
    $settings_fn = $testing_dir . '/test-settings.inc';
    $example_settings_fn = $testing_dir . '/test-settings.example.inc';
    if (file_exists($settings_fn)) {

      // grab the $file_spec array to config the module's connection settings
      include_once $settings_fn;

      // use those settings
      $settings = array(
        // define good settings
        'hostname' => $file_spec['hostname'],
        'collection' => $file_spec['collection'],
        'frontend' => $file_spec['frontend'],
        'timeout' => 10,
        'autofilter' => '1',
        'query_inspection' => FALSE,
        'search_title' => $this
          ->randomName(16),
        'results_per_page' => 16,
      );
      $this
        ->drupalPost('admin/config/search/google_appliance/settings', $settings, t('Save configuration'));
      $this
        ->assertText(t('The configuration options have been saved'), t('Successful module settings save .'));

      // submit the search specified in $file_spec via URL (form submission already tested)
      $this
        ->drupalGet('gsearch/' . $file_spec['query']);

      // make sure we get a response, and that it is not an error message
      $this
        ->assertResponse(200);
      $this
        ->assertNoText(t('No Results'), t('Search via URL succeeded, and produced a results listing.'));

      // ensure that the block shows up
      $this
        ->assertText(t('@block_title', array(
        '@block_title' => $block_title,
      )), t('<b>{MTP:2.3.6.7}</b> Found block title for related search block on the page (expected behavior)'));

      // no real good way to identify the label of a related search link, so whether or not
      // clicking those links produce a new results page with the expected query (they do) is
      // left to manual testing
    }
    else {
      $this
        ->error('Test settings file not found, aborting test. See ' . $example_settings_fn . ' for more information.');
    }
  }

}

Classes

Namesort descending Description
GoogleApplianceRelatedSearchesBlock Block related searches: test that the block is available and displays as expected.
GoogleApplianceResultsDisplaySettingsCheck Results page effects of module settings: verifies search interface settings and that the connection provided in the test settings file produces search results. Highly dependent upon good settings and a strategic choice of search query in the input file.
GoogleApplianceResultsPageFunctions Results page elements: verifies elements that should appear on the results page, and tests the functionality of the sort headers and pager
GoogleApplianceResultsPageSearchForm Results page search form: test that we get a blank page with the results page search form, and any possible errors are hidden, then test that submitting a search redirects back to the same page with terms in the form. Also tests effects of Page…
GoogleApplianceSearchBlockAvailability Search Block availability: test the interaction for appearance of the block search form via blocks administration, then be sure submission of that form redirect to the results page.
GoogleApplianceSettingsSave test that known-good settings produce a settings save
GoogleApplianceSettingsValidateHostname test the hostname settings validator
GoogleApplianceSettingsValidateResultsPerPage test results per page settings validator
GoogleApplianceSettingsValidateTimeout test the timeout settings validator