You are here

class DrupalSolrOfflineEnvironmentWebTestCase in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 tests/apachesolr_base.test \DrupalSolrOfflineEnvironmentWebTestCase
  2. 7 tests/apachesolr_base.test \DrupalSolrOfflineEnvironmentWebTestCase

@file Unit test class that provides tests for base functionality of the Apachesolr Module without having the need of a Solr Server

Hierarchy

Expanded class hierarchy of DrupalSolrOfflineEnvironmentWebTestCase

File

tests/apachesolr_base.test, line 43
Unit test class that provides tests for base functionality of the Apachesolr Module without having the need of a Solr Server

View source
class DrupalSolrOfflineEnvironmentWebTestCase extends DrupalSolrOfflineWebTestCase {

  /**
   * A global basic user who can search.
   */
  var $basic_user;

  /**
   * A global administrative user who can administer search.
   */
  var $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Solr Search Environments',
      'description' => 'Tests search environments functionality of the Solr module',
      'group' => 'ApacheSolr',
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp() {
    parent::setUp('apachesolr', 'search', 'apachesolr_search', 'apachesolr_test');

    // Create a basic user, which is subject to moderation.
    $permissions = array(
      'access content',
      'search content',
    );
    $basic_user = $this
      ->drupalCreateUser($permissions);

    // Create an admin user that can bypass revision moderation.
    $permissions = array(
      'access content',
      'search content',
      'administer nodes',
      'administer search',
    );
    $admin_user = $this
      ->drupalCreateUser($permissions);

    // Assign users to their test suite-wide properties.
    $this->basic_user = $basic_user;
    $this->admin_user = $admin_user;
  }

  /**
   * Asserts that the module was installed and that a notice appears that the server is offline
   */
  function testServerOffline() {

    // Load the default server.
    $env_id = apachesolr_default_environment();
    $environment = apachesolr_environment_load($env_id);
    $environment['url'] = 'http://localhost/solr/core_that_should_not_exist';
    apachesolr_environment_save($environment);
    $status = apachesolr_server_status($environment['url']);
    $this
      ->assertFalse($status, t('A false URL could not be loaded and is offline'));
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('admin/config/search/apachesolr');
    $text = t('The server seems to be unavailable. Please verify the server settings');
    $this
      ->assertText($text, t('When checking the status of the server it gives the correct message to inform the user that the server is not reachable'));
  }

  /**
   * Asserts that the module was installed and that a notice appears that the server is offline
   */
  function testIndexFileIncluded() {
    $env_id = apachesolr_default_environment();
    $environment = apachesolr_environment_load($env_id);
    $environment['url'] = 'http://localhost/solr/core_that_should_not_exist';
    apachesolr_environment_save($environment);
    $paths = array(
      'user',
      'node',
      'admin/config/search/apachesolr',
      'admin/config/search/apachesolr/search-pages',
      'admin/config/search/apachesolr/search-pages/core_search/edit',
      'admin/structure/block/manage/apachesolr_search/mlt-001/configure',
      'admin/config/search/apachesolr/settings/solr/bias',
      'admin/config/search/apachesolr/settings/solr/index',
      'admin/config/search/apachesolr/settings/solr/edit',
      'admin/reports/apachesolr',
      'admin/reports/apachesolr/conf',
      'search/site',
    );
    $this
      ->drupalLogin($this->admin_user);
    foreach ($paths as $path) {
      $this
        ->drupalGet($path);
      $text = 'apachesolr.index.inc was included';
      $this
        ->assertNoText($text, t('Apachesolr.index.inc was not included'));
    }
  }

