protected function CommentTranslationUITest::doTestAuthoringInfo in Drupal 10
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Functional/CommentTranslationUITest.php \Drupal\Tests\comment\Functional\CommentTranslationUITest::doTestAuthoringInfo()
- 9 core/modules/comment/tests/src/Functional/CommentTranslationUITest.php \Drupal\Tests\comment\Functional\CommentTranslationUITest::doTestAuthoringInfo()
File
- core/
modules/ comment/ tests/ src/ Functional/ CommentTranslationUITest.php, line 162
Class
- CommentTranslationUITest
- Tests the Comment Translation UI.
Namespace
Drupal\Tests\comment\FunctionalCode
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
->drupalGet($url);
$this
->submitForm($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
->assertEquals($values[$langcode]['uid'], $metadata
->getAuthor()
->id(), 'Translation author correctly stored.');
$this
->assertEquals($values[$langcode]['created'], $metadata
->getCreatedTime(), 'Translation date correctly stored.');
}
}