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->drupalGet('logout'); $this->drupalLoginUser($translator); // create store in english $node = $this->createStory('Test Translation ' . $this->randomName(), 'Node body.', 'en'); // submit translation in spanish $node_trans = $this->createTranslation($node->nid, 'Test Traducción ' . $this->randomName(), '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'); // 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'); } /** * 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.'); } else { // ensure that it is enabled $this->assertNotNull(true, 'Langauage [' . $language_code . '] already installed.'); $this->drupalPostRequest(NULL, array('enabled[' . $language_code . ']' => TRUE), 'Save configuration'); } } /** * 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'); // check to make sure the node was created $node = node_load(array('title' => $edit['title'])); $this->assertNotNull(($node === FALSE ? NULL : $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'); // check to make sure that translation was successfull $node = node_load(array('title' => $edit['title'])); $this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database.'); return $node; } }