You are here

function TranslationModuleTestCase::test_content_translation in SimpleTest 6

File

tests/translation_module.test, line 22

Class

TranslationModuleTestCase

Code

function test_content_translation() {

  // Setup users.
  $admin_user = $this
    ->drupalCreateUserRolePerm(array(
    'administer languages',
    'administer content types',
  ));
  $translator = $this
    ->drupalCreateUserRolePerm(array(
    'create story content',
    'edit own story content',
    'translate content',
  ));
  $this
    ->drupalLoginUser($admin_user);

  // Add languages.
  $this
    ->add_language('en');
  $this
    ->add_language('es');

  // Set story content type to use multilingual support with translation.
  $this
    ->drupalPost('admin/content/node-type/story', array(
    'language_content_type' => "2",
  ), 'Save content type');
  $this
    ->assertWantedRaw(t('The content type %type has been updated.', array(
    '%type' => 'Story',
  )), 'Story content type has been updated.');
  $this
    ->drupalGet('logout');
  $this
    ->drupalLoginUser($translator);

  // Create story in English.
  $node_title = 'Test Translation ' . $this
    ->randomName();
  $node = $this
    ->create_story($node_title, 'Node body.', 'en');

  // Submit translation in Spanish.
  $node_trans_title = 'Test Traduccion ' . $this
    ->randomName();
  $node_trans = $this
    ->create_translation($node->nid, $node_trans_title, 'Nodo cuerpo.', 'es');

  // Update origninal and mark translation as outdated.
  $edit = array();
  $edit['body'] = 'Node body. Additional Text.';
  $edit['translation[retranslate]'] = TRUE;
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
  $this
    ->assertWantedRaw(t('Story %title has been updated.', array(
    '%title' => $node_title,
  )), 'Original node updated.');

  // Check to make sure that interface shows translation as outdated
  $this
    ->drupalGet('node/' . $node->nid . '/translate');
  $this
    ->assertWantedRaw('<span class="marker">' . t('outdated') . '</span>', 'Translation marked as outdated.');

  // Update translation and mark as updated.
  $edit = array();
  $edit['body'] = 'Nodo cuerpo. Texto adicional.';
  $edit['translation[status]'] = FALSE;
  $this
    ->drupalPost('node/' . $node_trans->nid . '/edit', $edit, 'Save');
  $this
    ->assertWantedRaw(t('Story %title has been updated.', array(
    '%title' => $node_trans_title,
  )), 'Translated node updated.');
}