You are here

public function EntityTranslationHierarchyTestCase::testHierarchy in Entity Translation 7

Tests the handler hierarchy.

File

tests/entity_translation.test, line 626
Tests for Entity translation module.

Class

EntityTranslationHierarchyTestCase
Tests that entity translation handler hierarchy works properly.

Code

public function testHierarchy() {
  $entity_type = 'node';
  $node = $this
    ->drupalCreateNode();
  $factory = EntityTranslationHandlerFactory::getInstance();
  $handler = $factory
    ->getHandler($entity_type, $node);
  $children = array();
  foreach (range(0, 4) as $index) {
    $children[$index] = $this
      ->drupalCreateNode();
    $handler
      ->addChild($entity_type, $children[$index]);
  }
  $langcode = 'it';
  $handler
    ->setActiveLanguage($langcode);
  foreach ($children as $child) {
    $child_handler = $factory
      ->getHandler($entity_type, $child);
    $this
      ->assertEqual($child_handler
      ->getActiveLanguage(), $langcode);
  }
  $rm_index = mt_rand(0, count($children) - 1);
  $handler
    ->removeChild($entity_type, $children[$rm_index]);
  $langcode = 'fr';
  $handler
    ->setActiveLanguage($langcode);
  foreach ($children as $index => $child) {
    $child_handler = $factory
      ->getHandler($entity_type, $child);
    $this
      ->assertEqual($child_handler
      ->getActiveLanguage() == $langcode, $index != $rm_index);
  }

  // @todo Test the other properties.
}