Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / tests / src / Functional / SearchMultilingualTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\NodeInterface;
7 use Drupal\Tests\Traits\Core\CronRunTrait;
8
9 /**
10  * Tests search integration filters with multilingual nodes.
11  *
12  * @group views
13  */
14 class SearchMultilingualTest extends ViewTestBase {
15
16   use CronRunTrait;
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = ['node', 'search', 'language', 'content_translation'];
24
25   /**
26    * Views used by this test.
27    *
28    * @var array
29    */
30   public static $testViews = ['test_search'];
31
32   /**
33    * Tests search with multilingual nodes.
34    */
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);
40
41     // Add Spanish language programmatically.
42     ConfigurableLanguage::createFromLangcode('es')->save();
43
44     // Create a content type and make it translatable.
45     $type = $this->drupalCreateContentType();
46     $edit = [
47       'language_configuration[language_alterable]' => TRUE,
48     ];
49     $this->drupalPostForm('admin/structure/types/manage/' . $type->id(), $edit, t('Save content type'));
50     $edit = [
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,
55     ];
56     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
57     \Drupal::entityManager()->clearCachedDefinitions();
58
59     // Add a node in English, with title "sandwich".
60     $values = [
61       'title' => 'sandwich',
62       'type' => $type->id(),
63     ];
64     $node = $this->drupalCreateNode($values);
65
66     // "Translate" this node into Spanish, with title "pizza".
67     $node->addTranslation('es', ['title' => 'pizza', 'status' => NodeInterface::PUBLISHED]);
68     $node->save();
69
70     // Run cron so that the search index tables are updated.
71     $this->cronRun();
72
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.
76
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');
83   }
84
85 }