You are here

protected function SearchApiWebTest::createIndex in Search API 7

Creates a test index via the UI and tests whether this works correctly.

1 call to SearchApiWebTest::createIndex()
SearchApiWebTest::testFramework in ./search_api.test
Tests correct admin UI, indexing and search behavior.

File

./search_api.test, line 166
Contains the SearchApiWebTest and the SearchApiUnitTest classes.

Class

SearchApiWebTest
Class for testing Search API functionality via the UI.

Code

protected function createIndex() {
  $values = array(
    'name' => '',
    'item_type' => '',
    'enabled' => 1,
    'description' => 'An index used for testing.',
    'server' => '',
    'options[cron_limit]' => 5,
  );
  $this
    ->drupalPost('admin/config/search/search_api/add_index', $values, t('Create index'));
  $this
    ->assertText(t('!name field is required.', array(
    '!name' => t('Index name'),
  )));
  $this
    ->assertText(t('!name field is required.', array(
    '!name' => t('Item type'),
  )));
  $this->index_id = $id = 'test_index';
  $values = array(
    'name' => 'Search API test index',
    'machine_name' => $id,
    'item_type' => 'search_api_test',
    'enabled' => 1,
    'description' => 'An index used for testing.',
    'server' => '',
    'options[cron_limit]' => 1,
  );
  $this
    ->drupalPost(NULL, $values, t('Create index'));
  $this
    ->assertText(t('The index was successfully created. Please set up its indexed fields now.'), 'The index was successfully created.');
  $found = strpos($this
    ->getUrl(), 'admin/config/search/search_api/index/' . $id) !== FALSE;
  $this
    ->assertTrue($found, 'Correct redirect.');
  $index = $this
    ->index();
  $this
    ->assertEqual($index->name, $values['name'], 'Name correctly inserted.');
  $this
    ->assertEqual($index->item_type, $values['item_type'], 'Index item type correctly inserted.');
  $this
    ->assertFalse($index->enabled, 'Status correctly inserted.');
  $this
    ->assertEqual($index->description, $values['description'], 'Description correctly inserted.');
  $this
    ->assertNull($index->server, 'Index server correctly inserted.');
  $this
    ->assertEqual($index->options['cron_limit'], $values['options[cron_limit]'], 'Cron batch size correctly inserted.');
  $values = array(
    'additional[field]' => 'parent',
  );
  $this
    ->drupalPost("admin/config/search/search_api/index/{$id}/fields", $values, t('Add fields'));
  $this
    ->assertText(t('The available fields were successfully changed.'), 'Successfully added fields.');
  $this
    ->assertText('Parent » ID', 'Added fields are displayed.');
  $values = array(
    'fields[id][type]' => 'integer',
    'fields[id][boost]' => '1.0',
    'fields[id][indexed]' => 1,
    'fields[title][type]' => 'text',
    'fields[title][boost]' => '5.0',
    'fields[title][indexed]' => 1,
    'fields[body][type]' => 'text',
    'fields[body][boost]' => '1.0',
    'fields[body][indexed]' => 1,
    'fields[type][type]' => 'string',
    'fields[type][boost]' => '1.0',
    'fields[type][indexed]' => 1,
    'fields[parent:id][type]' => 'integer',
    'fields[parent:id][boost]' => '1.0',
    'fields[parent:id][indexed]' => 1,
    'fields[parent:title][type]' => 'text',
    'fields[parent:title][boost]' => '5.0',
    'fields[parent:title][indexed]' => 1,
    'fields[parent:body][type]' => 'text',
    'fields[parent:body][boost]' => '1.0',
    'fields[parent:body][indexed]' => 1,
    'fields[parent:type][type]' => 'string',
    'fields[parent:type][boost]' => '1.0',
    'fields[parent:type][indexed]' => 1,
  );
  $this
    ->drupalPost(NULL, $values, t('Save changes'));
  $this
    ->assertText(t('The indexed fields were successfully changed. The index was cleared and will have to be re-indexed with the new settings.'), 'Field settings saved.');
  $values = array(
    'callbacks[search_api_alter_add_url][status]' => 1,
    'callbacks[search_api_alter_add_url][weight]' => 0,
    'callbacks[search_api_alter_add_aggregation][status]' => 1,
    'callbacks[search_api_alter_add_aggregation][weight]' => 10,
    'processors[search_api_case_ignore][status]' => 1,
    'processors[search_api_case_ignore][weight]' => 0,
    'processors[search_api_case_ignore][settings][fields][title]' => 1,
    'processors[search_api_case_ignore][settings][fields][body]' => 1,
    'processors[search_api_case_ignore][settings][fields][parent:title]' => 1,
    'processors[search_api_case_ignore][settings][fields][parent:body]' => 1,
    'processors[search_api_tokenizer][status]' => 1,
    'processors[search_api_tokenizer][weight]' => 20,
    'processors[search_api_tokenizer][settings][spaces]' => '[^\\p{L}\\p{N}]',
    'processors[search_api_tokenizer][settings][ignorable]' => '[-]',
    'processors[search_api_tokenizer][settings][fields][title]' => 1,
    'processors[search_api_tokenizer][settings][fields][body]' => 1,
    'processors[search_api_tokenizer][settings][fields][parent:title]' => 1,
    'processors[search_api_tokenizer][settings][fields][parent:body]' => 1,
  );
  $this
    ->drupalPost(NULL, $values, t('Add new field'));
  $values = array(
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][name]' => 'Test fulltext field',
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][type]' => 'fulltext',
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][fields][title]' => 1,
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][fields][body]' => 1,
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][fields][parent:title]' => 1,
    'callbacks[search_api_alter_add_aggregation][settings][fields][search_api_aggregation_1][fields][parent:body]' => 1,
  );
  $this
    ->drupalPost(NULL, $values, t('Save configuration'));
  $this
    ->assertText(t("The indexing workflow was successfully edited. All content was scheduled for re-indexing so the new settings can take effect."), 'Workflow successfully edited.');
  $this
    ->drupalGet("admin/config/search/search_api/index/{$id}");
  $this
    ->assertTitle('Search API test index | Drupal', 'Correct title when viewing index.');
  $this
    ->assertText('An index used for testing.', 'Description displayed.');
  $this
    ->assertText('Search API test entity', 'Item type displayed.');
  $this
    ->assertText(t('disabled'), '"Disabled" status displayed.');
}