Commit 3e4c90d3 authored by catch's avatar catch

Issue #1386394 by David_Rothstein, Kristen Pol, tstoeckler: Add back the...

Issue #1386394 by David_Rothstein, Kristen Pol, tstoeckler: Add back the ability for install profiles (or at least distros) to pre-select a language or modify the language-selection screen
parent 78ed86e0
......@@ -418,13 +418,6 @@ function install_begin_request($class_loader, &$install_state) {
$container->get('string_translation')
->addTranslator($container->get('string_translator.file_translation'));
// Set the default language to the selected language, if any.
if (isset($install_state['parameters']['langcode'])) {
$default_language = new Language(array('id' => $install_state['parameters']['langcode']));
$container->get('language.default')->set($default_language);
\Drupal::translation()->setDefaultLangcode($install_state['parameters']['langcode']);
}
// Add list of all available profiles to the installation state.
$listing = new ExtensionDiscovery($container->get('app.root'));
$listing->setProfileDirectories(array());
......@@ -443,6 +436,19 @@ function install_begin_request($class_loader, &$install_state) {
}
}
// Use the language from the profile configuration, if available, to override
// the language previously set in the parameters.
if (isset($install_state['profile_info']['distribution']['langcode'])) {
$install_state['parameters']['langcode'] = $install_state['profile_info']['distribution']['langcode'];
}
// Set the default language to the selected language, if any.
if (isset($install_state['parameters']['langcode'])) {
$default_language = new Language(array('id' => $install_state['parameters']['langcode']));
$container->get('language.default')->set($default_language);
\Drupal::translation()->setDefaultLangcode($install_state['parameters']['langcode']);
}
// Override the module list with a minimal set of modules.
$module_handler = \Drupal::moduleHandler();
if (!$module_handler->moduleExists('system')) {
......
......@@ -118,7 +118,7 @@ protected function setUp() {
->set('app.root', DRUPAL_ROOT);
\Drupal::setContainer($this->container);
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
$this->visitInstaller();
// Select language.
$this->setUpLanguage();
......@@ -164,6 +164,13 @@ protected function setUp() {
}
}
/**
* Visits the interactive installer.
*/
protected function visitInstaller() {
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
}
/**
* Installer step: Select language.
*/
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Installer\DistributionProfileTranslationQueryTest.
*/
namespace Drupal\system\Tests\Installer;
use Drupal\Component\Serialization\Yaml;
use Drupal\simpletest\InstallerTestBase;
/**
* Tests distribution profile support with a 'langcode' query string.
*
* @group Installer
*
* @see \Drupal\system\Tests\Installer\DistributionProfileTranslationTest
*/
class DistributionProfileTranslationQueryTest extends InstallerTestBase {
/**
* {@inheritdoc}
*/
protected $langcode = 'de';
/**
* The distribution profile info.
*
* @var array
*/
protected $info;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->info = array(
'type' => 'profile',
'core' => \Drupal::CORE_COMPATIBILITY,
'name' => 'Distribution profile',
'distribution' => array(
'name' => 'My Distribution',
'langcode' => $this->langcode,
'install' => array(
'theme' => 'bartik',
),
),
);
// File API functions are not available yet.
$path = $this->siteDirectory . '/profiles/mydistro';
mkdir($path, 0777, TRUE);
file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
parent::setUp();
}
/**
* {@inheritdoc}
*/
protected function visitInstaller() {
// Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr'));
// Pass a different language code than the one set in the distribution
// profile. This distribution language should still be used.
// The unrouted URL assembler does not exist at this point, so we build the
// URL ourselves.
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
// The language should have been automatically detected, all following
// screens should be translated already.
$elements = $this->xpath('//input[@type="submit"]/@value');
$this->assertEqual((string) current($elements), 'Save and continue de');
$this->translations['Save and continue'] = 'Save and continue de';
// Check the language direction.
$direction = (string) current($this->xpath('/html/@dir'));
$this->assertEqual($direction, 'ltr');
// Verify that the distribution name appears.
$this->assertRaw($this->info['distribution']['name']);
// Verify that the requested theme is used.
$this->assertRaw($this->info['distribution']['install']['theme']);
// Verify that the "Choose profile" step does not appear.
$this->assertNoText('profile');
}
/**
* {@inheritdoc}
*/
protected function setUpLanguage() {
// This step is skipped, because the distribution profile uses a fixed
// language.
}
/**
* {@inheritdoc}
*/
protected function setUpProfile() {
// This step is skipped, because there is a distribution profile.
}
/**
* Confirms that the installation succeeded.
*/
public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getDisplayName());
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertText('German');
$this->assertNoText('English');
}
/**
* Returns the string for the test .po file.
*
* @param string $langcode
* The language code.
* @return string
* Contents for the test .po file.
*/
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Save and continue"
msgstr "Save and continue $langcode"
ENDPO;
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Installer\DistributionProfileTranslationTest.
*/
namespace Drupal\system\Tests\Installer;
use Drupal\Component\Serialization\Yaml;
use Drupal\simpletest\InstallerTestBase;
/**
* Tests distribution profile support.
*
* @group Installer
*
* @see \Drupal\system\Tests\Installer\DistributionProfileTest
*/
class DistributionProfileTranslationTest extends InstallerTestBase {
/**
* {@inheritdoc}
*/
protected $langcode = 'de';
/**
* The distribution profile info.
*
* @var array
*/
protected $info;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->info = array(
'type' => 'profile',
'core' => \Drupal::CORE_COMPATIBILITY,
'name' => 'Distribution profile',
'distribution' => array(
'name' => 'My Distribution',
'langcode' => $this->langcode,
'install' => array(
'theme' => 'bartik',
),
),
);
// File API functions are not available yet.
$path = $this->siteDirectory . '/profiles/mydistro';
mkdir($path, 0777, TRUE);
file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
parent::setUp();
}
/**
* {@inheritdoc}
*/
protected function visitInstaller() {
// Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
parent::visitInstaller();
// The language should have been automatically detected, all following
// screens should be translated already.
$elements = $this->xpath('//input[@type="submit"]/@value');
$this->assertEqual((string) current($elements), 'Save and continue de');
$this->translations['Save and continue'] = 'Save and continue de';
// Check the language direction.
$direction = (string) current($this->xpath('/html/@dir'));
$this->assertEqual($direction, 'ltr');
// Verify that the distribution name appears.
$this->assertRaw($this->info['distribution']['name']);
// Verify that the requested theme is used.
$this->assertRaw($this->info['distribution']['install']['theme']);
// Verify that the "Choose profile" step does not appear.
$this->assertNoText('profile');
}
/**
* {@inheritdoc}
*/
protected function setUpLanguage() {
// This step is skipped, because the distribution profile uses a fixed
// language.
}
/**
* {@inheritdoc}
*/
protected function setUpProfile() {
// This step is skipped, because there is a distribution profile.
}
/**
* Confirms that the installation succeeded.
*/
public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getDisplayName());
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertText('German');
$this->assertNoText('English');
}
/**
* Returns the string for the test .po file.
*
* @param string $langcode
* The language code.
* @return string
* Contents for the test .po file.
*/
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Save and continue"
msgstr "Save and continue $langcode"
ENDPO;
}
}
......@@ -29,12 +29,12 @@ protected function setUp() {
*/
public function testInstaller() {
// Verify that Drupal can't be immediately reinstalled.
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
$this->visitInstaller();
$this->assertRaw('Drupal already installed');
// Delete settings.php and attempt to reinstall again.
unlink($this->siteDirectory . '/settings.php');
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
$this->visitInstaller();
$this->setUpLanguage();
$this->setUpProfile();
$this->setUpSettings();
......
......@@ -26,7 +26,7 @@ protected function setUpLanguage() {
touch(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po');
// Check that all predefined languages show up with their native names.
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
$this->visitInstaller();
foreach (LanguageManager::getStandardLanguageList() as $langcode => $names) {
$this->assertOption('edit-langcode', $langcode);
$this->assertRaw('>' . $names[1] . '<');
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Installer\InstallerTranslationQueryTest.
*/
namespace Drupal\system\Tests\Installer;
use Drupal\simpletest\InstallerTestBase;
/**
* Installs Drupal in German and checks resulting site.
*
* @group Installer
*
* @see \Drupal\system\Tests\Installer\InstallerTranslationTest
*/
class InstallerTranslationQueryTest extends InstallerTestBase {
/**
* Overrides the language code in which to install Drupal.
*
* @var string
*/
protected $langcode = 'de';
/**
* {@inheritdoc}
*/
protected function visitInstaller() {
// Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
// The unrouted URL assembler does not exist at this point, so we build the
// URL ourselves.
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=' . $this->langcode);
// The language should have been automatically detected, all following
// screens should be translated already.
$elements = $this->xpath('//input[@type="submit"]/@value');
$this->assertEqual((string) current($elements), 'Save and continue de');
$this->translations['Save and continue'] = 'Save and continue de';
// Check the language direction.
$direction = (string) current($this->xpath('/html/@dir'));
$this->assertEqual($direction, 'ltr');
}
/**
* {@inheritdoc}
*/
protected function setUpLanguage() {
// The language was was preset by passing a query parameter in the URL, so
// no explicit language selection is necessary.
}
/**
* Verifies the expected behaviors of the installation result.
*/
public function testInstaller() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertText('German');
$this->assertNoText('English');
}
/**
* Returns the string for the test .po file.
*
* @param string $langcode
* The language code.
* @return string
* Contents for the test .po file.
*/
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Save and continue"
msgstr "Save and continue $langcode"
ENDPO;
}
}
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