t('Translation functionality'), 'desc' => t('Create a story with translation, modify the story outdating translation, and update translation.'), 'group' => t('Translation Tests'), ); } function setUp() { parent::setUp(); // enable modules $this->drupalModuleEnable('locale'); $this->drupalModuleEnable('translation'); } function tearDown() { parent::tearDown(); } function testContentTranslation() { // 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->addLanguage('en'); $this->addLanguage('es'); // set story content type to use Multilingual support with translation $this->drupalPostRequest('admin/content/types/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 store in english $node_title = 'Test Translation ' . $this->randomName(); $node = $this->createStory($node_title, 'Node body.', 'en'); // submit translation in spanish $node_trans_title = 'Test Traducción ' . $this->randomName(); $node_trans = $this->createTranslation($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->drupalPostRequest('node/' . $node->nid . '/edit', $edit, 'Save'); $this->assertWantedRaw(t('Story %title has been updated.', array('%title' => $node_title)), 'Original node updated.'); // update translation and mark as updated $edit = array(); $edit['body'] = 'Nodo cuerpo. Texto adicional.'; $edit['translation[status]'] = FALSE; $this->drupalPostRequest('node/' . $node_trans->nid . '/edit', $edit, 'Save'); $this->assertWantedRaw(t('Story %title has been updated.', array('%title' => $node_trans_title)), 'Translated node updated.'); } /** * Install a the specified language if it has not been already. Otherwise make sure that * the language is enabled. * * @param string $language_code The langauge code the check. */ function addLanguage($language_code) { // check to make sure that language has not already been installed $this->drupalGet('admin/settings/language'); if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) { // doesn't have language installed so add it $edit = array(); $edit['langcode'] = $language_code; $this->drupalPostRequest('admin/settings/language/add', $edit, 'Add language'); $languages = language_list('language', TRUE); // make sure not using cached version $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.'); if (array_key_exists($language_code, $languages)) $this->assertWantedRaw(t('The language %lang has been created and can now be used.', array('%lang' => $languages[$language_code])), 'Language has been added.'); } else { // ensure that it is enabled $this->assertTrue(true, 'Language [' . $language_code . '] already installed.'); $this->drupalPostRequest(NULL, array('enabled[' . $language_code . ']' => TRUE), 'Save configuration'); $this->assertWantedRaw(t('Configuration saved.'), 'Language successfully enabled.'); } } /** * Create a story in the specified language. * * @param string $title Title of story in specified language. * @param string $body Body of story in specified language. * @param string $language Langauge code. */ function createStory($title, $body, $language) { $this->drupalVariableSet('node_options_page', array('status', 'promote')); $edit = array(); $edit['title'] = $title; $edit['body'] = $body; $edit['language'] = $language; $this->drupalPostRequest('node/add/story', $edit, 'Save'); $this->assertWantedRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Story created.'); // check to make sure the node was created $node = node_load(array('title' => $edit['title'])); $this->assertTrue($node, 'Node found in database.'); return $node; } /** * Create a translation for the specified story in the specified language. * * @param integer $nid Node id of story to create translation for. * @param string $title Title of story in specified language. * @param string $body Body of story in specified language. * @param string $language Langauge code. */ function createTranslation($nid, $title, $body, $language) { $this->drupalGet('node/add/story', array('query' => array('translation' => $nid, 'language' => $language))); $edit = array(); $edit['title'] = $title; $edit['body'] = $body; $this->drupalPostRequest(NULL, $edit, 'Save'); $this->assertWantedRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Translation created.'); // check to make sure that translation was successfull $node = node_load(array('title' => $edit['title'])); $this->assertTrue($node, 'Node found in database.'); return $node; } }