You are here

public function DomainSourceParameterTest::testDomainSourceUrls in Domain Access 8

File

domain_source/tests/src/Functional/DomainSourceParameterTest.php, line 33

Class

DomainSourceParameterTest
Tests behavior for URLs that include query parameters.

Namespace

Drupal\Tests\domain_source\Functional

Code

public function testDomainSourceUrls() {

  // Create a node, assigned to a source domain.
  $id = 'example_com';
  $node = $this
    ->createNode([
    'type' => 'page',
    'title' => 'foo',
    DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD => $id,
  ]);

  // Variables for our tests.
  $path = 'domain-format-test';
  $options = [
    'query' => [
      '_format' => 'json',
    ],
  ];
  $domains = \Drupal::entityTypeManager()
    ->getStorage('domain')
    ->loadMultiple();
  foreach ($domains as $domain) {
    $this
      ->drupalGet($domain
      ->getPath() . $path, $options);
  }
  $source = $domains[$id];
  $uri_path = '/' . $path;
  $expected = base_path() . $path . '?_format=json';

  // Get the link using Url::fromUserInput()
  $url = Url::fromUserInput($uri_path, $options)
    ->toString();
  $this
    ->assertEquals($expected, $url, 'fromUserInput');
}