View source
<?php
if (!class_exists('EntityTranslationTestCase')) {
return;
}
class DraftyEntityTranslationTest extends EntityTranslationTestCase {
public static function getInfo() {
return array(
'name' => 'Drafty Entity Translation',
'description' => 'Test revision manipulation with entity translation',
'group' => 'Drafty',
'dependencies' => array(
'entity_translation',
),
);
}
function setUp(array $modules = array()) {
parent::setUp('locale', 'entity_translation', 'drafty_enforce', 'drafty_1992010');
$this
->login(parent::getAdminUser());
$this
->addLanguage('en');
$this
->addLanguage('es');
$this
->configureContentType();
$this
->login($this
->getTranslatorUser());
}
function createTranslation($node, $title, $body, $langcode, $source_langcode = 'en') {
$this
->drupalGet('node/' . $node->nid . '/edit/add/' . $source_langcode . '/' . $langcode);
$body_key = "body[{$langcode}][0][value]";
$this
->assertFieldByXPath("//textarea[@name='{$body_key}']", $node->body[$source_langcode][0]['value'], 'Original body value correctly populated.');
$this
->assertFieldById('edit-body-' . $langcode . '-add-more', t('Add another item'), t('Add another item button found.'));
$edit = array();
$edit[$body_key] = $body;
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/translate');
return $node;
}
function testFieldTranslation() {
$node_title = $this
->randomName();
$node_body = $this
->randomName();
$node = $this
->createPage($node_title, $node_body, 'en');
$original_version = node_load($node->nid, NULL, TRUE);
$node_translation_title = $this
->randomName();
$node_translation_body = $this
->randomName();
$node_translation = $this
->createTranslation($node, $node_translation_title, $node_translation_body, 'es');
$published_version = node_load($node->nid, NULL, TRUE);
$this
->assertTrue(!isset($original_version->body['es']), 'No Spanish translation on the original version');
$this
->assertTrue(!isset($published_version->body['es']), 'No Spanish translation on the published version');
$vid = db_select('node_revision')
->fields('node_revision', array(
'vid',
))
->condition('nid', $node->nid)
->condition('vid', $original_version->vid, '>')
->condition('vid', $published_version->vid, '<')
->execute()
->fetchField();
$draft_version = node_load($node->nid, $vid);
$this
->assertTrue($draft_version->body['es'], 'Spanish translation on the draft version');
drafty()
->publishRevision('node', $node->nid, $draft_version->vid);
$new_published_version = node_load($node->nid, NULL, TRUE);
$this
->assertTrue($draft_version->body['es'], 'Spanish translation on the newly published version');
drafty()
->publishRevision('node', $node->nid, $original_version->vid);
$re_published_original = node_load($node->nid, NULL, TRUE);
$this
->assertTrue(!isset($original_version->body['es']), 'No Spanish translation on the re-published original version');
}
}