  /**
   * Asserts that we can edit a search environment
   */
  function testEditSearchEnvironment() {
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->clickLink(t('Edit'));
    $this
      ->assertText(t('Example: http://localhost:8983/solr'), t('Edit page was succesfully loaded'));
    $edit = array(
      'name' => 'new description foo bar',
      'url' => 'http://localhost:8983/solr/core_does_not_exists',
    );
    $this
      ->drupalPost($this
      ->getUrl(), $edit, t('Save'));
    $this
      ->assertResponse(200);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('new description foo bar'), t('Search environment description was succesfully edited'));
    $this
      ->assertText('http://localhost:8983/solr/core_does_not_exists', t('Search environment url was succesfully edited'));
  }

  /**
   * Asserts that we can use various url forms for the search environment
   */
  function testEditSearchEnvironmentURLs() {

    // Set the various url schemes that will be tested
    $urls = array(
      'http://user@localhost:8983/solr/core_does_not_exists',
      'http://user:pass@localhost:8983/solr/core_does_not_exists',
      'http://user:pass@localhost/solr/core_does_not_exists',
      'https://localhost:8983/solr/core_does_not_exists',
    );
    $this
      ->drupalLogin($this->admin_user);
    foreach ($urls as $url) {
      $this
        ->drupalGet('admin/config/search/apachesolr/settings');
      $this
        ->clickLink(t('Edit'));
      $this
        ->assertText(t('Example: http://localhost:8983/solr'), t('Edit page was succesfully loaded'));
      $edit = array(
        'url' => $url,
      );
      $this
        ->drupalPost($this
        ->getUrl(), $edit, t('Save'));
      $this
        ->assertResponse(200);
      $this
        ->drupalGet('admin/config/search/apachesolr/settings');
      $this
        ->assertText($url, t('Search environment url was succesfully set to !url', array(
        '!url' => $url,
      )));
    }
  }

  /**
   * Asserts that we can clone a search environment
   */
  function testCloneSearchEnvironment() {
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('Clone'), t('Clone button is available'));
    $this
      ->drupalGet('admin/config/search/apachesolr/settings/solr/clone');
    $this
      ->assertText(t('Are you sure you want to clone search environment localhost server'), t('Clone confirmation page was succesfully loaded'));
    $this
      ->drupalPost($this
      ->getUrl(), array(), t('Clone'));
    $this
      ->assertResponse(200);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('localhost server [cloned]'), t('Search Environment was succesfully cloned'));

    // Check if the bundles and configurations are exactly the same
    // after we clear the caches.
    apachesolr_environments_clear_cache();
    $envs = apachesolr_load_all_environments();
    $this
      ->assertEqual(count($envs), 2, 'Now we have 2 environments');
    $orig_env = $envs['solr'];
    unset($envs['solr']);
    $cloned_env = array_pop($envs);
    $this
      ->assertTrue($this
      ->_nestedCompare($orig_env['index_bundles'], $cloned_env['index_bundles']));
    $this
      ->assertTrue($this
      ->_nestedCompare($orig_env['conf'], $cloned_env['conf']));
  }

  /**
   * Asserts that we can edit a search environment
   */
  function testCreateNewSearchEnvironment() {

    // Create a new environment
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('Add search environment'), t('Create new environment link is available'));
    $this
      ->clickLink(t('Add search environment'));
    $this
      ->assertText(t('Make this Solr search environment the default'), t('Environment creation page succesfully added'));
    $edit = array(
      'url' => 'http://localhost:8983/solr',
      'name' => 'my test description',
      'env_id' => 'solr_test',
    );
    $this
      ->drupalPost($this
      ->getUrl(), $edit, t('Save'));
    $this
      ->assertResponse(200);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('my test description'), t('Search Environment was succesfully created'));

    // Make this new search environment the default
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');

    // Click on the second environment edit link
    $this
      ->clickLink(t('Edit'), 1);
    $this
      ->assertText(t('Example: http://localhost:8983/solr'), t('Edit page was succesfully loaded'));
    $edit = array(
      'make_default' => 1,
      'conf[apachesolr_read_only]' => APACHESOLR_READ_ONLY,
    );
    $this
      ->drupalPost($this
      ->getUrl(), $edit, t('Save'));
    $this
      ->assertResponse(200);
    $this
      ->drupalGet('admin/config/search/apachesolr/settings');
    $this
      ->assertText(t('my test description (Default)'), t('New Search environment was succesfully changed to default environment'));

    // Clear our cache.
    apachesolr_environments_clear_cache();
    $mode = apachesolr_environment_variable_get('solr_test', 'apachesolr_read_only', APACHESOLR_READ_WRITE);
    $this
      ->assertEqual($mode, APACHESOLR_READ_ONLY, 'Environment succesfully changed to read only');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalSolrOfflineEnvironmentWebTestCase::$admin_user property A global administrative user who can administer search.
DrupalSolrOfflineEnvironmentWebTestCase::$basic_user property A global basic user who can search.
DrupalSolrOfflineEnvironmentWebTestCase::getInfo public static function
DrupalSolrOfflineEnvironmentWebTestCase::setUp function Implementation of setUp().
DrupalSolrOfflineEnvironmentWebTestCase::testCloneSearchEnvironment function Asserts that we can clone a search environment
DrupalSolrOfflineEnvironmentWebTestCase::testCreateNewSearchEnvironment function Asserts that we can edit a search environment
DrupalSolrOfflineEnvironmentWebTestCase::testEditSearchEnvironment function Asserts that we can edit a search environment
DrupalSolrOfflineEnvironmentWebTestCase::testEditSearchEnvironmentURLs function Asserts that we can use various url forms for the search environment
DrupalSolrOfflineEnvironmentWebTestCase::testIndexFileIncluded function Asserts that the module was installed and that a notice appears that the server is offline
DrupalSolrOfflineEnvironmentWebTestCase::testServerOffline function Asserts that the module was installed and that a notice appears that the server is offline
DrupalSolrOfflineWebTestCase::_nestedCompare function