diff --git a/src/Tests/LanguageIntegrationTest.php b/src/Tests/LanguageIntegrationTest.php index 2f4b877..3709f08 100644 --- a/src/Tests/LanguageIntegrationTest.php +++ b/src/Tests/LanguageIntegrationTest.php @@ -7,27 +7,17 @@ namespace Drupal\search_api\Tests; -use Drupal\Component\Utility\Unicode; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\search_api\Entity\Index; -use Drupal\search_api\Entity\Server; -use Drupal\search_api\SearchApiException; /** - * Tests the overall functionality of the Search API framework and admin UI. + * Tests the language specific functions of the Search API UI. * * @group search_api */ class LanguageIntegrationTest extends WebTestBase { /** - * The ID of the search server used for this test. - * - * @var string - */ - protected $serverId; - - /** * The ID of the search index used for this test. * * @var string @@ -35,13 +25,6 @@ class LanguageIntegrationTest extends WebTestBase { protected $indexId; /** - * A storage instance for indexes. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $indexStorage; - - /** * Modules to enable for this test. * * @var string[] @@ -49,132 +32,19 @@ class LanguageIntegrationTest extends WebTestBase { public static $modules = array('node', 'search_api', 'search_api_test_backend', 'language'); /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - $this->indexStorage = \Drupal::entityManager()->getStorage('search_api_index'); - } - - /** - * Tests various operations via the Search API's admin UI. + * Tests language specific operations trough the UI. */ public function testFramework() { $this->drupalLogin($this->adminUser); - $this->createServer(); - $this->createIndex(); + $this->getTestServer(); + $index = $this->getTestIndex(); + $this->indexId = $index->id(); $this->checkMultilingualContentEntityTracking(); } /** - * Tests creating a search server via the UI. - */ - protected function createServer() { - $this->serverId = Unicode::strtolower($this->randomMachineName()); - $settings_path = $this->urlGenerator->generateFromRoute('entity.search_api_server.add_form', array(), array('absolute' => TRUE)); - - $this->drupalGet($settings_path); - $this->assertResponse(200, 'Server add page exists'); - - $edit = array( - 'name' => '', - 'status' => 1, - 'description' => 'A server used for testing.', - 'backend' => 'search_api_test_backend', - ); - - $this->drupalPostForm($settings_path, $edit, $this->t('Save')); - $this->assertText($this->t('@name field is required.', array('@name' => $this->t('Server name')))); - - $edit = array( - 'name' => 'Search API test server', - 'status' => 1, - 'description' => 'A server used for testing.', - 'backend' => 'search_api_test_backend', - ); - $this->drupalPostForm($settings_path, $edit, $this->t('Save')); - $this->assertText($this->t('@name field is required.', array('@name' => $this->t('Machine-readable name')))); - - $edit = array( - 'name' => 'Search API test server', - 'id' => $this->serverId, - 'status' => 1, - 'description' => 'A server used for testing.', - 'backend' => 'search_api_test_backend', - ); - - $this->drupalPostForm(NULL, $edit, $this->t('Save')); - - $this->assertText($this->t('The server was successfully saved.')); - $this->assertUrl('admin/config/search/search-api/server/' . $this->serverId, array(), 'Correct redirect to server page.'); - } - - /** - * Tests creating a search index via the UI. - */ - protected function createIndex() { - $settings_path = $this->urlGenerator->generateFromRoute('entity.search_api_index.add_form', array(), array('absolute' => TRUE)); - - $this->drupalGet($settings_path); - $this->assertResponse(200); - $edit = array( - 'status' => 1, - 'description' => 'An index used for testing.', - ); - - $this->drupalPostForm(NULL, $edit, $this->t('Save')); - $this->assertText($this->t('@name field is required.', array('@name' => $this->t('Index name')))); - $this->assertText($this->t('@name field is required.', array('@name' => $this->t('Machine-readable name')))); - $this->assertText($this->t('@name field is required.', array('@name' => $this->t('Data sources')))); - - $this->indexId = 'test_index'; - - $edit = array( - 'name' => 'Search API test index', - 'id' => $this->indexId, - 'status' => 1, - 'description' => 'An index used for testing.', - 'server' => $this->serverId, - 'datasources[]' => array('entity:node'), - ); - - $this->drupalPostForm(NULL, $edit, $this->t('Save')); - - $this->assertText($this->t('The index was successfully saved.')); - $this->assertUrl($this->getIndexPath(), array(), 'Correct redirect to index page.'); - - $this->indexStorage->resetCache(array($this->indexId)); - /** @var $index \Drupal\search_api\IndexInterface */ - $index = $this->indexStorage->load($this->indexId); - - if ($this->assertTrue($index, 'Index was correctly created.')) { - $this->assertEqual($index->label(), $edit['name'], 'Name correctly inserted.'); - $this->assertEqual($index->id(), $edit['id'], 'Index ID correctly inserted.'); - $this->assertTrue($index->status(), 'Index status correctly inserted.'); - $this->assertEqual($index->getDescription(), $edit['description'], 'Index ID correctly inserted.'); - $this->assertEqual($index->getServerId(), $edit['server'], 'Index server ID correctly inserted.'); - $this->assertEqual($index->getDatasourceIds(), $edit['datasources[]'], 'Index datasource id correctly inserted.'); - } - else { - // Since none of the other tests would work, bail at this point. - throw new SearchApiException(); - } - - // Test the "Save and edit" button. - $index2_id = 'test_index2'; - $edit['id'] = $index2_id; - unset($edit['server']); - $this->drupalPostForm($settings_path, $edit, $this->t('Save and edit')); - - $this->assertText($this->t('The index was successfully saved.')); - $this->indexStorage->resetCache(array($index2_id)); - $index = $this->indexStorage->load($index2_id); - $this->assertUrl($index->urlInfo('fields'), array(), 'Correct redirect to index fields page.'); - } - - /** * Make sure multilingual content entities are tracked correctly. */ protected function checkMultilingualContentEntityTracking() { @@ -189,7 +59,7 @@ class LanguageIntegrationTest extends WebTestBase { $this->assertEqual($tracked_items, 2, 'Two items are tracked.'); // Add a translation - $article1->addTranslation('nl', array('title' => 'test NL', 'body' => 'lol cats')) + $article1->addTranslation('nl', array('title' => 'test NL', 'body' => 'Dutch body')) ->save(); // The translation should be tracked as well