public function PathautoLocaleTest::testLanguagePatterns in Pathauto 8
Test that patterns work on multilingual content.
File
- tests/
src/ FunctionalJavascript/ PathautoLocaleTest.php, line 95
Class
- PathautoLocaleTest
- Test pathauto functionality with localization and translation.
Namespace
Drupal\Tests\pathauto\FunctionalJavascriptCode
public function testLanguagePatterns() {
// Allow other modules to add additional permissions for the admin user.
$permissions = [
'administer pathauto',
'administer url aliases',
'create url aliases',
'bypass node access',
'access content overview',
'administer languages',
'translate any entity',
'administer content translation',
];
$admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin_user);
// Add French language.
$edit = [
'predefined_langcode' => 'fr',
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$this
->enableArticleTranslation();
// Create a pattern for English articles.
$this
->drupalGet('admin/config/search/path/patterns/add');
$session = $this
->getSession();
$page = $session
->getPage();
$page
->fillField('type', 'canonical_entities:node');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->fillField('pattern', '/the-articles/[node:title]');
$page
->fillField('bundles[article]', TRUE);
$page
->fillField('languages[en]', TRUE);
$page
->fillField('label', 'English articles');
$this
->assertSession()
->waitForElementVisible('css', '#edit-label-machine-name-suffix .machine-name-value');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('Pattern English articles saved.');
// Create a pattern for French articles.
$this
->drupalGet('admin/config/search/path/patterns/add');
$page
->fillField('type', 'canonical_entities:node');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->fillField('pattern', '/les-articles/[node:title]');
$page
->fillField('bundles[article]', TRUE);
$page
->fillField('languages[fr]', TRUE);
$page
->fillField('label', 'French articles');
$this
->assertSession()
->waitForElementVisible('css', '#edit-label-machine-name-suffix .machine-name-value');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('Pattern French articles saved.');
// Create a node and its translation. Assert aliases.
$edit = [
'title[0][value]' => 'English node',
'langcode[0][value]' => 'en',
];
$this
->drupalPostForm('node/add/article', $edit, t('Save'));
$english_node = $this
->drupalGetNodeByTitle('English node');
return;
$this
->assertAlias('/node/' . $english_node
->id(), '/the-articles/english-node', 'en');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink(t('Add'));
$edit = [
'title[0][value]' => 'French node',
];
$this
->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$this
->rebuildContainer();
$english_node = $this
->drupalGetNodeByTitle('English node');
$french_node = $english_node
->getTranslation('fr');
$this
->assertAlias('/node/' . $french_node
->id(), '/les-articles/french-node', 'fr');
// Bulk delete and Bulk generate patterns. Assert aliases.
$this
->deleteAllAliases();
// Bulk create aliases.
$edit = [
'update[canonical_entities:node]' => TRUE,
];
$this
->drupalPostForm('admin/config/search/path/update_bulk', $edit, t('Update'));
$this
->assertSession()
->pageTextContains(t('Generated 2 URL aliases.'));
$this
->assertAlias('/node/' . $english_node
->id(), '/the-articles/english-node', 'en');
$this
->assertAlias('/node/' . $french_node
->id(), '/les-articles/french-node', 'fr');
}