summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-03-07 00:01:11 (GMT)
committerNathaniel Catchpole2016-03-07 00:01:11 (GMT)
commit64415a68659f181eeaf6c9c4e3d7322043adbc37 (patch)
tree7fca26e72bec12a1cb1725d15025b077c465c7bc
parente1d1a0545283d7ed95b00e7394ba744c957573f5 (diff)
Issue #2580177 by DuaelFr, GoZ: Language list is not correctly ordered when it's localized
-rw-r--r--core/modules/language/src/ConfigurableLanguageManager.php2
-rw-r--r--core/modules/language/src/Tests/LanguageLocaleListTest.php79
2 files changed, 80 insertions, 1 deletions
diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php
index 6b72a4f..59d6d54 100644
--- a/core/modules/language/src/ConfigurableLanguageManager.php
+++ b/core/modules/language/src/ConfigurableLanguageManager.php
@@ -472,7 +472,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
}
$predefined[$key] = new TranslatableMarkup($value[0]);
}
- asort($predefined);
+ natcasesort($predefined);
return $predefined;
}
diff --git a/core/modules/language/src/Tests/LanguageLocaleListTest.php b/core/modules/language/src/Tests/LanguageLocaleListTest.php
new file mode 100644
index 0000000..ca13172
--- /dev/null
+++ b/core/modules/language/src/Tests/LanguageLocaleListTest.php
@@ -0,0 +1,79 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\language\Tests\LanguageListTest.
+ */
+
+namespace Drupal\language\Tests;
+
+use Drupal\simpletest\WebTestBase;
+use Drupal\Core\Language\Language;
+use Drupal\Core\Language\LanguageInterface;
+
+/**
+ * Adds a new language with translations and tests language list order.
+ *
+ * @group language
+ */
+class LanguageLocaleListTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('language', 'locale');
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ // Add a default locale storage for all these tests.
+ $this->storage = $this->container->get('locale.storage');
+ }
+
+ /**
+ * Tests adding, editing, and deleting languages.
+ */
+ function testLanguageLocaleList() {
+ // User to add and remove language.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
+ $this->drupalLogin($admin_user);
+
+ // Add predefined language.
+ $edit = array(
+ 'predefined_langcode' => 'fr',
+ );
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
+ $this->assertText('The language French has been created and can now be used');
+ $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
+ $this->rebuildContainer();
+
+ // Translate Spanish language to French (Espagnol).
+ $source = $this->storage->createString(array(
+ 'source' => 'Spanish',
+ 'context' => '',
+ ))->save();
+ $this->storage->createTranslation(array(
+ 'lid' => $source->lid,
+ 'language' => 'fr',
+ 'translation' => 'Espagnol',
+ ))->save();
+
+ // Get language list displayed in select list.
+ $this->drupalGet('fr/admin/config/regional/language/add');
+ $select = $this->xpath('//select[@id="edit-predefined-langcode"]');
+ $select_element = (array) end($select);
+ $options = $select_element['option'];
+ // Remove the 'Custom language...' option form the end.
+ array_pop($options);
+ // Order language list.
+ $options_ordered = $options;
+ natcasesort($options_ordered);
+
+ // Check the language list displayed is ordered.
+ $this->assertTrue($options === $options_ordered, 'Language list is ordered.');
+ }
+}