You are here

public function EntityAPIi18nItegrationTestCase::testDefaultController in Entity API 7

Tests the provided default controller.

File

./entity.test, line 652
Entity CRUD API tests.

Class

EntityAPIi18nItegrationTestCase
Test the i18n integration.

Code

public function testDefaultController() {

  // Create test entities for the user1 and unrelated to a user.
  $entity = entity_create('entity_test_type', array(
    'name' => 'test',
    'uid' => $GLOBALS['user']->uid,
    'label' => 'label-en',
  ));
  $entity
    ->save();

  // Add a translation.
  i18n_string_textgroup('entity_test')
    ->update_translation("entity_test_type:{$entity->name}:label", 'de', 'label-de');
  $default = entity_i18n_string("entity_test:entity_test_type:{$entity->name}:label", 'label-en');
  $translation = entity_i18n_string("entity_test:entity_test_type:{$entity->name}:label", 'label-en', 'de');
  $this
    ->assertEqual($translation, 'label-de', 'Label has been translated.');
  $this
    ->assertEqual($default, 'label-en', 'Default label retrieved.');

  // Test the helper method.
  $translation = $entity
    ->getTranslation('label', 'de');
  $default = $entity
    ->getTranslation('label');
  $this
    ->assertEqual($translation, 'label-de', 'Label has been translated via the helper method.');
  $this
    ->assertEqual($default, 'label-en', 'Default label retrieved via the helper method.');

  // Test updating and make sure the translation stays.
  $entity->name = 'test2';
  $entity
    ->save();
  $translation = $entity
    ->getTranslation('label', 'de');
  $this
    ->assertEqual($translation, 'label-de', 'Translation survives a name change.');

  // Test using the wrapper to retrieve a translation.
  $wrapper = entity_metadata_wrapper('entity_test_type', $entity);
  $translation = $wrapper
    ->language('de')->label
    ->value();
  $this
    ->assertEqual($translation, 'label-de', 'Translation retrieved via the wrapper.');

  // Test deleting.
  $entity
    ->delete();
  $translation = entity_i18n_string("entity_test:entity_test_type:{$entity->name}:label", 'label-en', 'de');
  $this
    ->assertEqual($translation, 'label-en', 'Translation has been deleted.');
}