summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2013-04-02 09:38:45 (GMT)
committer Gábor Hojtsy2013-04-02 09:38:45 (GMT)
commit1010f68d843eb350a0b27dbed0c1d8722ba49bb4 (patch)
treef13734c4feaf27bee37fc9ff84ab49b16ddd959e
parent7f5822661cb4e8faded298deaf0c12189baa9a03 (diff)
Issue #1954102 by vijaycs85, Gábor Hojtsy: Add testing for a multi-config file page; and fix bugs found on the way.
-rw-r--r--config_translation.admin.inc62
-rw-r--r--lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php31
2 files changed, 55 insertions, 38 deletions
diff --git a/config_translation.admin.inc b/config_translation.admin.inc
index 4741922..bbac6b3 100644
--- a/config_translation.admin.inc
+++ b/config_translation.admin.inc
@@ -237,22 +237,27 @@ function config_translation_form_submit(&$form, &$form_state) {
$language = $form_values['language'];
$group = $form_values['group'];
- foreach ($group->getNames() as $id => $name) {
- $config = config('locale.config.' . $language->langcode . '.' . $name);
- $base_config = config_translation_get_base_config($name);
+ // For the form submission handling, use the override free context.
+ config_context_enter('config.context.free');
- // Pass base configuration to check and save only overrides.
- config_translation_set_config($base_config, $config, $form_values[$id]);
- $saved_config = $config->get();
+ foreach ($group->getNames() as $id => $name) {
+ // Set config values based on form submission and original values.
+ $base_config = config($name);
+ $translation_config = config('locale.config.' . $language->langcode . '.' . $name);
+ config_translation_set_config($base_config, $translation_config, $form_values[$id]);
// If no overrides, delete language specific config file.
+ $saved_config = $translation_config->get();
if (empty($saved_config)) {
- $config->delete();
+ $translation_config->delete();
}
else {
- $config->save();
+ $translation_config->save();
}
}
+
+ config_context_leave();
+
drupal_set_message(t('Updated @language configuration translations successfully.', array('@language' => $language->name)));
$form_state['redirect'] = $group->getBasePath() . '/translate';
}
@@ -260,10 +265,11 @@ function config_translation_form_submit(&$form, &$form_state) {
/**
* Sets configuration based on a nested form value array.
*
- * @param array $base_config
- * An array of base language configuration values.
- * @param \Drupal\Core\Config\Config $config
- * Configuration instance. Values from $config_values will be set in this.
+ * @param \Drupal\Core\Config\Config $base_config
+ * Base language configuration values instance.
+ * @param \Drupal\Core\Config\Config $translation_config
+ * Translation configuration instance. Values from $config_values will be set
+ * in this instance.
* @param array $config_values
* A simple one dimensional or recursive array:
* - simple:
@@ -276,21 +282,21 @@ function config_translation_form_submit(&$form, &$form_state) {
* Either format is used, the nested arrays are just containers and not
* needed for saving the data.
*/
-function config_translation_set_config(array $base_config, Config $config, array $config_values) {
+function config_translation_set_config(Config $base_config, Config $translation_config, array $config_values) {
foreach ($config_values as $key => $value) {
if (is_array($value)) {
- return config_translation_set_config($base_config, $config, $value);
+ // Traverse into this level in the configuration.
+ config_translation_set_config($base_config, $translation_config, $value);
}
else {
- // Save value, if not same as original configuration.
- if ($base_config[$key] !== $value) {
- $config->set($key, $value);
+ // Save value, if different from original configuration. If same as
+ // original configuration, remove override.
+ if ($base_config->get($key) !== $value) {
+ $translation_config->set($key, $value);
}
else {
- // If same as original configuration, remove override.
- $config->clear($key);
+ $translation_config->clear($key);
}
-
}
}
}
@@ -437,19 +443,3 @@ function config_translation_enter_context($language) {
$account = new User(array('preferred_langcode' => $language->langcode), 'user');
$user_config_context->setAccount($account);
}
-
-/**
- * Helper to get base config data.
- *
- * @param string $name
- * Name of configuration.
- *
- * @return mixed
- * Array of configuration data. FALSE otherwise.
- */
-function config_translation_get_base_config($name) {
- config_context_enter('config.context.free');
- $base_config = config($name)->get();
- config_context_leave();
- return $base_config;
-}
diff --git a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php
index 78fa3fe..119a81d 100644
--- a/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php
+++ b/lib/Drupal/config_translation/Tests/ConfigTranslationUITest.php
@@ -32,8 +32,8 @@ class ConfigTranslationUITest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Configuration translation',
- 'description' => 'Add new language and translation site information',
- 'group' => 'Configuration',
+ 'description' => 'Translate settings and entities to various languages',
+ 'group' => 'Configuration translation',
);
}
@@ -221,6 +221,33 @@ class ConfigTranslationUITest extends WebTestBase {
}
/**
+ * Test case for account settings translation interface.
+ *
+ * This is the only special case so far where we have multiple config names
+ * involved building up one configuration translation form. Test that the
+ * translations are saved for all configuration names properly.
+ */
+ function testAccountSettingsConfigurationTranslation() {
+ $this->drupalGet('admin/config/people/accounts/translate');
+ $this->assertLinkByHref('admin/config/people/accounts/translate/add/fr');
+
+ // Update account settings fields for French.
+ $edit = array(
+ '0[anonymous]' => 'Anonyme',
+ '1[status_blocked][status_blocked.subject]' => 'Testing, your account is blocked.',
+ '1[status_blocked][status_blocked.body]' => 'Testing account blocked body.'
+ );
+
+ $this->drupalPost('admin/config/people/accounts/translate/add/fr', $edit, t('Save translation'));
+
+ // Make sure the changes are saved and loaded back properly.
+ $this->drupalGet('admin/config/people/accounts/translate/edit/fr');
+ foreach ($edit as $value) {
+ $this->assertRaw($value);
+ }
+ }
+
+ /**
* Helper to set site name and slogan for default language.
*
* @param string $site_name