protected function SearchMultilingualEntityTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php \Drupal\Tests\search\Functional\SearchMultilingualEntityTest::setUp()
- 9 core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php \Drupal\Tests\search\Functional\SearchMultilingualEntityTest::setUp()
File
- core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php, line 48
Class
- SearchMultilingualEntityTest
- Tests entities with multilingual fields.
Namespace
Drupal\Tests\search\Functional
Code
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$user = $this
->drupalCreateUser([
'administer search',
'search content',
'use advanced search',
'access content',
'access site reports',
'administer site configuration',
]);
$this
->drupalLogin($user);
$this->plugin = $this->container
->get('plugin.manager.search')
->createInstance('node_search');
$this
->assertIndexCounts(0, 0, 'before adding nodes');
$this
->assertDatabaseCounts(0, 0, 'before adding nodes');
ConfigurableLanguage::createFromLangcode('hu')
->save();
ConfigurableLanguage::createFromLangcode('sv')
->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage
->setTranslatable(TRUE);
$field_storage
->save();
$default_format = filter_default_format();
$nodes = [
[
'title' => 'First node en',
'type' => 'page',
'body' => [
[
'value' => $this
->randomMachineName(32),
'format' => $default_format,
],
],
'langcode' => 'en',
],
[
'title' => 'Second node this is the English title',
'type' => 'page',
'body' => [
[
'value' => $this
->randomMachineName(32),
'format' => $default_format,
],
],
'langcode' => 'en',
],
[
'title' => 'Third node en',
'type' => 'page',
'body' => [
[
'value' => $this
->randomMachineName(32),
'format' => $default_format,
],
],
'langcode' => 'en',
],
[],
[],
[],
[],
[],
];
$this->searchableNodes = [];
foreach ($nodes as $setting) {
$this->searchableNodes[] = $this
->drupalCreateNode($setting);
}
$translation = $this->searchableNodes[1]
->addTranslation('hu', [
'title' => 'Second node hu',
]);
$translation->body->value = $this
->randomMachineName(32);
$this->searchableNodes[1]
->save();
$translation = $this->searchableNodes[2]
->addTranslation('hu', [
'title' => 'Third node this is the Hungarian title',
]);
$translation->body->value = $this
->randomMachineName(32);
$translation = $this->searchableNodes[2]
->addTranslation('sv', [
'title' => 'Third node sv',
]);
$translation->body->value = $this
->randomMachineName(32);
$this->searchableNodes[2]
->save();
$this
->assertIndexCounts(8, 8, 'before updating the search index');
$this
->assertDatabaseCounts(0, 0, 'before updating the search index');
}