You are here

function UserRelationshipsI18nTestCase::testTypeTranslation in User Relationships 7

Test translation of types.

File

./user_relationships.test, line 596
User Relationships API tests @author Alex Karshakevich http://drupal.org/user/183217

Class

UserRelationshipsI18nTestCase
User Relationship type tests.

Code

function testTypeTranslation() {
  $admin = $this
    ->drupalCreateUser(array(
    'administer languages',
    'access administration pages',
    'administer user relationships',
    'translate interface',
    'translate user-defined strings',
  ));
  $this
    ->drupalLogin($admin);
  $this
    ->addLanguage('de');
  $this
    ->drupalPost('admin/config/regional/language/configure', array(
    'language[enabled][locale-url]' => TRUE,
  ), t('Save settings'));
  $this
    ->drupalGet('admin/config/people/relationships');
  $this
    ->clickLink(t('Add relationship type'));

  // Create relationship type.
  $edit = array(
    'name' => $this
      ->randomName(),
    'machine_name' => strtolower($this
      ->randomName()),
    'plural_name' => $this
      ->randomName(),
    'reverse_name' => $this
      ->randomName(),
    'reverse_plural_name' => $this
      ->randomName(),
    'name_capitalized' => $this
      ->randomName(),
    'plural_name_capitalized' => $this
      ->randomName(),
    'reverse_name_capitalized' => $this
      ->randomName(),
    'reverse_plural_name_capitalized' => $this
      ->randomName(),
    'requires_approval' => FALSE,
    'ui_settings_show_tab' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Add and translate'));
  $this
    ->clickLink(t('translate'));

  // Get the subscriber id from the path.
  $this
    ->assertTrue(preg_match('|admin/config/people/relationships/(\\d+)/translate$|', $this
    ->getUrl(), $matches), 'Type id found');
  $rtid = $matches[1];

  // strings[user_relationships:type:1:name]
  // Translate the type.
  $translations = array(
    "strings[user_relationships:type:{$rtid}:name]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:plural_name]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:reverse_name]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:reverse_plural_name]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:name_capitalized]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:plural_name_capitalized]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:reverse_name_capitalized]" => $this
      ->randomName(),
    "strings[user_relationships:type:{$rtid}:reverse_plural_name_capitalized]" => $this
      ->randomName(),
  );
  $this
    ->drupalPost(NULL, $translations, t('Save translation'));
  $this
    ->drupalGet('de/admin/config/people/relationships');

  // The translated name should now be shown.
  $this
    ->assertNoText($edit['name']);
  $this
    ->assertText($translations["strings[user_relationships:type:{$rtid}:name]"]);
  $this
    ->drupalGet('de/relationships');
  $this
    ->assertNoText($edit['plural_name_capitalized']);
  $this
    ->assertText($translations["strings[user_relationships:type:{$rtid}:plural_name_capitalized]"]);
}