You are here

public function GoogleApplianceResultsDisplaySettingsCheck::testCase in Google Search Appliance 7

File

testing/google_appliance.test, line 577
Implements automated simpletest routines for integration testing of the Google Appliance module.

Class

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.

Code

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.');
  }
}