public function DomainEntityReferenceTest::testDomainFieldStorage in Domain Access 8
Create content for a domain field.
File
- domain/
tests/ src/ Functional/ DomainEntityReferenceTest.php, line 67
Class
- DomainEntityReferenceTest
- Tests the domain record entity reference field type.
Namespace
Drupal\Tests\domain\FunctionalCode
public function testDomainFieldStorage() {
$this->admin_user = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
'administer node display',
'administer domains',
]);
$this
->drupalLogin($this->admin_user);
// Create test domain field.
$this
->domainCreateTestField();
// 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 test field', '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[{$one}]"] = TRUE;
$edit["field_domain[{$two}]"] = TRUE;
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$this
->assertResponse(200);
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load(1);
$values = $node
->get('field_domain');
// Get the expected value count.
$this
->assertCount(2, $values, 'Node saved with two domain records.');
}