summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorborisson_2017-07-24 09:23:37 (GMT)
committerJoris Vercammen2017-07-24 09:23:37 (GMT)
commitfe311204c2cc1325e16980df4a92b0d3f5d32a02 (patch)
tree3648d3472593f819dcece87c1f0e64868a13f9ac
parent9064a63c94a4accd9f5f6906479c2d689d4ba7f9 (diff)
Issue #2827808 by borisson_: Facets on multilangual site8.x-1.0-alpha11
-rw-r--r--README.txt7
-rw-r--r--tests/src/Functional/LanguageIntegrationTest.php51
2 files changed, 58 insertions, 0 deletions
diff --git a/README.txt b/README.txt
index d362124..86dfe1d 100644
--- a/README.txt
+++ b/README.txt
@@ -146,3 +146,10 @@ the chosen module (and others, probably) doesn't find the select element.
So the library should be attached to the block in custom code, we haven't done
this in facets because we don't want to support all possible frameworks.
See https://www.drupal.org/node/2853121 for more information.
+
+Q: Why are facets results links from another language showing in the facet
+results?
+A: Facets use the same limitations as the query object passed, so when using
+views, add a filter to the view to limit to one language.
+Otherwise, this is solved by adding a `hook_search_api_query_alter()` that
+limits the results to the current language.
diff --git a/tests/src/Functional/LanguageIntegrationTest.php b/tests/src/Functional/LanguageIntegrationTest.php
index b825d40..aeef243 100644
--- a/tests/src/Functional/LanguageIntegrationTest.php
+++ b/tests/src/Functional/LanguageIntegrationTest.php
@@ -151,6 +151,57 @@ class LanguageIntegrationTest extends FacetsTestBase {
$this->clickLink('item');
$this->assertTrue(strpos($this->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this->assertTrue(strpos($this->getUrl(), 'tyto_alba'), 'Found the facet in the url');
+ }
+
+ /**
+ * Tests facets where the count is different per language.
+ *
+ * @see https://www.drupal.org/node/2827808
+ */
+ public function testLanguageDifferences() {
+ $entity_test_storage = \Drupal::entityTypeManager()
+ ->getStorage('entity_test_mulrev_changed');
+ $entity_test_storage->create([
+ 'name' => 'foo bar baz',
+ 'body' => 'test test',
+ 'type' => 'item',
+ 'keywords' => ['orange', 'lol'],
+ 'category' => 'item_category',
+ 'langcode' => 'xx-lolspeak',
+ ])->save();
+ $entity_test_storage->create([
+ 'name' => 'foo bar baz',
+ 'body' => 'test test',
+ 'type' => 'item',
+ 'keywords' => ['orange', 'rofl'],
+ 'category' => 'item_category',
+ 'langcode' => 'xx-lolspeak',
+ ])->save();
+
+ $id = 'water_bear';
+ $this->createFacet('Water bear', $id, 'keywords');
+
+ $this->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/edit');
+
+ $this->assertEquals(2, $this->indexItems($this->indexId), '2 items were indexed.');
+
+ $this->drupalGet('search-api-test-fulltext');
+ $this->assertFacetBlocksAppear();
+ $this->assertSession()->pageTextContains('orange');
+ $this->assertSession()->pageTextContains('grape');
+ $this->assertSession()->pageTextContains('rofl');
+
+ $this->drupalPostForm(NULL, ['language' => 'xx-lolspeak'], 'Search');
+ $this->assertFacetBlocksAppear();
+ $this->assertSession()->pageTextContains('orange');
+ $this->assertSession()->pageTextContains('rofl');
+ $this->assertSession()->pageTextNotContains('grape');
+
+ $this->drupalPostForm(NULL, ['language' => 'en'], 'Search');
+ $this->assertFacetBlocksAppear();
+ $this->assertSession()->pageTextContains('orange');
+ $this->assertSession()->pageTextContains('grape');
+ $this->assertSession()->pageTextNotContains('rofl');
}
}