You are here

protected function NodeTranslationUITest::doTestAuthoringInfo in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeTranslationUITest.php \Drupal\node\Tests\NodeTranslationUITest::doTestAuthoringInfo()

Tests the translation authoring information.

Overrides ContentTranslationUITestBase::doTestAuthoringInfo

File

core/modules/node/src/Tests/NodeTranslationUITest.php, line 185
Contains \Drupal\node\Tests\NodeTranslationUITest.

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\node\Tests

Code

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

  // Post different base field information for each translation.
  foreach ($this->langcodes as $langcode) {
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = array(
      'uid' => $user
        ->id(),
      'created' => REQUEST_TIME - mt_rand(0, 1000),
      'sticky' => (bool) mt_rand(0, 1),
      'promote' => (bool) mt_rand(0, 1),
    );
    $edit = array(
      'uid[0][target_id]' => $user
        ->getUsername(),
      'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
      'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
      'sticky[value]' => $values[$langcode]['sticky'],
      'promote[value]' => $values[$langcode]['promote'],
    );
    $options = array(
      'language' => $languages[$langcode],
    );
    $url = $entity
      ->urlInfo('edit-form', $options);
    $this
      ->drupalPostForm($url, $edit, $this
      ->getFormSubmitAction($entity, $langcode), $options);
  }
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  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.');
  }
}