public function DomainSourceExcludeTest::testDomainSourceExclude in Domain Access 8
Tests domain source excludes.
File
- domain_source/
tests/ src/ Functional/ DomainSourceExcludeTest.php, line 36
Class
- DomainSourceExcludeTest
- Tests behavior for excluding some links from rewriting.
Namespace
Drupal\Tests\domain_source\FunctionalCode
public function testDomainSourceExclude() {
// Create a node, assigned to a source domain.
$id = 'one_example_com';
$node_values = [
'type' => 'page',
'title' => 'foo',
DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD => $id,
];
$node = $this
->createNode($node_values);
// Variables for our tests.
$path = 'node/1';
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
$source = $domains[$id];
$expected = $source
->getPath() . $path;
$route_name = 'entity.node.canonical';
$route_parameters = [
'node' => 1,
];
$uri = 'entity:' . $path;
$uri_path = '/' . $path;
$options = [];
// Get the link using Url::fromRoute().
$url = Url::fromRoute($route_name, $route_parameters, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromRoute');
// Get the link using Url::fromUserInput()
$url = Url::fromUserInput($uri_path, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromUserInput');
// Get the link using Url::fromUri()
$url = Url::fromUri($uri, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromUri');
// Exclude the edit path from rewrites.
$config = $this
->config('domain_source.settings');
$config
->set('exclude_routes', [
'edit_form' => 'edit_form',
])
->save();
// Variables for our tests.
$path = 'node/1/edit';
$expected = base_path() . $path;
$route_name = 'entity.node.edit_form';
$route_parameters = [
'node' => 1,
];
$uri = 'internal:/' . $path;
$uri_path = '/' . $path;
$options = [];
// Because of path cache, we have to flush here.
drupal_flush_all_caches();
// Get the link using Url::fromRoute().
$url = Url::fromRoute($route_name, $route_parameters, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromRoute');
// Get the link using Url::fromUserInput()
$url = Url::fromUserInput($uri_path, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromUserInput');
// Get the link using Url::fromUri()
$url = Url::fromUri($uri, $options)
->toString();
$this
->assertEquals($expected, $url, 'fromUri');
}