public function DomainSourceElementTest::runInstalledTest in Domain Access 8
Basic test setup.
1 call to DomainSourceElementTest::runInstalledTest()
- DomainSourceElementTest::testDomainSourceElement in domain_source/
tests/ src/ Functional/ DomainSourceElementTest.php - Test runner.
File
- domain_source/
tests/ src/ Functional/ DomainSourceElementTest.php, line 52
Class
- DomainSourceElementTest
- Tests behavior for the domain source field element.
Namespace
Drupal\Tests\domain_source\FunctionalCode
public function runInstalledTest($node_type) {
$admin = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
'administer node display',
'administer domains',
'publish to any domain',
]);
$this
->drupalLogin($admin);
$this
->drupalGet('node/add/article');
$this
->assertSession()
->statusCodeEquals(200);
$nid = $node_type == 'article' ? 1 : 2;
// Set the title, so the node can be saved.
$this
->fillField('title[0][value]', 'Test node');
// We expect to find 5 domain options. We set two as selected.
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
$count = 0;
$ids = [
'example_com',
'one_example_com',
'two_example_com',
];
foreach ($domains as $domain) {
$locator = DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD . '[' . $domain
->id() . ']';
$this
->findField($locator);
if (in_array($domain
->id(), $ids)) {
$this
->checkField($locator);
}
}
// Find the all affiliates field.
$locator = DomainAccessManagerInterface::DOMAIN_ACCESS_ALL_FIELD . '[value]';
$this
->findField($locator);
// Set all affiliates to TRUE.
$this
->checkField($locator);
// Find the Domain Source field.
$locator = DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD;
$this
->findField($locator);
// Set it to one_example_com.
$this
->selectFieldOption($locator, 'one_example_com');
// Save the form.
$this
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
// Check the URL.
$url = $this
->geturl();
$this
->assert(strpos($url, 'node/' . $nid . '/edit') === FALSE, 'Form submitted.');
// Edit the node.
$this
->drupalGet('node/' . $nid . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
// Set the domain source field to an unselected domain.
$this
->selectFieldOption($locator, 'three_example_com');
// Save the form.
$this
->pressButton('edit-submit');
$this
->assertSession()
->pageTextContains('The source domain must be selected as a publishing option.');
// Check the URL.
$url = $this
->geturl();
$this
->assert(strpos($url, 'node/' . $nid . '/edit') > 0, 'Form not submitted.');
// Set the field properly and save again.
$this
->selectFieldOption($locator, 'one_example_com');
// Save the form.
$this
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
// Check the URL.
$url = $this
->geturl();
$this
->assert(strpos($url, 'node/' . $nid . '/edit') === FALSE, 'Form submitted.');
// Save with no source.
// Edit the node.
$this
->drupalGet('node/1/edit');
$this
->assertSession()
->statusCodeEquals(200);
// Set the domain source field to an unselected domain.
$this
->selectFieldOption($locator, '_none');
// Save the form.
$this
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
// Check the URL.
$url = $this
->geturl();
$this
->assert(strpos($url, 'node/' . $nid . '/edit') === FALSE, 'Form submitted.');
}