You are here

protected function NodeTranslationUITest::doTestAuthoringInfo in Drupal 8

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

Tests the translation authoring information.

Overrides ContentTranslationUITestBase::doTestAuthoringInfo

File

core/modules/node/tests/src/Functional/NodeTranslationUITest.php, line 198

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\Tests\node\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 base field information for each translation.
  foreach ($this->langcodes as $langcode) {
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = [
      'uid' => $user
        ->id(),
      'created' => REQUEST_TIME - mt_rand(0, 1000),
      'sticky' => (bool) mt_rand(0, 1),
      'promote' => (bool) mt_rand(0, 1),
    ];

    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = $this->container
      ->get('date.formatter');
    $edit = [
      'uid[0][target_id]' => $user
        ->getAccountName(),
      'created[0][value][date]' => $date_formatter
        ->format($values[$langcode]['created'], 'custom', 'Y-m-d'),
      'created[0][value][time]' => $date_formatter
        ->format($values[$langcode]['created'], 'custom', 'H:i:s'),
      'sticky[value]' => $values[$langcode]['sticky'],
      'promote[value]' => $values[$langcode]['promote'],
    ];
    $options = [
      'language' => $languages[$langcode],
    ];
    $url = $entity
      ->toUrl('edit-form', $options);
    $this
      ->drupalPostForm($url, $edit, $this
      ->getFormSubmitAction($entity, $langcode), $options);
  }
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);
  foreach ($this->langcodes as $langcode) {
    $translation = $entity
      ->getTranslation($langcode);
    $metadata = $this->manager
      ->getTranslationMetadata($translation);
    $this
      ->assertEqual($metadata
      ->getAuthor()
      ->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
    $this
      ->assertEqual($metadata
      ->getCreatedTime(), $values[$langcode]['created'], 'Translation date correctly stored.');
    $this
      ->assertEqual($translation
      ->isSticky(), $values[$langcode]['sticky'], 'Sticky of Translation correctly stored.');
    $this
      ->assertEqual($translation
      ->isPromoted(), $values[$langcode]['promote'], 'Promoted of Translation correctly stored.');
  }
}