public function EntityTranslationToggleFieldsTranslatabilityTestCase::testTogglingFieldsWithDataRevisionable in Entity Translation 7
Tests toggling translatability on fields with data (revisionable).
File
- tests/
entity_translation.test, line 1138 - Tests for Entity translation module.
Class
- EntityTranslationToggleFieldsTranslatabilityTestCase
- Tests for enabling fields to use Entity Translation or disabling them.
Code
public function testTogglingFieldsWithDataRevisionable() {
// Enable revisions for Basic pages.
$this
->login($this
->getAdminUser());
$this
->configureContentTypeForRevisions();
// Create an untranslated Basic page.
$this
->login($this
->getTranslatorUser());
$node_title = $this
->randomName();
$node_body = $this
->randomName();
$node = $this
->createUntranslatedPage($node_title, $node_body);
$this
->assert(isset($node->body[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
$this
->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $node_body);
// Create a new revision for the page.
$edit_revision = array(
'title' => $this
->randomName(),
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit_revision, t('Save'));
$node = node_load($node->nid, NULL, TRUE);
$this
->assert($node->vid == $node->nid + 1, t('Correct vid attached to the node object.'));
// Enable translation for field body and check field migration on all
// revisions.
$this
->login($this
->getAdminUser());
$this
->drupalGet('admin/structure/types/manage/page/fields/body');
$this
->clickLink('Enable translation');
$this
->drupalPost(NULL, array(), t('Confirm'));
$node_current_revision = current(entity_load('node', FALSE, array(
'vid' => $node->vid,
), TRUE));
$this
->assert(isset($node_current_revision->body['en']), t('Found field data in English as expected.'));
$this
->assertEqual($node_current_revision->body['en'][0]['value'], $node_body);
$this
->assert(!isset($node_current_revision->body[LANGUAGE_NONE]), t('No field data in LANGUAGE_NONE found.'));
$node_previous_revision = current(entity_load('node', FALSE, array(
'vid' => $node->vid - 1,
), TRUE));
$this
->assert(isset($node_previous_revision->body['en']), t('Found field data in English as expected.'));
$this
->assertEqual($node_previous_revision->body['en'][0]['value'], $node_body);
$this
->assert(!isset($node_previous_revision->body[LANGUAGE_NONE]), t('No field data in LANGUAGE_NONE found.'));
// Disable translation for field_body.
$this
->drupalGet('admin/structure/types/manage/page/fields/body');
$this
->clickLink('Disable translation');
$this
->drupalPost(NULL, array(), t('Confirm'));
// Disable translation for field body and check field reverse migration on
// all revisions.
$node_current_revision = current(entity_load('node', FALSE, array(
'vid' => $node->vid,
), TRUE));
$this
->assert(isset($node_current_revision->body[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
$this
->assertEqual($node_current_revision->body[LANGUAGE_NONE][0]['value'], $node_body);
$this
->assert(!isset($node_current_revision->body['en']), t('No field data in English found.'));
$node_previous_revision = current(entity_load('node', FALSE, array(
'vid' => $node->vid - 1,
), TRUE));
$this
->assert(isset($node_previous_revision->body[LANGUAGE_NONE]), t('Found field data in LANGUAGE_NONE as expected.'));
$this
->assertEqual($node_previous_revision->body[LANGUAGE_NONE][0]['value'], $node_body);
$this
->assert(!isset($node_previous_revision->body['en']), t('No field data in English found.'));
}