LanguageLocaleListTest.php in Drupal 9
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 {
protected static $modules = [
'language',
'locale',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
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
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$this
->assertSession()
->pageTextContains('The language French has been created and can now be used');
$this
->assertSession()
->addressEquals(Url::fromRoute('entity.configurable_language.collection'));
$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');
$options = $this
->assertSession()
->selectExists('edit-predefined-langcode')
->findAll('css', 'option');
$options = array_map(function ($item) {
return $item
->getText();
}, $options);
array_pop($options);
$options_ordered = $options;
natcasesort($options_ordered);
$this
->assertSame($options, $options_ordered, 'Language list is ordered.');
}
}