function NodeTranslationUITest::doTestAuthoringInfo

Same name and namespace in other branches
  1. 8.9.x 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()
  3. 11.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::doTestAuthoringInfo()

Overrides ContentTranslationUITestBase::doTestAuthoringInfo

File

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

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->drupalGet($url, $options);
        $this->submitForm($edit, $this->getFormSubmitAction($entity, $langcode));
    }
    $storage->resetCache([
        $this->entityId,
    ]);
    $entity = $storage->load($this->entityId);
    foreach ($this->langcodes as $langcode) {
        $translation = $entity->getTranslation($langcode);
        $metadata = $this->manager
            ->getTranslationMetadata($translation);
        $this->assertEquals($values[$langcode]['uid'], $metadata->getAuthor()
            ->id(), 'Translation author correctly stored.');
        $this->assertEquals($values[$langcode]['created'], $metadata->getCreatedTime(), 'Translation date correctly stored.');
        $this->assertEquals($values[$langcode]['sticky'], $translation->isSticky(), 'Sticky of Translation correctly stored.');
        $this->assertEquals($values[$langcode]['promote'], $translation->isPromoted(), 'Promoted of Translation correctly stored.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.