View source
<?php
class TranslationOverviewPriorityTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Translation Priority'),
'description' => t('Submit priorities to the translation tab and ensure that they are saved.'),
'group' => t('Translation Overview'),
);
}
function setUp() {
parent::setUp('locale', 'translation', 'translation overview');
$this->admin_user = $this
->drupalCreateUser(array(
'administer languages',
'administer content types',
'access administration pages',
));
$this->translator = $this
->drupalCreateUser(array(
'create page content',
'edit own page content',
'translate content',
));
$this
->drupalLogin($this->admin_user);
$this
->addLanguage('en');
$this
->addLanguage('es');
$this
->addLanguage('ja');
$this
->addLanguage('ko');
$this
->drupalGet('admin/content/node-type/page');
$this
->drupalPost('admin/content/node-type/page', array(
'language_content_type' => '2',
), t('Save content type'));
$this
->assertRaw(t('The content type %type has been updated.', array(
'%type' => 'Page',
)), t('Page content type has been updated.'));
$this
->drupalLogout();
$this
->drupalLogin($this->translator);
$node_title = 'Test Translation ' . $this
->randomName();
$this->en_node = $this
->createPage($node_title, 'Node body.', 'en');
}
function testTranslationOverviewDatabaseRecord() {
$node_trans_title = 'Test Traduccion ' . $this
->randomName();
$node_trans = $this
->createTranslation($this->en_node->nid, $node_trans_title, 'Nodo cuerpo.', 'es');
}
function testTranslationOverviewRelatedTab() {
$this
->drupalGet('node/' . $this->en_node->nid . '/translate');
$this
->assertRaw(t('Translation Priorites'), t('Tranlation Priorites injecting into the form.'));
}
function addLanguage($language_code) {
$this
->drupalGet('admin/settings/language');
if (strpos($this
->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
$edit = array();
$edit['langcode'] = $language_code;
$this
->drupalPost('admin/settings/language/add', $edit, t('Add language'));
$languages = language_list('language', TRUE);
$this
->assertTrue(array_key_exists($language_code, $languages), t('Language [' . $language_code . '] was installed successfully.'));
if (array_key_exists($language_code, $languages)) {
}
}
else {
$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.'));
}
}
function createPage($title, $body, $language) {
$edit = array();
$edit['title'] = $title;
$edit['body'] = $body;
$edit['language'] = $language;
$this
->drupalPost('node/add/page', $edit, t('Save'));
$this
->assertRaw(t('Page %title has been created.', array(
'%title' => $edit['title'],
)), t('Page created.'));
$node = node_load(array(
'title' => $edit['title'],
));
$this
->assertTrue($node, t('Node found in database.'));
return $node;
}
function createTranslation($nid, $title, $body, $language) {
$this
->drupalGet('node/add/page', array(
'query' => array(
'translation' => $nid,
'language' => $language,
),
));
$edit = array();
$edit['title'] = $title;
$edit['body'] = $body;
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw(t('Page %title has been created.', array(
'%title' => $edit['title'],
)), t('Translation created.'));
$node = node_load(array(
'title' => $edit['title'],
));
$this
->assertTrue($node, t('Node found in database.'));
return $node;
}
}