diff --git a/src/Tests/ViewsTest.php b/src/Tests/ViewsTest.php index fae68b1..6d8b903 100644 --- a/src/Tests/ViewsTest.php +++ b/src/Tests/ViewsTest.php @@ -4,6 +4,8 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Url; +use Drupal\entity_test\Entity\EntityTestMulRevChanged; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\search_api\Entity\Index; use Drupal\search_api\Utility; @@ -21,7 +23,7 @@ class ViewsTest extends WebTestBase { * * @var string[] */ - public static $modules = array('search_api_test_views', 'views_ui'); + public static $modules = array('search_api_test_views', 'views_ui', 'language'); /** * A search index ID. @@ -36,6 +38,9 @@ class ViewsTest extends WebTestBase { public function setUp() { parent::setUp(); + // Add a second language. + ConfigurableLanguage::createFromLangcode('nl')->save(); + $this->setUpExampleStructure(); \Drupal::getContainer() ->get('search_api.index_task_manager') @@ -175,7 +180,7 @@ public function testView() { $this->checkResults($query, array(1, 2, 4, 5), 'Search with Keywords "not empty" filter'); $query = array( - 'language' => array('***LANGUAGE_language_content***'), + 'language' => array('***LANGUAGE_site_default***'), ); $this->checkResults($query, array(1, 2, 3, 4, 5), 'Search with "Page content language" filter'); $query = array( @@ -273,6 +278,19 @@ protected function checkResults(array $query, array $expected_results = NULL, $l * Test Views admin UI and field handlers. */ public function testViewsAdmin() { + // Add some Dutch nodes. + foreach (array(1, 2, 3, 4, 5) as $id) { + $entity = EntityTestMulRevChanged::load($id); + $entity = $entity->addTranslation('nl', array( + 'body' => "dutch node $id", + 'category' => "dutch category $id", + 'keywords' => array("dutch $id A", "dutch $id B"), + )); + $entity->save(); + } + $this->entities = EntityTestMulRevChanged::loadMultiple(); + $this->indexItems($this->indexId); + // For viewing the user name and roles of the user associated with test // entities, the logged-in user needs to have the permission to administer // both users and permissions. @@ -409,18 +427,28 @@ public function testViewsAdmin() { } $field_entity = $field_entity->{$direct_property}[0]->entity; } - if ($field != 'search_api_datasource') { - $data = Utility::extractFieldValues($field_entity->get($field)); - if (!$data) { - $data = array('[EMPTY]'); - } + // Check that both the English and the Dutch entity are present in the + // results, with their correct field values. + $entities = array($field_entity); + if ($field_entity->hasTranslation('nl')) { + $entities[] = $field_entity->getTranslation('nl'); } - else { - $data = array('entity:entity_test_mulrev_changed'); + foreach ($entities as $i => $field_entity) { + if ($field != 'search_api_datasource') { + $data = Utility::extractFieldValues($field_entity->get($field)); + if (!$data) { + $data = array('[EMPTY]'); + } + } + else { + $data = array('entity:entity_test_mulrev_changed'); + } + $row_num = 2 * $id + $i - 1; + $prefix = "#$row_num [$field] "; + $text = $prefix . implode("|$prefix", $data); + $translated = $i ? ' [translated]' : ''; + $this->assertText($text, "Correct value displayed for field $field on entity #$id (\"$text\")$translated"); } - $prefix = "#$id [$field] "; - $text = $prefix . implode("|$prefix", $data); - $this->assertText($text, "Correct value displayed for field $field on entity #$id (\"$text\")"); } } } diff --git a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.body.yml b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.body.yml index a03a334..80b2ed4 100644 --- a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.body.yml +++ b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.body.yml @@ -8,7 +8,7 @@ settings: { } module: text locked: false cardinality: 1 -translatable: false +translatable: true indexes: { } dependencies: module: diff --git a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.category.yml b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.category.yml index 98e32df..aaf1b13 100644 --- a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.category.yml +++ b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.category.yml @@ -9,7 +9,7 @@ settings: module: Core locked: false cardinality: 1 -translatable: false +translatable: true indexes: { } dependencies: module: diff --git a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.keywords.yml b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.keywords.yml index ae0fdcf..0354534 100644 --- a/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.keywords.yml +++ b/tests/search_api_test_example_content/config/install/field.storage.entity_test_mulrev_changed.keywords.yml @@ -9,7 +9,7 @@ settings: module: Core locked: false cardinality: -1 -translatable: false +translatable: true indexes: { } dependencies: module: