1 locale.test LocaleMultilingualFieldsFunctionalTest::testMultilingualNodeForm()

Test if field languages are correctly set through the node form.

File

core/modules/locale/tests/locale.test, line 2551
Tests for locale.module.

Class

LocaleMultilingualFieldsFunctionalTest
Functional test for multilingual fields.

Code

function testMultilingualNodeForm() {
  // Create "Page" content.
  $langcode = LANGUAGE_NONE;
  $title_key = "title";
  $title_value = $this->randomName(8);
  $body_key = "body[$langcode][0][value]";
  $body_value = $this->randomName(16);

  // Create node to edit.
  $edit = array();
  $edit[$title_key] = $title_value;
  $edit[$body_key] = $body_value;
  $edit['langcode'] = 'en';
  $this->backdropPost('node/add/page', $edit, t('Save'));

  // Check that the node exists in the database.
  $node = $this->backdropGetNodeByTitle($edit[$title_key]);
  $this->assertTrue($node, 'Node found in database.');

  $assert = isset($node->body['en']) && !isset($node->body[LANGUAGE_NONE]) && $node->body['en'][0]['value'] == $body_value;
  $this->assertTrue($assert, 'Field language correctly set.');

  // Change node language.
  $this->backdropGet("node/$node->nid/edit");
  $edit = array(
    $title_key => $this->randomName(8),
    'langcode' => 'it',
  );
  $this->backdropPost(NULL, $edit, t('Save'));
  $node = $this->backdropGetNodeByTitle($edit[$title_key], TRUE);
  $this->assertTrue($node, 'Node found in database.');

  $assert = isset($node->body['it']) && !isset($node->body['en']) && $node->body['it'][0]['value'] == $body_value;
  $this->assertTrue($assert, 'Field language correctly changed.');

  // Enable content language URL detection.
  language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0));

  // Test multilingual field language fallback logic.
  $this->backdropGet("it/node/$node->nid");
  $this->assertRaw($body_value, 'Body correctly displayed using Italian as requested language');

  $this->backdropGet("node/$node->nid");
  $this->assertRaw($body_value, 'Body correctly displayed using English as requested language');
}