Commit 8c5ffa32 authored by alexpott's avatar alexpott

Issue #2424171 by vijaycs85, likin, Gábor Hojtsy, Wim Leers: Language module...

Issue #2424171 by vijaycs85, likin, Gábor Hojtsy, Wim Leers: Language module vs. content translation module interaction exposes content translation bug
parent d5c9873b
......@@ -119,11 +119,16 @@ public function testLanguageBlockVisibilityLanguageDelete() {
* Tests block language visibility with different language types.
*/
public function testMultipleLanguageTypes() {
// Customize content language settings from their defaults.
// Customize content language detection to be different from interface
// language detection.
$edit = [
'language_content[configurable]' => TRUE,
// Interface language detection: only using session.
'language_interface[enabled][language-url]' => FALSE,
'language_interface[enabled][language-session]' => TRUE,
// Content language detection: only using URL.
'language_content[configurable]' => TRUE,
'language_content[enabled][language-url]' => TRUE,
'language_content[enabled][language-interface]' => FALSE,
];
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
......
......@@ -15,7 +15,6 @@ function content_translation_install() {
// Assign a fairly low weight to ensure our implementation of
// hook_module_implements_alter() is run among the last ones.
module_set_weight('content_translation', 10);
\Drupal::service('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0));
}
/**
......
......@@ -112,18 +112,18 @@ function testAliasTranslation() {
// Ensure the node was created.
$node_storage->resetCache(array($english_node->id()));
$english_node = $node_storage->load($english_node->id());
$french_node = $english_node->getTranslation('fr');
$english_node_french_translation = $english_node->getTranslation('fr');
$this->assertTrue($english_node->hasTranslation('fr'), 'Node found in database.');
// Confirm that the alias works.
$this->drupalGet('fr/' . $edit['path[0][alias]']);
$this->assertText($french_node->body->value, 'Alias for French translation works.');
$this->assertText($english_node_french_translation->body->value, 'Alias for French translation works.');
// Confirm that the alias is returned for the URL. Languages are cached on
// many levels, and we need to clear those caches.
$this->container->get('language_manager')->reset();
$languages = $this->container->get('language_manager')->getLanguages();
$url = $french_node->url('canonical', array('language' => $languages['fr']));
$url = $english_node_french_translation->url('canonical', array('language' => $languages['fr']));
$this->assertTrue(strpos($url, $edit['path[0][alias]']), 'URL contains the path alias.');
......@@ -150,11 +150,11 @@ function testAliasTranslation() {
// path alias for French matching the english alias. So the alias manager
// needs to use the URL language to check whether the alias is valid.
$this->drupalGet($english_alias);
$this->assertText($english_node->body->value, 'Alias for English translation works.');
$this->assertText($english_node_french_translation->body->value, 'English alias, but French preferred by the user: French translation.');
// Check that the French alias works.
$this->drupalGet("fr/$french_alias");
$this->assertText($french_node->body->value, 'Alias for French translation works.');
$this->assertText($english_node_french_translation->body->value, 'Alias for French translation works.');
// Disable URL language negotiation.
$edit = array('language_interface[enabled][language-url]' => FALSE);
......@@ -162,7 +162,7 @@ function testAliasTranslation() {
// Check that the English alias still works.
$this->drupalGet($english_alias);
$this->assertText($english_node->body->value, 'Alias for English translation works.');
$this->assertText($english_node_french_translation->body->value, 'English alias, but French preferred by the user: French translation.');
// Check that the French alias is not available. We check the unprefixed
// alias because we disabled URL language negotiation above. In this
......@@ -175,16 +175,16 @@ function testAliasTranslation() {
// it has the appropriate contents at this point.
$this->container->get('path.alias_manager')->cacheClear();
$french_node_path = $this->container->get('path.alias_manager')->getPathByAlias($french_alias, 'fr');
$this->assertEqual($french_node_path, 'node/' . $french_node->id(), 'Normal path works.');
$this->assertEqual($french_node_path, 'node/' . $english_node_french_translation->id(), 'Normal path works.');
// Second call should return the same path.
$french_node_path = $this->container->get('path.alias_manager')->getPathByAlias($french_alias, 'fr');
$this->assertEqual($french_node_path, 'node/' . $french_node->id(), 'Normal path is the same.');
$this->assertEqual($french_node_path, 'node/' . $english_node_french_translation->id(), 'Normal path is the same.');
// Confirm that the alias works.
$french_node_alias = $this->container->get('path.alias_manager')->getAliasByPath('node/' . $french_node->id(), 'fr');
$french_node_alias = $this->container->get('path.alias_manager')->getAliasByPath('node/' . $english_node_french_translation->id(), 'fr');
$this->assertEqual($french_node_alias, $french_alias, 'Alias works.');
// Second call should return the same alias.
$french_node_alias = $this->container->get('path.alias_manager')->getAliasByPath('node/' . $french_node->id(), 'fr');
$french_node_alias = $this->container->get('path.alias_manager')->getAliasByPath('node/' . $english_node_french_translation->id(), 'fr');
$this->assertEqual($french_node_alias, $french_alias, 'Alias is the same.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment