public function DomainAccessLanguageSaveTest::testDomainAccessSave in Domain Access 8
Basic test setup.
File
- domain_access/
tests/ src/ Functional/ DomainAccessLanguageSaveTest.php, line 50
Class
- DomainAccessLanguageSaveTest
- Tests saving the domain access field elements in multiple languages.
Namespace
Drupal\Tests\domain_access\FunctionalCode
public function testDomainAccessSave() {
$storage = \Drupal::entityTypeManager()
->getStorage('node');
// Save a node programmatically.
$node = $storage
->create([
'type' => 'article',
'title' => 'Test node',
'uid' => '1',
'status' => 1,
DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD => [
'example_com',
],
DomainAccessManagerInterface::DOMAIN_ACCESS_ALL_FIELD => 1,
]);
$node
->save();
// Load the node.
$node = $storage
->load(1);
// Check that two values are set properly.
$manager = \Drupal::service('domain_access.manager');
$values = $manager
->getAccessValues($node);
$this
->assert(count($values) == 1, 'Node saved with one domain records.');
$value = $manager
->getAllValue($node);
$this
->assert($value == 1, 'Node saved to all affiliates.');
// Create an Afrikaans translation assigned to domain 2.
$translation = $node
->addTranslation('af');
$translation->title->value = $this
->randomString();
$translation->{DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD} = [
'example_com',
'one_example_com',
];
$translation->{DomainAccessManagerInterface::DOMAIN_ACCESS_ALL_FIELD} = 0;
$translation->status = 1;
$node
->save();
// Load and check the translated node.
$parent_node = $storage
->load(1);
$node = $parent_node
->getTranslation('af');
$values = $manager
->getAccessValues($node);
$this
->assert(count($values) == 2, 'Node saved with two domain records.');
$value = $manager
->getAllValue($node);
$this
->assert($value == 0, 'Node not saved to all affiliates.');
}