public function WorkflowUiTest::testAccess in Drupal 10
Same name and namespace in other branches
- 8 core/modules/workflows/tests/src/Functional/WorkflowUiTest.php \Drupal\Tests\workflows\Functional\WorkflowUiTest::testAccess()
- 9 core/modules/workflows/tests/src/Functional/WorkflowUiTest.php \Drupal\Tests\workflows\Functional\WorkflowUiTest::testAccess()
Tests route access/permissions.
File
- core/
modules/ workflows/ tests/ src/ Functional/ WorkflowUiTest.php, line 40
Class
- WorkflowUiTest
- Tests workflow creation UI.
Namespace
Drupal\Tests\workflows\FunctionalCode
public function testAccess() {
// Create a minimal workflow for testing.
$workflow = Workflow::create([
'id' => 'test',
'type' => 'workflow_type_test',
'label' => 'Test',
]);
$workflow
->getTypePlugin()
->addState('draft', 'Draft')
->addState('published', 'Published')
->addTransition('publish', 'Publish', [
'draft',
'published',
], 'published');
$workflow
->save();
$paths = [
'admin/config/workflow/workflows',
'admin/config/workflow/workflows/add',
'admin/config/workflow/workflows/manage/test',
'admin/config/workflow/workflows/manage/test/delete',
'admin/config/workflow/workflows/manage/test/add_state',
'admin/config/workflow/workflows/manage/test/state/published',
'admin/config/workflow/workflows/manage/test/state/published/delete',
'admin/config/workflow/workflows/manage/test/add_transition',
'admin/config/workflow/workflows/manage/test/transition/publish',
'admin/config/workflow/workflows/manage/test/transition/publish/delete',
];
foreach ($paths as $path) {
$this
->drupalGet($path);
// No access.
$this
->assertSession()
->statusCodeEquals(403);
}
$this
->drupalLogin($this
->createUser([
'administer workflows',
]));
foreach ($paths as $path) {
$this
->drupalGet($path);
// User has access.
$this
->assertSession()
->statusCodeEquals(200);
}
// Ensure that default states can not be deleted.
\Drupal::state()
->set('workflow_type_test.required_states', [
'published',
]);
$this
->drupalGet('admin/config/workflow/workflows/manage/test/state/published/delete');
$this
->assertSession()
->statusCodeEquals(403);
\Drupal::state()
->set('workflow_type_test.required_states', []);
// Delete one of the states and ensure the other test cannot be deleted.
$this
->drupalGet('admin/config/workflow/workflows/manage/test/state/published/delete');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/config/workflow/workflows/manage/test/state/draft/delete');
$this
->assertSession()
->statusCodeEquals(403);
}