| Line # | Frequency | Source Line | | 1 | | <?php
|
| 2 | | // $Id: translation.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
|
| 3 | |
|
| 4 | | class TranslationModuleTestCase extends DrupalTestCase {
|
| 5 | | var $book;
|
| 6 | |
|
| 7 | | function getInfo() {
|
| 8 | | return array(
|
| 9 | 1 | 'name' => t('Translation functionality'),
|
| 10 | | 'description' => t('Create a story with translation, modify the story outdating translation, and update translation.'),
|
| 11 | | 'group' => t('Translation Tests'),
|
| 12 | | );
|
| 13 | | }
|
| 14 | |
|
| 15 | | function setUp() {
|
| 16 | | parent::setUp();
|
| 17 | |
|
| 18 | | // Enable modules.
|
| 19 | | $this->drupalModuleEnable('locale');
|
| 20 | | $this->drupalModuleEnable('translation');
|
| 21 | | }
|
| 22 | |
|
| 23 | | function testContentTranslation() {
|
| 24 | | // Setup users.
|
| 25 | | $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
|
| 26 | | $translator = $this->drupalCreateUser(array('create story content', 'edit own story content', 'translate content'));
|
| 27 | |
|
| 28 | | $this->drupalLogin($admin_user);
|
| 29 | |
|
| 30 | | // Add languages.
|
| 31 | | $this->addLanguage('en');
|
| 32 | | $this->addLanguage('es');
|
| 33 | |
|
| 34 | | // Set story content type to use multilingual support with translation.
|
| 35 | | $this->drupalPost('admin/content/node-type/story', array('language_content_type' => "2"), t('Save content type'));
|
| 36 | | $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Story')), 'Story content type has been updated.');
|
| 37 | |
|
| 38 | | $this->drupalGet('logout');
|
| 39 | | $this->drupalLogin($translator);
|
| 40 | |
|
| 41 | | // Create story in English.
|
| 42 | | $node_title = 'Test Translation '. $this->randomName();
|
| 43 | | $node = $this->createStory($node_title, 'Node body.', 'en');
|
| 44 | |
|
| 45 | | // Submit translation in Spanish.
|
| 46 | | $node_trans_title = 'Test Traduccion '. $this->randomName();
|
| 47 | | $node_trans = $this->createTranslation($node->nid, $node_trans_title, 'Nodo cuerpo.', 'es');
|
| 48 | |
|
| 49 | | // Update origninal and mark translation as outdated.
|
| 50 | | $edit = array();
|
| 51 | | $edit['body'] = 'Node body. Additional Text.';
|
| 52 | | $edit['translation[retranslate]'] = TRUE;
|
| 53 | | $this->drupalPost('node/'. $node->nid .'/edit', $edit, t('Save'));
|
| 54 | | $this->assertRaw(t('Story %title has been updated.', array('%title' => $node_title)), 'Original node updated.');
|
| 55 | |
|
| 56 | | // Check to make sure that interface shows translation as outdated
|
| 57 | | $this->drupalGet('node/'. $node->nid .'/translate');
|
| 58 | | $this->assertRaw('<span class="marker">'. t('outdated') .'</span>', 'Translation marked as outdated.');
|
| 59 | |
|
| 60 | | // Update translation and mark as updated.
|
| 61 | | $edit = array();
|
| 62 | | $edit['body'] = 'Nodo cuerpo. Texto adicional.';
|
| 63 | | $edit['translation[status]'] = FALSE;
|
| 64 | | $this->drupalPost('node/'. $node_trans->nid .'/edit', $edit, t('Save'));
|
| 65 | | $this->assertRaw(t('Story %title has been updated.', array('%title' => $node_trans_title)), 'Translated node updated.');
|
| 66 | | }
|
| 67 | |
|
| 68 | | /**
|
| 69 | | * Install a the specified language if it has not been already. Otherwise make sure that
|
| 70 | | * the language is enabled.
|
| 71 | | *
|
| 72 | | * @param string $language_code The langauge code the check.
|
| 73 | | */
|
| 74 | | function addLanguage($language_code) {
|
| 75 | | // Check to make sure that language has not already been installed.
|
| 76 | | $this->drupalGet('admin/settings/language');
|
| 77 | |
|
| 78 | | if (strpos($this->drupalGetContent(), 'enabled['. $language_code .']') === FALSE) {
|
| 79 | | // Doesn't have language installed so add it.
|
| 80 | | $edit = array();
|
| 81 | | $edit['langcode'] = $language_code;
|
| 82 | | $this->drupalPost('admin/settings/language/add', $edit, t('Add language'));
|
| 83 | |
|
| 84 | | $languages = language_list('language', TRUE); // make sure not using cached version
|
| 85 | | $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
|
| 86 | |
|
| 87 | | if (array_key_exists($language_code, $languages)) {
|
| 88 | | $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'))));
|
| 89 | | }
|
| 90 | | }
|
| 91 | | else {
|
| 92 | | // Ensure that it is enabled.
|
| 93 | | $this->assertTrue(true, 'Language ['. $language_code .'] already installed.');
|
| 94 | | $this->drupalPost(NULL, array('enabled['. $language_code .']' => TRUE), t('Save configuration'));
|
| 95 | |
|
| 96 | | $this->assertRaw(t('Configuration saved.'), 'Language successfully enabled.');
|
| 97 | | }
|
| 98 | | }
|
| 99 | |
|
| 100 | | /**
|
| 101 | | * Create a story in the specified language.
|
| 102 | | *
|
| 103 | | * @param string $title Title of story in specified language.
|
| 104 | | * @param string $body Body of story in specified language.
|
| 105 | | * @param string $language Langauge code.
|
| 106 | | */
|
| 107 | | function createStory($title, $body, $language) {
|
| 108 | | $this->drupalVariableSet('node_options_page', array('status', 'promote'));
|
| 109 | |
|
| 110 | | $edit = array();
|
| 111 | | $edit['title'] = $title;
|
| 112 | | $edit['body'] = $body;
|
| 113 | | $edit['language'] = $language;
|
| 114 | | $this->drupalPost('node/add/story', $edit, t('Save'));
|
| 115 | |
|
| 116 | | $this->assertRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Story created.');
|
| 117 | |
|
| 118 | | // Check to make sure the node was created.
|
| 119 | | $node = node_load(array('title' => $edit['title']));
|
| 120 | | $this->assertTrue($node, 'Node found in database.');
|
| 121 | |
|
| 122 | | return $node;
|
| 123 | | }
|
| 124 | |
|
| 125 | | /**
|
| 126 | | * Create a translation for the specified story in the specified language.
|
| 127 | | *
|
| 128 | | * @param integer $nid Node id of story to create translation for.
|
| 129 | | * @param string $title Title of story in specified language.
|
| 130 | | * @param string $body Body of story in specified language.
|
| 131 | | * @param string $language Langauge code.
|
| 132 | | */
|
| 133 | | function createTranslation($nid, $title, $body, $language) {
|
| 134 | | $this->drupalGet('node/add/story', array('query' => array('translation' => $nid, 'language' => $language)));
|
| 135 | |
|
| 136 | | $edit = array();
|
| 137 | | $edit['title'] = $title;
|
| 138 | | $edit['body'] = $body;
|
| 139 | |
|
| 140 | | $this->drupalPost(NULL, $edit, t('Save'));
|
| 141 | |
|
| 142 | | $this->assertRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Translation created.');
|
| 143 | |
|
| 144 | | // Check to make sure that translation was successfull.
|
| 145 | | $node = node_load(array('title' => $edit['title']));
|
| 146 | | $this->assertTrue($node, 'Node found in database.');
|
| 147 | |
|
| 148 | | return $node;
|
| 149 | | }
|
| 150 | | }
|