You are here

protected function CommentTranslationUITest::doTestAuthoringInfo in Drupal 8

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

Tests the translation authoring information.

Overrides ContentTranslationUITestBase::doTestAuthoringInfo

File

core/modules/comment/tests/src/Functional/CommentTranslationUITest.php, line 162

Class

CommentTranslationUITest
Tests the Comment Translation UI.

Namespace

Drupal\Tests\comment\Functional

Code

protected function doTestAuthoringInfo() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);
  $languages = $this->container
    ->get('language_manager')
    ->getLanguages();
  $values = [];

  // Post different authoring information for each translation.
  foreach ($this->langcodes as $langcode) {
    $url = $entity
      ->toUrl('edit-form', [
      'language' => $languages[$langcode],
    ]);
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = [
      'uid' => $user
        ->id(),
      'created' => REQUEST_TIME - mt_rand(0, 1000),
    ];

    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = $this->container
      ->get('date.formatter');
    $edit = [
      'uid' => $user
        ->getAccountName() . ' (' . $user
        ->id() . ')',
      'date[date]' => $date_formatter
        ->format($values[$langcode]['created'], 'custom', 'Y-m-d'),
      'date[time]' => $date_formatter
        ->format($values[$langcode]['created'], 'custom', 'H:i:s'),
    ];
    $this
      ->drupalPostForm($url, $edit, $this
      ->getFormSubmitAction($entity, $langcode));
  }
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);
  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.');
  }
}