You are here

public function GoogleApplianceResultsPageFunctions::testCase in Google Search Appliance 7

File

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

Class

GoogleApplianceResultsPageFunctions
Results page elements: verifies elements that should appear on the results page, and tests the functionality of the sort headers and pager

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