diff --git a/src/Tests/PathautoLocaleTest.php b/src/Tests/PathautoLocaleTest.php index feffb25..7ec7c78 100644 --- a/src/Tests/PathautoLocaleTest.php +++ b/src/Tests/PathautoLocaleTest.php @@ -100,14 +100,7 @@ class PathautoLocaleTest extends WebTestBase { ); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); - // Enable content translation on articles. - $this->drupalGet('admin/config/regional/content-language'); - $edit = array( - 'entity_types[node]' => TRUE, - 'settings[node][article][translatable]' => TRUE, - 'settings[node][article][settings][language][language_alterable]' => TRUE, - ); - $this->drupalPostForm(NULL, $edit, t('Save configuration')); + $this->enableArticleTranslation(); // Create a pattern for English articles. $this->drupalGet('admin/config/search/path/patterns/add'); @@ -173,4 +166,41 @@ class PathautoLocaleTest extends WebTestBase { $this->assertAlias('/node/' . $french_node->id(), '/les-articles/french-node', 'fr'); } + /** + * Tests the alias created for a node with language Not Applicable. + */ + 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->assertEqual($alias['langcode'], LanguageInterface::LANGCODE_NOT_SPECIFIED, 'PathautoGenerator::createEntityAlias() adjusts the alias langcode from Not Applicable to Not Specified.'); + + // Check that the alias works. + $this->drupalGet('content/test-node'); + $this->assertResponse(200); + } + + /** + * Enables content translation on articles. + */ + protected function enableArticleTranslation() { + // Enable content translation on articles. + $this->drupalGet('admin/config/regional/content-language'); + $edit = array( + 'entity_types[node]' => TRUE, + 'settings[node][article][translatable]' => TRUE, + 'settings[node][article][settings][language][language_alterable]' => TRUE, + ); + $this->drupalPostForm(NULL, $edit, t('Save configuration')); + } + } diff --git a/src/Tests/PathautoUnitTest.php b/src/Tests/PathautoUnitTest.php index a79eb8c..d2bddac 100644 --- a/src/Tests/PathautoUnitTest.php +++ b/src/Tests/PathautoUnitTest.php @@ -460,24 +460,6 @@ class PathautoUnitTest extends KernelTestBase { } /** - * Tests the alias created for a node with language Not Applicable. - */ - public function testLanguageNotApplicable() { - $pattern = $this->createPattern('node', '/content/[node:title]', -1); - $pattern->save(); - - $entity = \Drupal::entityManager()->getStorage('node')->create([ - 'title' => 'Sample page', - 'type' => 'page', - 'langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE, - ]); - $entity->save(); - - $alias = \Drupal::service('pathauto.alias_storage_helper')->loadBySource('/node/' . $entity->id()); - $this->assertEqual($alias['langcode'], LanguageInterface::LANGCODE_NOT_SPECIFIED, 'PathautoGenerator::createEntityAlias() adjusts the alias langcode from Not Applicable to Not Specified.'); - } - - /** * Creates a node programmatically. * * @param array $settings