function ContentTranslationWorkflowsTest::testWorkflows
Same name in other branches
- 9 core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::testWorkflows()
- 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::testWorkflows()
- 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::testWorkflows()
Tests simple and editorial translation workflows.
File
-
core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationWorkflowsTest.php, line 191
Class
- ContentTranslationWorkflowsTest
- Tests the content translation workflows for the test entity.
Namespace
Drupal\Tests\content_translation\FunctionalCode
public function testWorkflows() : void {
// Test workflows for the editor.
$expected_status = [
'edit' => 200,
'delete' => 200,
'overview' => 403,
'add_translation' => 403,
'edit_translation' => 403,
'delete_translation' => 403,
'view_unpublished_translation' => 403,
'view_unpublished_translation_reference' => FALSE,
];
$this->doTestWorkflows($this->editor, $expected_status);
// Test workflows for the translator.
$expected_status = [
'edit' => 403,
'delete' => 403,
'overview' => 200,
'add_translation' => 200,
'edit_translation' => 200,
'delete_translation' => 200,
'view_unpublished_translation' => 200,
'view_unpublished_translation_reference' => TRUE,
];
$this->doTestWorkflows($this->translator, $expected_status);
// Test workflows for the admin.
$expected_status = [
'edit' => 200,
'delete' => 200,
'overview' => 200,
'add_translation' => 200,
'edit_translation' => 403,
'delete_translation' => 403,
'view_unpublished_translation' => 200,
'view_unpublished_translation_reference' => TRUE,
];
$this->doTestWorkflows($this->administrator, $expected_status);
// Check that translation permissions allow the associated operations.
$ops = [
'create' => 'Add',
'update' => 'Edit',
'delete' => 'Delete',
];
$translations_url = $this->entity
->toUrl('drupal:content-translation-overview');
foreach ($ops as $current_op => $item) {
$user = $this->drupalCreateUser([
$this->getTranslatePermission(),
"{$current_op} content translations",
'view test entity',
]);
$this->drupalLogin($user);
$this->drupalGet($translations_url);
// Make sure that the user.permissions cache context and the cache tags
// for the entity are present.
$this->assertCacheContext('user.permissions');
foreach ($this->entity
->getCacheTags() as $cache_tag) {
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', $cache_tag);
}
foreach ($ops as $op => $label) {
if ($op != $current_op) {
$this->assertSession()
->linkNotExists($label, new FormattableMarkup('No %op link found.', [
'%op' => $label,
]));
}
else {
$this->assertSession()
->linkExists($label, 0, new FormattableMarkup('%op link found.', [
'%op' => $label,
]));
}
}
}
// Test workflows for the entity owner with non-editable content.
$expected_status = [
'edit' => 403,
'delete' => 403,
'overview' => 403,
'add_translation' => 403,
'edit_translation' => 403,
'delete_translation' => 403,
'view_unpublished_translation' => 200,
'view_unpublished_translation_reference' => TRUE,
];
$this->doTestWorkflows($this->entityOwner, $expected_status);
// Test workflows for the entity owner with editable content.
$this->setupEntity($this->entityOwner);
$this->referencingEntity
->set('field_reference', $this->entity
->id());
$this->referencingEntity
->save();
$expected_status = [
'edit' => 200,
'delete' => 403,
'overview' => 200,
'add_translation' => 200,
'edit_translation' => 200,
'delete_translation' => 200,
'view_unpublished_translation' => 200,
'view_unpublished_translation_reference' => TRUE,
];
$this->doTestWorkflows($this->entityOwner, $expected_status);
$expected_status = [
'edit' => 403,
'delete' => 403,
'overview' => 403,
'add_translation' => 403,
'edit_translation' => 403,
'delete_translation' => 403,
'view_unpublished_translation' => 200,
'view_unpublished_translation_reference' => TRUE,
];
$this->doTestWorkflows($this->notEntityOwner, $expected_status);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.