You are here

public function DomainPathNodeAliasTest::testDomainPathNodeAliasesFill in Domain Path 8

Test domain path node aliases.

File

tests/src/Functional/DomainPathNodeAliasTest.php, line 22

Class

DomainPathNodeAliasTest
Tests the domain path node aliases saving from edit form.

Namespace

Drupal\Tests\domain_path\Functional

Code

public function testDomainPathNodeAliasesFill() {
  $edit = [];
  $edit['title[0][value]'] = $this
    ->randomMachineName(8);
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);
  foreach ($this->domains as $domain) {
    $domain_specific_alias_value = $this
      ->randomMachineName(8);
    $domain_specific_alias_path = "/{$domain_specific_alias_value}";
    $edit['domain_path[' . $domain
      ->id() . ']'] = $domain_specific_alias_path;
    if ($domain
      ->isDefault()) {
      $domain_paths_check['default'] = $domain_specific_alias_value;
    }
    else {
      $domain_paths_check['specific'] = $domain_specific_alias_value;
    }
  }
  $edit['path[0][alias]'] = '/' . $this
    ->randomMachineName(8);
  $this
    ->drupalPostForm('node/add/page', $edit, t('Save'));

  // Check that the node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $this
    ->assertTrue($node, 'Node found in database.');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  if (!empty($domain_paths_check['default'])) {
    $this
      ->drupalGet($domain_paths_check['default']);
    $this
      ->assertSession()
      ->statusCodeEquals(200);
  }
  if (!empty($domain_paths_check['specific'])) {
    $this
      ->drupalGet($domain_paths_check['specific']);
    $this
      ->assertSession()
      ->statusCodeNotEquals(200);
  }
}