protected function ContentTranslationUITestBase::doTestAuthoringInfo in Drupal 8
Same name in this branch
- 8 core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\ContentTranslationUITestBase::doTestAuthoringInfo()
- 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestAuthoringInfo()
Same name and namespace in other branches
- 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestAuthoringInfo()
- 10 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestAuthoringInfo()
Tests the translation authoring information.
1 call to ContentTranslationUITestBase::doTestAuthoringInfo()
- ContentTranslationUITestBase::testTranslationUI in core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationUITestBase.php - Tests the basic translation UI.
2 methods override ContentTranslationUITestBase::doTestAuthoringInfo()
- CommentTranslationUITest::doTestAuthoringInfo in core/
modules/ comment/ tests/ src/ Functional/ CommentTranslationUITest.php - Tests the translation authoring information.
- NodeTranslationUITest::doTestAuthoringInfo in core/
modules/ node/ tests/ src/ Functional/ NodeTranslationUITest.php - Tests the translation authoring information.
File
- core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationUITestBase.php, line 309
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
->drupalPostForm($url, $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
->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 = [
// User names have by default length 8.
'content_translation[uid]' => $this
->randomMachineName(12),
'content_translation[created]' => '19/11/1978',
];
$this
->drupalPostForm($entity
->toUrl('edit-form'), $edit, $this
->getFormSubmitAction($entity, $langcode));
$this
->assertNotEmpty($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.');
}