Index: translation.admin.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/translation/translation.admin.inc,v
retrieving revision 1.3
diff -u -r1.3 translation.admin.inc
--- translation.admin.inc	3 Oct 2010 16:36:14 -0000	1.3
+++ translation.admin.inc	18 Oct 2010 19:09:29 -0000
@@ -370,6 +370,7 @@
   );
 
   $handler->setTranslation($translation, $form_state['values']);
+  field_attach_form_validate($form['#entity_type'], (object) $form['#entity'], $form, $form_state);
   field_attach_update($form['#entity_type'], $form['#entity']);
 
   // Update URL alias.
Index: translation.test
===================================================================
RCS file: translation.test
diff -N translation.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ translation.test	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,188 @@
+<?php
+// $Id: translation_node.test,v 1.1 2010/09/23 11:58:28 plach Exp $
+
+class TranslationTestCase extends DrupalWebTestCase {
+
+  /**
+   * Return the test information
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Translation functionality',
+      'description' => 'Create a basic page with translation and multivalue field.',
+      'group' => 'Translation',
+    );
+  }
+
+  /**
+   * Prepare basic test environment.
+   *
+   * Enable modules depending on.
+   */
+  function setUp() {
+    parent::setUp('locale', 'translation_node');
+  }
+
+  /**
+   * Test if field based translation works.
+   *
+   * Enable field based translation for basic pages.
+   * Add a field with a cardinality higher than 1, to test
+   * if field_default_extract_form_values() is invoked.
+   * Create basic page.
+   * Translate basic page.
+   */
+  function testFieldTranslation() {
+    // Setup users.
+    $user = $this->drupalCreateUser(array(
+      'administer languages',
+      'administer content types',
+      'access administration pages',
+      'create page content',
+      'edit own page content',
+      'translate content',
+      'translate any entity',
+    ));
+    $this->drupalLogin($user);
+
+    // Add languages.
+    $this->addLanguage('en');
+    $this->addLanguage('es');
+
+    // Configure Content Type
+    $this->configureContentType();
+
+    // Create Basic page in English.
+    $node_title = $this->randomName();
+    $node_body = $this->randomName();
+    $node = $this->createPage($node_title, $node_body, 'en');
+
+    // Submit translation in Spanish.
+    $node_translation_title = $this->randomName();
+    $node_translation_body = $this->randomName();
+    $node_translation = $this->createTranslation($node, $node_translation_title, $node_translation_body, 'es');
+  }
+
+  /**
+   * Install a specified language if it has not been already.
+   *
+   * Otherwise make sure that the language is enabled.
+   *
+   * @param string $language_code The language code the check.
+   */
+  function addLanguage($language_code) {
+    // Check to make sure that language has not already been installed.
+    $this->drupalGet('admin/config/regional/language');
+
+    if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
+      // Doesn't have language installed so add it.
+      $edit = array();
+      $edit['langcode'] = $language_code;
+      $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+      // Make sure we're not using a stale list.
+      drupal_static_reset('language_list');
+      $languages = language_list('language');
+      $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
+
+      if (array_key_exists($language_code, $languages)) {
+        $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), t('Language has been created.'));
+      }
+    }
+    elseif ($this->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(':name' => 'enabled[' . $language_code . ']'))) {
+      // It's installed and enabled. No need to do anything.
+      $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed and enabled.');
+    }
+    else {
+      // It's installed but not enabled. Enable it.
+      $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.');
+      $this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
+      $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
+    }
+  }
+
+  /**
+   * Configure content type for this test.
+   * Enable content translation
+   * Change body to multivalue field
+   */
+  function configureContentType() {
+    // Configure "Basic page" content type to use
+    // multilingual support with translation.
+    $this->drupalGet('admin/structure/types/manage/page');
+    $edit = array();
+    $edit['language_content_type'] = 4;
+    $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
+    $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
+
+    // Set body field to multivalue
+    $this->drupalGet('admin/structure/types/manage/page/fields/body');
+    $edit = array();
+    $edit['field[cardinality]'] = -1; // Unlimited
+    $this->drupalPost('admin/structure/types/manage/page/fields/body', $edit, t('Save settings'));
+    $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), t('Body field settings have been updated.'));
+
+    // Check if the multivalue setting works
+    $this->drupalGet('node/add/page');
+    $this->assertFieldById('edit-body-und-add-more', t('Add another item'), t('Add another item button found.'));
+  }
+
+  /**
+   * Create a "Basic page" in the specified language.
+   *
+   * @param string $title Title of basic page in specified language.
+   * @param string $body Body of basic page in specified language.
+   * @param string $language Language code.
+   */
+  function createPage($title, $body, $language) {
+    $edit = array();
+    $langcode = LANGUAGE_NONE;
+    $edit["title"] = $title;
+    $edit["body[$langcode][0][value]"] = $body;
+    $edit['language'] = $language;
+    $this->drupalPost('node/add/page', $edit, t('Save'));
+    $this->assertRaw(t('Basic page %title has been created.', array('%title' => $title)), t('Basic page created.'));
+
+    // Check to make sure the node was created.
+    $node = $this->drupalGetNodeByTitle($title);
+    $this->assertTrue($node, t('Node found in database.'));
+
+    return $node;
+  }
+
+  /**
+   * Create a translation.
+   *
+   * @param stdClass $node Node of the basic page to create translation for.
+   * @param string $title Title of basic page in specified language.
+   * @param string $body Body of basic page in specified language.
+   * @param string $language Language code.
+   */
+  function createTranslation($node, $title, $body, $language) {
+    $this->drupalGet('node/' . $node->nid . '/translate/add/es/en');
+
+    $body_key = "body[$language][0][value]";
+    $this->assertFieldByXPath(
+      "//textarea[@name='$body_key']",
+      $node->body[$node->language][0]['value'],
+      'Original body value correctly populated.'
+    );
+
+    $this->assertFieldById(
+      'edit-body-' . $language . '-add-more',
+      t('Add another item'),
+      t('Add another item button found.')
+    );
+
+    $edit = array();
+    $edit[$body_key] = $body;
+    $this->drupalPost(NULL, $edit, t('Save translation'));
+    $this->assertLinkByHref(
+      'node/' . $node->nid . '/translate/edit/' . $language,
+      0,
+      t('Translation edit link found. Translation created.')
+    );
+
+    return $node;
+  }
+}
