You are here

function TMGMTNodeSourceTestCase::checkTranslatedData in Translation Management Tool 7

Compares the data from an entity with the translated data.

Parameters

$node: The translated node object.

$data: An array with the translated data.

$langcode: The code of the target language.

1 call to TMGMTNodeSourceTestCase::checkTranslatedData()
TMGMTNodeSourceTestCase::testNodeSource in sources/node/tmgmt_node.test
Tests nodes field translation.

File

sources/node/tmgmt_node.test, line 127

Class

TMGMTNodeSourceTestCase
Basic Node Source tests.

Code

function checkTranslatedData($node, $data, $langcode) {
  foreach (element_children($data) as $field_name) {
    if ($field_name == 'node_title') {
      $this
        ->assertEqual($node->title, $data['node_title']['#translation']['#text'], 'The title of the translated node matches the translated data.');
      continue;
    }
    foreach (element_children($data[$field_name]) as $delta) {
      $field_langcode = field_is_translatable('node', field_info_field($field_name)) ? $langcode : LANGUAGE_NONE;
      foreach (element_children($data[$field_name][$delta]) as $column) {
        $column_value = $data[$field_name][$delta][$column];
        if (!isset($column_value['#translate']) || $column_value['#translate']) {
          $this
            ->assertEqual($node->{$field_name}[$field_langcode][$delta][$column], $column_value['#translation']['#text'], format_string('The translatable field %field:%delta has been populated with the proper translated data.', array(
            '%field' => $field_name,
            'delta' => $delta,
          )));
        }
      }
    }
  }
}