You are here

protected function SearchApiWebTest::createServer in Search API 7

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

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

File

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

Class

SearchApiWebTest
Class for testing Search API functionality via the UI.

Code

protected function createServer() {
  $values = array(
    'name' => '',
    'enabled' => 1,
    'description' => 'A server used for testing.',
    'class' => '',
  );
  $this
    ->drupalPost('admin/config/search/search_api/add_server', $values, t('Create server'));
  $this
    ->assertText(t('!name field is required.', array(
    '!name' => t('Server name'),
  )));
  $this
    ->assertText(t('!name field is required.', array(
    '!name' => t('Service class'),
  )));
  $this->server_id = $id = 'test_server';
  $values = array(
    'name' => 'Search API test server',
    'machine_name' => $id,
    'enabled' => 1,
    'description' => 'A server used for testing.',
    'class' => 'search_api_test_service',
  );
  $this
    ->drupalPost(NULL, $values, t('Create server'));
  $values2 = array(
    'options[form][test]' => 'search_api_test foo bar',
  );
  $this
    ->drupalPost(NULL, $values2, t('Create server'));
  $this
    ->assertText(t('The server was successfully created.'));
  $found = strpos($this
    ->getUrl(), 'admin/config/search/search_api/server/' . $id) !== FALSE;
  $this
    ->assertTrue($found, 'Correct redirect.');
  $server = $this
    ->server();
  $this
    ->assertEqual($server->name, $values['name'], 'Name correctly inserted.');
  $this
    ->assertTrue($server->enabled, 'Status correctly inserted.');
  $this
    ->assertEqual($server->description, $values['description'], 'Description correctly inserted.');
  $this
    ->assertEqual($server->class, $values['class'], 'Service class correctly inserted.');
  $this
    ->assertEqual($server->options['test'], $values2['options[form][test]'], 'Service options correctly inserted.');
  $this
    ->assertTitle('Search API test server | Drupal', 'Correct title when viewing server.');
  $this
    ->assertText('A server used for testing.', 'Description displayed.');
  $this
    ->assertText('search_api_test_service', 'Service name displayed.');
  $this
    ->assertText('search_api_test foo bar', 'Service options displayed.');
}