Chris@0: drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); Chris@4: Chris@0: // Create and log in user. Chris@0: $test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']); Chris@0: $this->drupalLogin($test_user); Chris@0: Chris@0: // Add a new language. Chris@0: ConfigurableLanguage::createFromLangcode('es')->save(); Chris@0: Chris@0: // Set up times to be applied to the English and Spanish translations of the Chris@0: // node create time, so that they are filtered in/out in the Chris@0: // search_date_query_alter test module. Chris@0: $created_time_en = new \DateTime('February 10 2016 10PM'); Chris@0: $created_time_es = new \DateTime('March 19 2016 10PM'); Chris@0: $default_format = filter_default_format(); Chris@0: Chris@0: $node = $this->drupalCreateNode([ Chris@0: 'title' => 'Node EN', Chris@0: 'type' => 'page', Chris@0: 'body' => [ Chris@0: 'value' => $this->randomMachineName(32), Chris@0: 'format' => $default_format, Chris@0: ], Chris@0: 'langcode' => 'en', Chris@0: 'created' => $created_time_en->getTimestamp(), Chris@0: ]); Chris@0: Chris@0: // Add Spanish translation to the node. Chris@0: $translation = $node->addTranslation('es', ['title' => 'Node ES']); Chris@0: $translation->body->value = $this->randomMachineName(32); Chris@0: $translation->created->value = $created_time_es->getTimestamp(); Chris@0: $node->save(); Chris@0: Chris@0: // Update the index. Chris@0: $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); Chris@0: $plugin->updateIndex(); Chris@0: search_update_totals(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests searching with date filters that exclude some translations. Chris@0: */ Chris@0: public function testDateIntervalQueryAlter() { Chris@0: // Search for keyword node. Chris@0: $edit = ['keys' => 'node']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Search')); Chris@0: Chris@0: // The nodes must have the same node ID but the created date is different. Chris@0: // So only the Spanish translation must appear. Chris@0: $this->assertLink('Node ES', 0, 'Spanish translation found in search results'); Chris@0: $this->assertNoLink('Node EN', 'Search results do not contain English node'); Chris@0: } Chris@0: Chris@0: }