View source
<?php
namespace Drupal\Tests\search\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class SearchDateIntervalTest extends BrowserTestBase {
protected static $modules = [
'language',
'search_date_query_alter',
'node',
'search',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$test_user = $this
->drupalCreateUser([
'access content',
'search content',
'use advanced search',
'administer nodes',
'administer languages',
'access administration pages',
'administer site configuration',
]);
$this
->drupalLogin($test_user);
ConfigurableLanguage::createFromLangcode('es')
->save();
$created_time_en = new \DateTime('February 10 2016 10PM');
$created_time_es = new \DateTime('March 19 2016 10PM');
$default_format = filter_default_format();
$node = $this
->drupalCreateNode([
'title' => 'Node EN',
'type' => 'page',
'body' => [
'value' => $this
->randomMachineName(32),
'format' => $default_format,
],
'langcode' => 'en',
'created' => $created_time_en
->getTimestamp(),
]);
$translation = $node
->addTranslation('es', [
'title' => 'Node ES',
]);
$translation->body->value = $this
->randomMachineName(32);
$translation->created->value = $created_time_es
->getTimestamp();
$node
->save();
$plugin = $this->container
->get('plugin.manager.search')
->createInstance('node_search');
$plugin
->updateIndex();
}
public function testDateIntervalQueryAlter() {
$edit = [
'keys' => 'node',
];
$this
->drupalPostForm('search/node', $edit, t('Search'));
$this
->assertSession()
->linkExists('Node ES', 0, 'Spanish translation found in search results');
$this
->assertSession()
->linkNotExists('Node EN', 'Search results do not contain English node');
}
}