public function DomainAccessEntityReferenceTest::testDomainAccessFieldStorage in Domain Access 8
Tests the storage of the domain access field.
File
- domain_access/
tests/ src/ Functional/ DomainAccessEntityReferenceTest.php, line 51
Class
- DomainAccessEntityReferenceTest
- Tests the domain access entity reference field type.
Namespace
Drupal\Tests\domain_access\FunctionalCode
public function testDomainAccessFieldStorage() {
$this->admin_user = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
'administer node display',
'administer domains',
'publish to any domain',
]);
$this
->drupalLogin($this->admin_user);
// Create 5 domains.
$this
->domainCreateTestDomains(5);
// Visit the article field display administration page.
$this
->drupalGet('node/add/article');
$this
->assertResponse(200);
// Check the new field exists on the page.
$this
->assertText('Domain Access', 'Found the domain field instance.');
// We expect to find 5 domain options.
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
foreach ($domains as $domain) {
$string = 'value="' . $domain
->id() . '"';
$this
->assertRaw($string, 'Found the domain option.');
if (!isset($one)) {
$one = $domain
->id();
continue;
}
if (!isset($two)) {
$two = $domain
->id();
}
}
// Try to post a node, assigned to the first two domains.
$edit['title[0][value]'] = 'Test node';
$edit["field_domain_access[{$one}]"] = TRUE;
$edit["field_domain_access[{$two}]"] = TRUE;
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$this
->assertResponse(200);
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load(1);
// Check that two values are set.
$values = \Drupal::service('domain_access.manager')
->getAccessValues($node);
$this
->assertCount(2, $values, 'Node saved with two domain records.');
}