You are here

protected function ContentTranslationUITestBase::doTestAuthoringInfo in Zircon Profile 8.0

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

Tests the translation authoring information.

1 call to ContentTranslationUITestBase::doTestAuthoringInfo()
ContentTranslationUITestBase::testTranslationUI in core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
Tests the basic translation UI.
2 methods override ContentTranslationUITestBase::doTestAuthoringInfo()
CommentTranslationUITest::doTestAuthoringInfo in core/modules/comment/src/Tests/CommentTranslationUITest.php
Tests the translation authoring information.
NodeTranslationUITest::doTestAuthoringInfo in core/modules/node/src/Tests/NodeTranslationUITest.php
Tests the translation authoring information.

File

core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php, line 291
Contains \Drupal\content_translation\Tests\ContentTranslationUITestBase.

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\content_translation\Tests

Code

protected function doTestAuthoringInfo() {
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  $values = array();

  // Post different authoring information for each translation.
  foreach ($this->langcodes as $index => $langcode) {
    $user = $this
      ->drupalCreateUser();
    $values[$langcode] = array(
      'uid' => $user
        ->id(),
      'created' => REQUEST_TIME - mt_rand(0, 1000),
    );
    $edit = array(
      'content_translation[uid]' => $user
        ->getUsername(),
      'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
    );
    $url = $entity
      ->urlInfo('edit-form', array(
      'language' => ConfigurableLanguage::load($langcode),
    ));
    $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.');
  }

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