Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\search\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@4
|
6 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests searching with date filters that exclude some translations.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group search
|
Chris@0
|
12 */
|
Chris@4
|
13 class SearchDateIntervalTest extends BrowserTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@4
|
16 * {@inheritdoc}
|
Chris@0
|
17 */
|
Chris@4
|
18 protected static $modules = ['language', 'search_date_query_alter', 'node', 'search'];
|
Chris@0
|
19
|
Chris@0
|
20 protected function setUp() {
|
Chris@0
|
21 parent::setUp();
|
Chris@0
|
22
|
Chris@4
|
23 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
Chris@4
|
24
|
Chris@0
|
25 // Create and log in user.
|
Chris@0
|
26 $test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']);
|
Chris@0
|
27 $this->drupalLogin($test_user);
|
Chris@0
|
28
|
Chris@0
|
29 // Add a new language.
|
Chris@0
|
30 ConfigurableLanguage::createFromLangcode('es')->save();
|
Chris@0
|
31
|
Chris@0
|
32 // Set up times to be applied to the English and Spanish translations of the
|
Chris@0
|
33 // node create time, so that they are filtered in/out in the
|
Chris@0
|
34 // search_date_query_alter test module.
|
Chris@0
|
35 $created_time_en = new \DateTime('February 10 2016 10PM');
|
Chris@0
|
36 $created_time_es = new \DateTime('March 19 2016 10PM');
|
Chris@0
|
37 $default_format = filter_default_format();
|
Chris@0
|
38
|
Chris@0
|
39 $node = $this->drupalCreateNode([
|
Chris@0
|
40 'title' => 'Node EN',
|
Chris@0
|
41 'type' => 'page',
|
Chris@0
|
42 'body' => [
|
Chris@0
|
43 'value' => $this->randomMachineName(32),
|
Chris@0
|
44 'format' => $default_format,
|
Chris@0
|
45 ],
|
Chris@0
|
46 'langcode' => 'en',
|
Chris@0
|
47 'created' => $created_time_en->getTimestamp(),
|
Chris@0
|
48 ]);
|
Chris@0
|
49
|
Chris@0
|
50 // Add Spanish translation to the node.
|
Chris@0
|
51 $translation = $node->addTranslation('es', ['title' => 'Node ES']);
|
Chris@0
|
52 $translation->body->value = $this->randomMachineName(32);
|
Chris@0
|
53 $translation->created->value = $created_time_es->getTimestamp();
|
Chris@0
|
54 $node->save();
|
Chris@0
|
55
|
Chris@0
|
56 // Update the index.
|
Chris@0
|
57 $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
Chris@0
|
58 $plugin->updateIndex();
|
Chris@0
|
59 search_update_totals();
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * Tests searching with date filters that exclude some translations.
|
Chris@0
|
64 */
|
Chris@0
|
65 public function testDateIntervalQueryAlter() {
|
Chris@0
|
66 // Search for keyword node.
|
Chris@0
|
67 $edit = ['keys' => 'node'];
|
Chris@0
|
68 $this->drupalPostForm('search/node', $edit, t('Search'));
|
Chris@0
|
69
|
Chris@0
|
70 // The nodes must have the same node ID but the created date is different.
|
Chris@0
|
71 // So only the Spanish translation must appear.
|
Chris@0
|
72 $this->assertLink('Node ES', 0, 'Spanish translation found in search results');
|
Chris@0
|
73 $this->assertNoLink('Node EN', 'Search results do not contain English node');
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 }
|