public function TransitionAccessTest::testRestrictedTransitionAccess in Scheduler content moderation integration 8
Test access to scheduled content for users without right to transition.
File
- tests/
src/ Functional/ TransitionAccessTest.php, line 123
Class
- TransitionAccessTest
- Test covering the TransitionAccessConstraintValidator.
Namespace
Drupal\Tests\scheduler_content_moderation_integration\FunctionalCode
public function testRestrictedTransitionAccess() {
// Create a draft as restricted user.
$this
->drupalLogin($this->restrictedUser);
$edit = [
'title[0][value]' => $this
->randomString(),
'moderation_state[0][state]' => 'draft',
];
$this
->drupalPostForm('node/add/page', $edit, 'Save');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$publish_time = strtotime('+2 days');
$date_formatter = \Drupal::service('date.formatter');
// Schedule publishing.
$this
->drupalLogin($this->schedulerUser);
$edit = [
'moderation_state[0][state]' => 'draft',
'publish_on[0][value][date]' => date('Y-m-d', $publish_time),
'publish_on[0][value][time]' => date('H:i:s', $publish_time),
'publish_state[0]' => 'published',
];
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s.', $node
->getTitle(), $date_formatter
->format($publish_time, 'long')));
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertResponse(200, 'Scheduler user should be able to edit the node."');
// Restricted user does not have permission to scheduled transition,
// editing access should be denied.
$this
->drupalLogin($this->restrictedUser);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertResponse(403, 'Restricted user should not be able to edit the node."');
// Remove scheduling info.
$this
->drupalLogin($this->schedulerUser);
$edit = [
'moderation_state[0][state]' => 'draft',
'publish_on[0][value][date]' => NULL,
'publish_on[0][value][time]' => NULL,
'publish_state[0]' => '_none',
];
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, 'Save');
// Check if node is editable when there is no scheduling
// (using 'create_new_draft' transition).
$this
->drupalLogin($this->restrictedUser);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertResponse(200, 'Restricted user should be able to edit the node."');
}