LanguageLocaleListTest.php in Drupal 8
File
core/modules/language/tests/src/Functional/LanguageLocaleListTest.php
View source
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class LanguageLocaleListTest extends BrowserTestBase {
public static $modules = [
'language',
'locale',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->storage = $this->container
->get('locale.storage');
}
public function testLanguageLocaleList() {
$admin_user = $this
->drupalCreateUser([
'administer languages',
'access administration pages',
]);
$this
->drupalLogin($admin_user);
$edit = [
'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(Url::fromRoute('entity.configurable_language.collection', [], [
'absolute' => TRUE,
])
->toString());
$this
->rebuildContainer();
$source = $this->storage
->createString([
'source' => 'Spanish',
'context' => '',
])
->save();
$this->storage
->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => 'Espagnol',
])
->save();
$this
->drupalGet('fr/admin/config/regional/language/add');
$option_elements = $this
->xpath('//select[@id="edit-predefined-langcode/option"]');
$options = [];
foreach ($option_elements as $option_element) {
$options[] = $option_element
->getText();
}
array_pop($options);
$options_ordered = $options;
natcasesort($options_ordered);
$this
->assertTrue($options === $options_ordered, 'Language list is ordered.');
}
}