You are here

public function PathautoLocaleTest::testLanguageNotApplicable in Pathauto 8

Tests the alias created for a node with language Not Applicable.

File

tests/src/FunctionalJavascript/PathautoLocaleTest.php, line 186

Class

PathautoLocaleTest
Test pathauto functionality with localization and translation.

Namespace

Drupal\Tests\pathauto\FunctionalJavascript

Code

public function testLanguageNotApplicable() {
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->enableArticleTranslation();

  // Create a pattern for nodes.
  $pattern = $this
    ->createPattern('node', '/content/[node:title]', -1);
  $pattern
    ->save();

  // Create a node with language Not Applicable.
  $node = $this
    ->createNode([
    'type' => 'article',
    'title' => 'Test node',
    'langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE,
  ]);

  // Check that the generated alias has language Not Specified.
  $alias = \Drupal::service('pathauto.alias_storage_helper')
    ->loadBySource('/node/' . $node
    ->id());
  $this
    ->assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED, $alias['langcode'], 'PathautoGenerator::createEntityAlias() adjusts the alias langcode from Not Applicable to Not Specified.');

  // Check that the alias works.
  $this
    ->drupalGet('content/test-node');
  $this
    ->assertSession()
    ->pageTextContains(t('Test node'));
}