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