Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\views\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@0
|
6 use Drupal\node\NodeInterface;
|
Chris@0
|
7 use Drupal\Tests\Traits\Core\CronRunTrait;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests search integration filters with multilingual nodes.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group views
|
Chris@0
|
13 */
|
Chris@0
|
14 class SearchMultilingualTest extends ViewTestBase {
|
Chris@0
|
15
|
Chris@0
|
16 use CronRunTrait;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Modules to enable.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var array
|
Chris@0
|
22 */
|
Chris@0
|
23 public static $modules = ['node', 'search', 'language', 'content_translation'];
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * Views used by this test.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @var array
|
Chris@0
|
29 */
|
Chris@0
|
30 public static $testViews = ['test_search'];
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Tests search with multilingual nodes.
|
Chris@0
|
34 */
|
Chris@0
|
35 public function testMultilingualSearchFilter() {
|
Chris@0
|
36 // Create a user with admin for languages, content, and content types, plus
|
Chris@0
|
37 // the ability to access content and searches.
|
Chris@0
|
38 $user = $this->drupalCreateUser(['administer nodes', 'administer content types', 'administer languages', 'administer content translation', 'access content', 'search content']);
|
Chris@0
|
39 $this->drupalLogin($user);
|
Chris@0
|
40
|
Chris@0
|
41 // Add Spanish language programmatically.
|
Chris@0
|
42 ConfigurableLanguage::createFromLangcode('es')->save();
|
Chris@0
|
43
|
Chris@0
|
44 // Create a content type and make it translatable.
|
Chris@0
|
45 $type = $this->drupalCreateContentType();
|
Chris@0
|
46 $edit = [
|
Chris@0
|
47 'language_configuration[language_alterable]' => TRUE,
|
Chris@0
|
48 ];
|
Chris@0
|
49 $this->drupalPostForm('admin/structure/types/manage/' . $type->id(), $edit, t('Save content type'));
|
Chris@0
|
50 $edit = [
|
Chris@0
|
51 'entity_types[node]' => TRUE,
|
Chris@0
|
52 'settings[node][' . $type->id() . '][translatable]' => TRUE,
|
Chris@0
|
53 'settings[node][' . $type->id() . '][fields][title]' => TRUE,
|
Chris@0
|
54 'settings[node][' . $type->id() . '][fields][body]' => TRUE,
|
Chris@0
|
55 ];
|
Chris@0
|
56 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
|
Chris@0
|
57
|
Chris@0
|
58 // Add a node in English, with title "sandwich".
|
Chris@0
|
59 $values = [
|
Chris@0
|
60 'title' => 'sandwich',
|
Chris@0
|
61 'type' => $type->id(),
|
Chris@0
|
62 ];
|
Chris@0
|
63 $node = $this->drupalCreateNode($values);
|
Chris@0
|
64
|
Chris@0
|
65 // "Translate" this node into Spanish, with title "pizza".
|
Chris@0
|
66 $node->addTranslation('es', ['title' => 'pizza', 'status' => NodeInterface::PUBLISHED]);
|
Chris@0
|
67 $node->save();
|
Chris@0
|
68
|
Chris@0
|
69 // Run cron so that the search index tables are updated.
|
Chris@0
|
70 $this->cronRun();
|
Chris@0
|
71
|
Chris@0
|
72 // Test the keyword filter by visiting the page.
|
Chris@0
|
73 // The views are in the test view 'test_search', and they just display the
|
Chris@0
|
74 // titles of the nodes in the result, as links.
|
Chris@0
|
75
|
Chris@0
|
76 // Page with a keyword filter of 'pizza'. This should find the Spanish
|
Chris@0
|
77 // translated node, which has 'pizza' in the title, but not the English
|
Chris@0
|
78 // one, which does not have the word 'pizza' in it.
|
Chris@0
|
79 $this->drupalGet('test-filter');
|
Chris@0
|
80 $this->assertLink('pizza', 0, 'Found translation with matching title');
|
Chris@0
|
81 $this->assertNoLink('sandwich', 'Did not find translation with non-matching title');
|
Chris@0
|
82 }
|
Chris@0
|
83
|
Chris@0
|
84 }
|