public function TransitionAccessTest::testTransitionAccess in Scheduler content moderation integration 8
Test TransitionAccessConstraintValidator.
File
- tests/
src/ Functional/ TransitionAccessTest.php, line 82
Class
- TransitionAccessTest
- Test covering the TransitionAccessConstraintValidator.
Namespace
Drupal\Tests\scheduler_content_moderation_integration\FunctionalCode
public function testTransitionAccess() {
$this
->drupalLogin($this->schedulerUser);
// Create a node and publish it using the "publish" transition.
$edit = [
'title[0][value]' => $this
->randomString(),
'moderation_state[0][state]' => 'published',
];
$this
->drupalPostForm('node/add/page', $edit, 'Save');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$publish_time = strtotime('+2 days');
// Change node moderation state to "archived" (using the "archive"
// transition), and schedule publishing.
$edit = [
'moderation_state[0][state]' => 'archived',
'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');
// It should fail because the user does not have access to the
// "archived_published" transition.
$this
->assertSession()
->pageTextContains('You do not have access to transition from Archived to Published');
// Ensure that allowed transitions can still be used (the "publish" one).
$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');
$date_formatter = \Drupal::service('date.formatter');
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s.', $node
->getTitle(), $date_formatter
->format($publish_time, 'long')));
}