protected function NodeAccessLanguageAwareTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php \Drupal\Tests\node\Kernel\NodeAccessLanguageAwareTest::setUp()
- 9 core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php \Drupal\Tests\node\Kernel\NodeAccessLanguageAwareTest::setUp()
File
- core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php, line 48
Class
- NodeAccessLanguageAwareTest
- Tests node_access and select queries with node_access tag functionality with
multiple languages with node_access_test_language which is language-aware.
Namespace
Drupal\Tests\node\Kernel
Code
protected function setUp() : void {
parent::setUp();
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_private',
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
]);
$field_storage
->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'widget' => [
'type' => 'options_buttons',
],
'settings' => [
'on_label' => 'Private',
'off_label' => 'Not private',
],
])
->save();
node_access_rebuild();
$this->webUser = $this
->drupalCreateUser([
'access content',
]);
$this->adminUser = User::load(1);
ConfigurableLanguage::createFromLangcode('hu')
->save();
ConfigurableLanguage::createFromLangcode('ca')
->save();
$this->nodes['both_public'] = $node = $this
->drupalCreateNode([
'body' => [
[],
],
'langcode' => 'hu',
'field_private' => [
[
'value' => 0,
],
],
]);
$translation = $node
->addTranslation('ca');
$translation->title->value = $this
->randomString();
$translation->field_private->value = 0;
$node
->save();
$this->nodes['ca_private'] = $node = $this
->drupalCreateNode([
'body' => [
[],
],
'langcode' => 'hu',
'field_private' => [
[
'value' => 0,
],
],
]);
$translation = $node
->addTranslation('ca');
$translation->title->value = $this
->randomString();
$translation->field_private->value = 1;
$node
->save();
$this->nodes['hu_private'] = $node = $this
->drupalCreateNode([
'body' => [
[],
],
'langcode' => 'hu',
'field_private' => [
[
'value' => 1,
],
],
]);
$translation = $node
->addTranslation('ca');
$translation->title->value = $this
->randomString();
$translation->field_private->value = 0;
$node
->save();
$this->nodes['both_private'] = $node = $this
->drupalCreateNode([
'body' => [
[],
],
'langcode' => 'hu',
'field_private' => [
[
'value' => 1,
],
],
]);
$translation = $node
->addTranslation('ca');
$translation->title->value = $this
->randomString();
$translation->field_private->value = 1;
$node
->save();
$this->nodes['no_language_public'] = $this
->drupalCreateNode([
'field_private' => [
[
'value' => 0,
],
],
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$this->nodes['no_language_private'] = $this
->drupalCreateNode([
'field_private' => [
[
'value' => 1,
],
],
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
}