You are here

class TranslationModuleTestCase in SimpleTest 6

Hierarchy

Expanded class hierarchy of TranslationModuleTestCase

File

tests/translation_module.test, line 3

View source
class TranslationModuleTestCase extends DrupalTestCase {
  var $book;
  function get_info() {
    return array(
      'name' => t('Translation functionality'),
      'desc' => t('Create a story with translation, modify the story outdating translation, and update translation.'),
      'group' => t('Translation Tests'),
    );
  }
  function setUp() {
    parent::setUp();

    // Enable modules.
    $this
      ->drupalModuleEnable('locale');
    $this
      ->drupalModuleEnable('translation');
  }
  function test_content_translation() {

    // Setup users.
    $admin_user = $this
      ->drupalCreateUserRolePerm(array(
      'administer languages',
      'administer content types',
    ));
    $translator = $this
      ->drupalCreateUserRolePerm(array(
      'create story content',
      'edit own story content',
      'translate content',
    ));
    $this
      ->drupalLoginUser($admin_user);

    // Add languages.
    $this
      ->add_language('en');
    $this
      ->add_language('es');

    // Set story content type to use multilingual support with translation.
    $this
      ->drupalPost('admin/content/node-type/story', array(
      'language_content_type' => "2",
    ), 'Save content type');
    $this
      ->assertWantedRaw(t('The content type %type has been updated.', array(
      '%type' => 'Story',
    )), 'Story content type has been updated.');
    $this
      ->drupalGet('logout');
    $this
      ->drupalLoginUser($translator);

    // Create story in English.
    $node_title = 'Test Translation ' . $this
      ->randomName();
    $node = $this
      ->create_story($node_title, 'Node body.', 'en');

    // Submit translation in Spanish.
    $node_trans_title = 'Test Traduccion ' . $this
      ->randomName();
    $node_trans = $this
      ->create_translation($node->nid, $node_trans_title, 'Nodo cuerpo.', 'es');

    // Update origninal and mark translation as outdated.
    $edit = array();
    $edit['body'] = 'Node body. Additional Text.';
    $edit['translation[retranslate]'] = TRUE;
    $this
      ->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
    $this
      ->assertWantedRaw(t('Story %title has been updated.', array(
      '%title' => $node_title,
    )), 'Original node updated.');

    // Check to make sure that interface shows translation as outdated
    $this
      ->drupalGet('node/' . $node->nid . '/translate');
    $this
      ->assertWantedRaw('<span class="marker">' . t('outdated') . '</span>', 'Translation marked as outdated.');

    // Update translation and mark as updated.
    $edit = array();
    $edit['body'] = 'Nodo cuerpo. Texto adicional.';
    $edit['translation[status]'] = FALSE;
    $this
      ->drupalPost('node/' . $node_trans->nid . '/edit', $edit, 'Save');
    $this
      ->assertWantedRaw(t('Story %title has been updated.', array(
      '%title' => $node_trans_title,
    )), 'Translated node updated.');
  }

  /**
   * Install a the specified language if it has not been already. Otherwise make sure that
   * the language is enabled.
   *
   * @param string $language_code The langauge code the check.
   */
  function add_language($language_code) {

    // Check to make sure that language has not already been installed.
    $this
      ->drupalGet('admin/settings/language');
    if (strpos($this
      ->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {

      // Doesn't have language installed so add it.
      $edit = array();
      $edit['langcode'] = $language_code;
      $this
        ->drupalPost('admin/settings/language/add', $edit, 'Add language');
      $languages = language_list('language', TRUE);

      // make sure not using cached version
      $this
        ->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
      if (array_key_exists($language_code, $languages)) {
        $this
          ->assertWantedRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array(
          '%language' => $languages[$language_code]->name,
          '@locale-help' => url('admin/help/locale'),
        )));
      }
    }
    else {

      // Ensure that it is enabled.
      $this
        ->assertTrue(true, 'Language [' . $language_code . '] already installed.');
      $this
        ->drupalPost(NULL, array(
        'enabled[' . $language_code . ']' => TRUE,
      ), 'Save configuration');
      $this
        ->assertWantedRaw(t('Configuration saved.'), 'Language successfully enabled.');
    }
  }

  /**
   * Create a story in the specified language.
   *
   * @param string $title Title of story in specified language.
   * @param string $body Body of story in specified language.
   * @param string $language Langauge code.
   */
  function create_story($title, $body, $language) {
    $this
      ->drupalVariableSet('node_options_page', array(
      'status',
      'promote',
    ));
    $edit = array();
    $edit['title'] = $title;
    $edit['body'] = $body;
    $edit['language'] = $language;
    $this
      ->drupalPost('node/add/story', $edit, 'Save');
    $this
      ->assertWantedRaw(t('Story %title has been created.', array(
      '%title' => $edit['title'],
    )), 'Story created.');

    // Check to make sure the node was created.
    $node = node_load(array(
      'title' => $edit['title'],
    ));
    $this
      ->assertTrue($node, 'Node found in database.');
    return $node;
  }

  /**
   * Create a translation for the specified story in the specified language.
   *
   * @param integer $nid Node id of story to create translation for.
   * @param string $title Title of story in specified language.
   * @param string $body Body of story in specified language.
   * @param string $language Langauge code.
   */
  function create_translation($nid, $title, $body, $language) {
    $this
      ->drupalGet('node/add/story', array(
      'query' => array(
        'translation' => $nid,
        'language' => $language,
      ),
    ));
    $edit = array();
    $edit['title'] = $title;
    $edit['body'] = $body;
    $this
      ->drupalPost(NULL, $edit, 'Save');
    $this
      ->assertWantedRaw(t('Story %title has been created.', array(
      '%title' => $edit['title'],
    )), 'Translation created.');

    // Check to make sure that translation was successfull.
    $node = node_load(array(
      'title' => $edit['title'],
    ));
    $this
      ->assertTrue($node, 'Node found in database.');
    return $node;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$_cleanupContentTypes property
DrupalTestCase::$_cleanupNodes property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::$_modules property
DrupalTestCase::$_originalModules property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::checkOriginalModules function Retrieves and saves current modules list into $_originalModules and $_modules.
DrupalTestCase::clickLink function Follows a link by name.
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateContentType function Creates a custom content type based on default settings.
DrupalTestCase::drupalCreateNode function Creates a node based on default settings.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Broker for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPost function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser By $reporting you specify if this request does assertions or not Warning: empty ("") returns will cause fails with $reporting
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a drupal variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 8
TranslationModuleTestCase::$book property
TranslationModuleTestCase::add_language function Install a the specified language if it has not been already. Otherwise make sure that the language is enabled.
TranslationModuleTestCase::create_story function Create a story in the specified language.
TranslationModuleTestCase::create_translation function Create a translation for the specified story in the specified language.
TranslationModuleTestCase::get_info function
TranslationModuleTestCase::setUp function
TranslationModuleTestCase::test_content_translation function