protected function BookMultilingualTest::setUp in Drupal 10
Same name and namespace in other branches
- 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::setUp()
File
- core/modules/book/tests/src/Kernel/BookMultilingualTest.php, line 50
Class
- BookMultilingualTest
- Tests multilingual books.
Namespace
Drupal\Tests\book\Kernel
Code
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'language',
]);
ConfigurableLanguage::create([
'id' => self::LANGCODE,
])
->save();
$config = $this
->config('language.types');
$config
->set('configurable', [
LanguageInterface::TYPE_INTERFACE,
LanguageInterface::TYPE_CONTENT,
]);
$config
->set('negotiation', [
LanguageInterface::TYPE_INTERFACE => [
'enabled' => [
LanguageNegotiationUser::METHOD_ID => 0,
],
],
LanguageInterface::TYPE_CONTENT => [
'enabled' => [
LanguageNegotiationUrl::METHOD_ID => 0,
],
],
]);
$config
->save();
$config = $this
->config('language.negotiation');
$config
->set('url.source', LanguageNegotiationUrl::CONFIG_DOMAIN);
$config
->set('url.domains', [
'en' => 'en.book.test.domain',
self::LANGCODE => self::LANGCODE . '.book.test.domain',
]);
$config
->save();
$this->container
->get('kernel')
->rebuildContainer();
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installSchema('book', [
'book',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installSchema('system', [
'sequences',
]);
$this
->installConfig([
'node',
'book',
'field',
]);
$node_type = NodeType::create([
'type' => $this
->randomMachineName(),
'name' => $this
->randomString(),
]);
$node_type
->save();
$this->container
->get('content_translation.manager')
->setEnabled('node', $node_type
->id(), TRUE);
$book_config = $this
->config('book.settings');
$allowed_types = $book_config
->get('allowed_types');
$allowed_types[] = $node_type
->id();
$book_config
->set('allowed_types', $allowed_types)
->save();
for ($root = 1; $root <= 8; $root += 7) {
for ($i = 0; $i <= 6; $i++) {
$node = Node::create([
'title' => $this
->randomString(),
'type' => $node_type
->id(),
]);
$node
->addTranslation(self::LANGCODE, [
'title' => $this
->randomString(),
]);
switch ($i) {
case 0:
$node->book['bid'] = 'new';
$node->book['pid'] = 0;
$node->book['depth'] = 1;
break;
case 1:
case 2:
$node->book['bid'] = $root;
$node->book['pid'] = $root;
$node->book['depth'] = 2;
break;
case 3:
case 4:
$node->book['bid'] = $root;
$node->book['pid'] = $root + 1;
$node->book['depth'] = 3;
break;
case 5:
case 6:
$node->book['bid'] = $root;
$node->book['pid'] = $root + 2;
$node->book['depth'] = 3;
break;
}
$node->book['weight'] = $i;
$node->nid->value = $root + $i;
$node
->enforceIsNew();
$node
->save();
}
}
\Drupal::currentUser()
->setAccount($this
->createUser([
'access content',
]));
}