protected function EntityTranslationUITest::assertAuthoringInfo

Tests the translation authoring information.

1 call to EntityTranslationUITest::assertAuthoringInfo()
EntityTranslationUITest::testTranslationUI in drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php
Tests the basic translation UI.
1 method overrides EntityTranslationUITest::assertAuthoringInfo()

File

drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php, line 160
Definition of Drupal\entity\Tests\EntityTranslationUITest.

Class

EntityTranslationUITest
Tests the Entity Translation UI.

Namespace

Drupal\translation_entity\Tests

Code

protected function assertAuthoringInfo() {
  $entity = entity_load($this->entityType, $this->entityId, TRUE);
  $path = $this->controller
    ->getEditPath($entity);
  $values = array();

  // Post different authoring information for each translation.
  foreach ($this->langcodes as $index => $langcode) {
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = array(
      'uid' => $user->uid,
      'created' => REQUEST_TIME - mt_rand(0, 1000),
    );
    $edit = array(
      'translation_entity[name]' => $user->name,
      'translation_entity[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
    );
    $prefix = $index > 0 ? $langcode . '/' : '';
    $this
      ->drupalPost($prefix . $path, $edit, $this
      ->getFormSubmitAction($entity));
  }
  $entity = entity_load($this->entityType, $this->entityId, TRUE);
  foreach ($this->langcodes as $langcode) {
    $this
      ->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly stored.');
    $this
      ->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly stored.');
  }

  // Try to post non valid values and check that they are rejected.
  $langcode = 'en';
  $edit = array(
    // User names have by default length 8.
    'translation_entity[name]' => $this
      ->randomName(12),
    'translation_entity[created]' => '19/11/1978',
  );
  $this
    ->drupalPost($path, $edit, $this
    ->getFormSubmitAction($entity));
  $this
    ->assertTrue($this
    ->xpath('//div[@id="messages"]//div[contains(@class, "error")]//ul'), 'Invalid values generate a list of form errors.');
  $this
    ->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly kept.');
  $this
    ->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly kept.');
}