diff --git a/src/Tests/PathautoNodeWebTest.php b/src/Tests/PathautoNodeWebTest.php index 825b679..a10cf10 100644 --- a/src/Tests/PathautoNodeWebTest.php +++ b/src/Tests/PathautoNodeWebTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\pathauto\Tests; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\pathauto\Entity\PathautoPattern; use Drupal\node\Entity\Node; use Drupal\pathauto\PathautoState; @@ -25,7 +26,7 @@ class PathautoNodeWebTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'pathauto', 'views', 'taxonomy', 'pathauto_views_test'); + public static $modules = array('node', 'locale', 'pathauto', 'views', 'taxonomy', 'pathauto_views_test'); /** * Admin user. @@ -146,6 +147,38 @@ class PathautoNodeWebTest extends WebTestBase { } /** + * Tests that nodes with the same title but different languages are properly + * handled. + */ + public function testNodeDifferentLanguages() { + $this->drupalLogin($this->rootUser); + + // Create a title-based node pattern. + $this->createPattern('node', '/prefix/[node:title]', -1); + + // Add predefined French language. + ConfigurableLanguage::createFromLangcode('fr')->save(); + + // Create two English articles with the same title. + $edit = [ + 'title' => 'Sample article', + 'type' => 'article', + 'langcode' => 'en', + ]; + $node1 = $this->drupalCreateNode($edit); + $this->assertEntityAlias($node1, '/prefix/sample-article', 'en'); + + $node2 = $this->drupalCreateNode($edit); + $this->assertEntityAlias($node2, '/prefix/sample-article-0', 'en'); + + // Now, create a French article with the same title, and verify that it gets + // the basic alias with the correct langcode. + $edit['langcode'] = 'fr'; + $node3 = $this->drupalCreateNode($edit); + $this->assertEntityAlias($node3, '/prefix/sample-article', 'fr'); + } + + /** * Test node operations. */ function testNodeOperations() {