3 namespace Drupal\Tests\views\Functional;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\NodeInterface;
7 use Drupal\Tests\Traits\Core\CronRunTrait;
10 * Tests search integration filters with multilingual nodes.
14 class SearchMultilingualTest extends ViewTestBase {
23 public static $modules = ['node', 'search', 'language', 'content_translation'];
26 * Views used by this test.
30 public static $testViews = ['test_search'];
33 * Tests search with multilingual nodes.
35 public function testMultilingualSearchFilter() {
36 // Create a user with admin for languages, content, and content types, plus
37 // the ability to access content and searches.
38 $user = $this->drupalCreateUser(['administer nodes', 'administer content types', 'administer languages', 'administer content translation', 'access content', 'search content']);
39 $this->drupalLogin($user);
41 // Add Spanish language programmatically.
42 ConfigurableLanguage::createFromLangcode('es')->save();
44 // Create a content type and make it translatable.
45 $type = $this->drupalCreateContentType();
47 'language_configuration[language_alterable]' => TRUE,
49 $this->drupalPostForm('admin/structure/types/manage/' . $type->id(), $edit, t('Save content type'));
51 'entity_types[node]' => TRUE,
52 'settings[node][' . $type->id() . '][translatable]' => TRUE,
53 'settings[node][' . $type->id() . '][fields][title]' => TRUE,
54 'settings[node][' . $type->id() . '][fields][body]' => TRUE,
56 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
57 \Drupal::entityManager()->clearCachedDefinitions();
59 // Add a node in English, with title "sandwich".
61 'title' => 'sandwich',
62 'type' => $type->id(),
64 $node = $this->drupalCreateNode($values);
66 // "Translate" this node into Spanish, with title "pizza".
67 $node->addTranslation('es', ['title' => 'pizza', 'status' => NodeInterface::PUBLISHED]);
70 // Run cron so that the search index tables are updated.
73 // Test the keyword filter by visiting the page.
74 // The views are in the test view 'test_search', and they just display the
75 // titles of the nodes in the result, as links.
77 // Page with a keyword filter of 'pizza'. This should find the Spanish
78 // translated node, which has 'pizza' in the title, but not the English
79 // one, which does not have the word 'pizza' in it.
80 $this->drupalGet('test-filter');
81 $this->assertLink('pizza', 0, 'Found translation with matching title');
82 $this->assertNoLink('sandwich', 'Did not find translation with non-matching title');