protected function ContentTranslationUITestBase::doTestAuthoringInfo in Drupal 10
Same name and namespace in other branches
- 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestAuthoringInfo()
- 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestAuthoringInfo()
Tests the translation authoring information.
File
- core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationUITestBase.php, line 320
Class
- ContentTranslationUITestBase
- Tests the Content Translation UI.
Namespace
Drupal\Tests\content_translation\FunctionalCode
protected function doTestAuthoringInfo() {
$storage = $this->container
->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage
->resetCache([
$this->entityId,
]);
$entity = $storage
->load($this->entityId);
$values = [];
// Post different authoring information for each translation.
foreach ($this->langcodes as $index => $langcode) {
$user = $this
->drupalCreateUser();
$values[$langcode] = [
'uid' => $user
->id(),
'created' => REQUEST_TIME - mt_rand(0, 1000),
];
$edit = [
'content_translation[uid]' => $user
->getAccountName(),
'content_translation[created]' => $this->container
->get('date.formatter')
->format($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
];
$url = $entity
->toUrl('edit-form', [
'language' => ConfigurableLanguage::load($langcode),
]);
$this
->drupalGet($url);
$this
->submitForm($edit, $this
->getFormSubmitAction($entity, $langcode));
}
$storage = $this->container
->get('entity_type.manager')
->getStorage($this->entityTypeId);
$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.');
}
// Try to post non valid values and check that they are rejected.
$langcode = 'en';
$edit = [
// User names have by default length 8.
'content_translation[uid]' => $this
->randomMachineName(12),
'content_translation[created]' => '19/11/1978',
];
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm($edit, $this
->getFormSubmitAction($entity, $langcode));
$this
->assertSession()
->statusMessageExists('error');
$metadata = $this->manager
->getTranslationMetadata($entity
->getTranslation($langcode));
$this
->assertEquals($values[$langcode]['uid'], $metadata
->getAuthor()
->id(), 'Translation author correctly kept.');
$this
->assertEquals($values[$langcode]['created'], $metadata
->getCreatedTime(), 'Translation date correctly kept.');
}