You are here

solr_multilingual.test in Apache Solr Multilingual 7

Same filename and directory in other branches
  1. 6.3 apachesolr_multilingual_confgen/tests/solr_multilingual.test

File

apachesolr_multilingual_confgen/tests/solr_multilingual.test
View source
<?php

/*
 * @file Test file for the multilingual indexing and search.
*/
class DrupalSolrMultilingualConfigTestCase extends AbstractDrupalSolrOnlineWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Solr Multilingual',
      'description' => 'Indexes multilingual content and queries it.',
      'group' => 'ApacheSolr Multilingual',
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp() {
    parent::setUp('apachesolr_multilingual', 'apachesolr_multilingual_confgen', 'apachesolr_confgen_textfiles');

    // REVIEW why isn't this triggered by the includes above?
    querypath_boot();
  }

  /**
   * Test search indexing.
   */
  function testSolrRunningUsingMultilingualDefaultConfig() {
    $solr_version = '1.4.x';
    $filesdir = variable_get('file_public_path');
    mkdir("{$filesdir}/solr_multlingual", 0777, TRUE);
    $filesdir = realpath("{$filesdir}/solr_multlingual");
    $files = array();
    foreach (array(
      'currency',
      'elevate',
      'schema',
      'solrconfig',
    ) as $file) {
      if ('currency' == $file && strpos($solr_version, '1.') === 0) {
        continue;
      }
      $qp = apachesolr_confgen_get_original_qp($file, $solr_version);
      drupal_alter('apachesolr_confgen_' . $file, $qp, $solr_version);
      $files[$file . '.xml'] = $qp
        ->find(':root')
        ->xml();
    }
    drupal_alter('apachesolr_confgen_zip_file', $files, $solr_version);
    $assert_files = array(
      'solrconfig.xml',
      'schema.xml',
      'elevate.xml',
    );
    foreach ($assert_files as $file_name) {
      $this
        ->assertTrue(array_key_exists($file_name, $files), 'Verify existence of ' . $file_name);
    }
    $assert_multilingual_files = array(
      'compoundwords.txt',
      'mapping-ISOLatin1Accent.txt',
      'protwords.txt',
      'stopwords.txt',
      'synonyms.txt',
    );
    $language_ids = array_keys(apachesolr_multilingual_language_list());
    $language_ids[] = '';
    foreach ($assert_multilingual_files as $file_name) {
      foreach ($language_ids as $language_id) {
        $i18n_file_name = !empty($language_id) ? str_replace('.txt', '_' . $language_id . '.txt', $file_name) : $file_name;
        $this
          ->assertTrue(array_key_exists($file_name, $files), 'Verify existence of ' . $i18n_file_name);
      }
    }
    foreach ($files as $file_name => $file_data) {
      file_put_contents($filesdir . '/' . $file_name, $file_data);
    }
    parent::setUpSolr($filesdir . '/*');
    if ($this->solr_available) {

      // workaround for drupal.org test bot
      $this
        ->assertTrue($this->solr
        ->ping(), "Verify solr server started with multilingual configuration");
      $response = $this->solr
        ->search("*:*", array(
        'qt' => 'standard',
      ));
      $response = $response->response;
      $this
        ->assertEqual($response->numFound, 0, "There should not be any documents in the index");
    }
    unset($filesdir);
  }

}