protected function ContentTranslationWorkflowsTest::doTestWorkflows in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest::doTestWorkflows()
Checks that workflows have the expected behaviors for the given user.
Parameters
\Drupal\user\UserInterface $user: The user to test the workflow behavior against.
array $expected_status: The an associative array with the operation name as key and the expected status as value.
1 call to ContentTranslationWorkflowsTest::doTestWorkflows()
- ContentTranslationWorkflowsTest::testWorkflows in core/
modules/ content_translation/ src/ Tests/ ContentTranslationWorkflowsTest.php - Test simple and editorial translation workflows.
File
- core/
modules/ content_translation/ src/ Tests/ ContentTranslationWorkflowsTest.php, line 153 - Contains \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest.
Class
- ContentTranslationWorkflowsTest
- Tests the content translation workflows for the test entity.
Namespace
Drupal\content_translation\TestsCode
protected function doTestWorkflows(UserInterface $user, $expected_status) {
$default_langcode = $this->langcodes[0];
$languages = $this->container
->get('language_manager')
->getLanguages();
$args = [
'@user_label' => $user
->getUsername(),
];
$options = [
'language' => $languages[$default_langcode],
'absolute' => TRUE,
];
$this
->drupalLogin($user);
// Check whether the user is allowed to access the entity form in edit mode.
$edit_url = $this->entity
->urlInfo('edit-form', $options);
$this
->drupalGet($edit_url, $options);
$this
->assertResponse($expected_status['edit'], SafeMarkup::format('The @user_label has the expected edit access.', $args));
// Check whether the user is allowed to access the entity delete form.
$delete_url = $this->entity
->urlInfo('delete-form', $options);
$this
->drupalGet($delete_url, $options);
$this
->assertResponse($expected_status['delete'], SafeMarkup::format('The @user_label has the expected delete access.', $args));
// Check whether the user is allowed to access the translation overview.
$langcode = $this->langcodes[1];
$options['language'] = $languages[$langcode];
$translations_url = $this->entity
->url('drupal:content-translation-overview', $options);
$this
->drupalGet($translations_url);
$this
->assertResponse($expected_status['overview'], SafeMarkup::format('The @user_label has the expected translation overview access.', $args));
// Check whether the user is allowed to create a translation.
$add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
$this->entityTypeId => $this->entity
->id(),
'source' => $default_langcode,
'target' => $langcode,
], $options);
if ($expected_status['add_translation'] == 200) {
$this
->clickLink('Add');
$this
->assertUrl($add_translation_url
->toString(), [], 'The translation overview points to the translation form when creating translations.');
// Check that the translation form does not contain shared elements for
// translators.
if ($expected_status['edit'] == 403) {
$this
->assertNoSharedElements();
}
}
else {
$this
->drupalGet($add_translation_url);
}
$this
->assertResponse($expected_status['add_translation'], SafeMarkup::format('The @user_label has the expected translation creation access.', $args));
// Check whether the user is allowed to edit a translation.
$langcode = $this->langcodes[2];
$options['language'] = $languages[$langcode];
$edit_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_edit", [
$this->entityTypeId => $this->entity
->id(),
'language' => $langcode,
], $options);
if ($expected_status['edit_translation'] == 200) {
$this
->drupalGet($translations_url);
$editor = $expected_status['edit'] == 200;
if ($editor) {
$this
->clickLink('Edit', 2);
// An editor should be pointed to the entity form in multilingual mode.
// We need a new expected edit path with a new language.
$expected_edit_path = $this->entity
->url('edit-form', $options);
$this
->assertUrl($expected_edit_path, [], 'The translation overview points to the edit form for editors when editing translations.');
}
else {
$this
->clickLink('Edit');
// While a translator should be pointed to the translation form.
$this
->assertUrl($edit_translation_url
->toString(), [], 'The translation overview points to the translation form for translators when editing translations.');
// Check that the translation form does not contain shared elements.
$this
->assertNoSharedElements();
}
}
else {
$this
->drupalGet($edit_translation_url);
}
$this
->assertResponse($expected_status['edit_translation'], SafeMarkup::format('The @user_label has the expected translation edit access.', $args));
// Check whether the user is allowed to delete a translation.
$langcode = $this->langcodes[2];
$options['language'] = $languages[$langcode];
$delete_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_delete", [
$this->entityTypeId => $this->entity
->id(),
'language' => $langcode,
], $options);
if ($expected_status['delete_translation'] == 200) {
$this
->drupalGet($translations_url);
$editor = $expected_status['delete'] == 200;
if ($editor) {
$this
->clickLink('Delete', 2);
// An editor should be pointed to the entity deletion form in
// multilingual mode. We need a new expected delete path with a new
// language.
$expected_delete_path = $this->entity
->url('delete-form', $options);
$this
->assertUrl($expected_delete_path, [], 'The translation overview points to the delete form for editors when deleting translations.');
}
else {
$this
->clickLink('Delete');
// While a translator should be pointed to the translation deletion
// form.
$this
->assertUrl($delete_translation_url
->toString(), [], 'The translation overview points to the translation deletion form for translators when deleting translations.');
}
}
else {
$this
->drupalGet($delete_translation_url);
}
$this
->assertResponse($expected_status['delete_translation'], SafeMarkup::format('The @user_label has the expected translation deletion access.', $args));
}