You are here

protected function CommentTranslationUITest::doTestAuthoringInfo in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Tests/CommentTranslationUITest.php \Drupal\comment\Tests\CommentTranslationUITest::doTestAuthoringInfo()

Tests the translation authoring information.

Overrides ContentTranslationUITestBase::doTestAuthoringInfo

File

core/modules/comment/src/Tests/CommentTranslationUITest.php, line 153
Contains \Drupal\comment\Tests\CommentTranslationUITest.

Class

CommentTranslationUITest
Tests the Comment Translation UI.

Namespace

Drupal\comment\Tests

Code

protected function doTestAuthoringInfo() {
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  $languages = $this->container
    ->get('language_manager')
    ->getLanguages();
  $values = array();

  // Post different authoring information for each translation.
  foreach ($this->langcodes as $langcode) {
    $url = $entity
      ->urlInfo('edit-form', [
      'language' => $languages[$langcode],
    ]);
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = array(
      'uid' => $user
        ->id(),
      'created' => REQUEST_TIME - mt_rand(0, 1000),
    );
    $edit = array(
      'uid' => $user
        ->getUsername() . '(' . $user
        ->id() . ')',
      'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
      'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
    );
    $this
      ->drupalPostForm($url, $edit, $this
      ->getFormSubmitAction($entity, $langcode));
  }
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  foreach ($this->langcodes as $langcode) {
    $metadata = $this->manager
      ->getTranslationMetadata($entity
      ->getTranslation($langcode));
    $this
      ->assertEqual($metadata
      ->getAuthor()
      ->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
    $this
      ->assertEqual($metadata
      ->getCreatedTime(), $values[$langcode]['created'], 'Translation date correctly stored.');
  }
}