Issue #2424171 by vijaycs85, likin, Gábor Hojtsy, Wim Leers: Language module vs. content translation module interaction exposes content translation bug
parent
d5c9873bcf
commit
8c5ffa3242
|
@ -119,11 +119,16 @@ class BlockLanguageTest extends WebTestBase {
|
||||||
* Tests block language visibility with different language types.
|
* Tests block language visibility with different language types.
|
||||||
*/
|
*/
|
||||||
public function testMultipleLanguageTypes() {
|
public function testMultipleLanguageTypes() {
|
||||||
// Customize content language settings from their defaults.
|
// Customize content language detection to be different from interface
|
||||||
|
// language detection.
|
||||||
$edit = [
|
$edit = [
|
||||||
'language_content[configurable]' => TRUE,
|
// Interface language detection: only using session.
|
||||||
'language_interface[enabled][language-url]' => FALSE,
|
'language_interface[enabled][language-url]' => FALSE,
|
||||||
'language_interface[enabled][language-session]' => TRUE,
|
'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'));
|
$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
|
// Assign a fairly low weight to ensure our implementation of
|
||||||
// hook_module_implements_alter() is run among the last ones.
|
// hook_module_implements_alter() is run among the last ones.
|
||||||
module_set_weight('content_translation', 10);
|
module_set_weight('content_translation', 10);
|
||||||
\Drupal::service('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -112,18 +112,18 @@ class PathLanguageTest extends PathTestBase {
|
||||||
// Ensure the node was created.
|
// Ensure the node was created.
|
||||||
$node_storage->resetCache(array($english_node->id()));
|
$node_storage->resetCache(array($english_node->id()));
|
||||||
$english_node = $node_storage->load($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.');
|
$this->assertTrue($english_node->hasTranslation('fr'), 'Node found in database.');
|
||||||
|
|
||||||
// Confirm that the alias works.
|
// Confirm that the alias works.
|
||||||
$this->drupalGet('fr/' . $edit['path[0][alias]']);
|
$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
|
// Confirm that the alias is returned for the URL. Languages are cached on
|
||||||
// many levels, and we need to clear those caches.
|
// many levels, and we need to clear those caches.
|
||||||
$this->container->get('language_manager')->reset();
|
$this->container->get('language_manager')->reset();
|
||||||
$languages = $this->container->get('language_manager')->getLanguages();
|
$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.');
|
$this->assertTrue(strpos($url, $edit['path[0][alias]']), 'URL contains the path alias.');
|
||||||
|
|
||||||
|
@ -150,11 +150,11 @@ class PathLanguageTest extends PathTestBase {
|
||||||
// path alias for French matching the english alias. So the alias manager
|
// 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.
|
// needs to use the URL language to check whether the alias is valid.
|
||||||
$this->drupalGet($english_alias);
|
$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.
|
// Check that the French alias works.
|
||||||
$this->drupalGet("fr/$french_alias");
|
$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.
|
// Disable URL language negotiation.
|
||||||
$edit = array('language_interface[enabled][language-url]' => FALSE);
|
$edit = array('language_interface[enabled][language-url]' => FALSE);
|
||||||
|
@ -162,7 +162,7 @@ class PathLanguageTest extends PathTestBase {
|
||||||
|
|
||||||
// Check that the English alias still works.
|
// Check that the English alias still works.
|
||||||
$this->drupalGet($english_alias);
|
$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
|
// Check that the French alias is not available. We check the unprefixed
|
||||||
// alias because we disabled URL language negotiation above. In this
|
// alias because we disabled URL language negotiation above. In this
|
||||||
|
@ -175,16 +175,16 @@ class PathLanguageTest extends PathTestBase {
|
||||||
// it has the appropriate contents at this point.
|
// it has the appropriate contents at this point.
|
||||||
$this->container->get('path.alias_manager')->cacheClear();
|
$this->container->get('path.alias_manager')->cacheClear();
|
||||||
$french_node_path = $this->container->get('path.alias_manager')->getPathByAlias($french_alias, 'fr');
|
$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.
|
// Second call should return the same path.
|
||||||
$french_node_path = $this->container->get('path.alias_manager')->getPathByAlias($french_alias, 'fr');
|
$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.
|
// 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.');
|
$this->assertEqual($french_node_alias, $french_alias, 'Alias works.');
|
||||||
// Second call should return the same alias.
|
// 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.');
|
$this->assertEqual($french_node_alias, $french_alias, 'Alias is the same.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue