public function SchedulerPermissionsTest::testUserPermissionsEdit in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerPermissionsTest.php \Drupal\Tests\scheduler\Functional\SchedulerPermissionsTest::testUserPermissionsEdit()
Tests that users without permission can edit existing scheduled content.
File
- tests/
src/ Functional/ SchedulerPermissionsTest.php, line 67
Class
- SchedulerPermissionsTest
- Tests the permissions of the Scheduler module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testUserPermissionsEdit() {
// Create a user who can add the content type but who does not have the
// permission to use the scheduler functionality.
$this->webUser = $this
->drupalCreateUser([
'access content',
'administer nodes',
'create ' . $this->type . ' content',
'edit own ' . $this->type . ' content',
'delete own ' . $this->type . ' content',
'view own unpublished content',
]);
$this
->drupalLogin($this->webUser);
$publish_time = strtotime('+ 6 hours', $this->requestTime);
$unpublish_time = strtotime('+ 10 hours', $this->requestTime);
// Create nodes with publish_on and unpublish_on dates.
$unpublished_node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => FALSE,
'publish_on' => $publish_time,
]);
$published_node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => TRUE,
'unpublish_on' => $unpublish_time,
]);
// Verify that the publish_on date is stored as expected before editing.
$this
->assertEquals($publish_time, $unpublished_node->publish_on->value, 'The publish_on value is stored correctly before edit.');
// Edit the unpublished node and save.
$title = 'For Publishing ' . $this
->randomString(10);
$this
->drupalPostForm('node/' . $unpublished_node
->id() . '/edit', [
'title[0][value]' => $title,
], 'Save');
// Check the updated title, to verify that edit and save was sucessful.
$unpublished_node = $this->nodeStorage
->load($unpublished_node
->id());
$this
->assertEquals($title, $unpublished_node->title->value, 'The unpublished node title has been updated correctly after edit.');
// Test that the publish_on date is still stored and is unchanged.
$this
->assertEquals($publish_time, $unpublished_node->publish_on->value, 'The node publish_on value is still stored correctly after edit.');
// Do the same for unpublishing.
// Verify that the unpublish_on date is stored as expected before editing.
$this
->assertEquals($unpublish_time, $published_node->unpublish_on->value, 'The unpublish_on value is stored correctly before edit.');
// Edit the published node and save.
$title = 'For Unpublishing ' . $this
->randomString(10);
$this
->drupalPostForm('node/' . $published_node
->id() . '/edit', [
'title[0][value]' => $title,
], 'Save');
// Check the updated title, to verify that edit and save was sucessful.
$published_node = $this->nodeStorage
->load($published_node
->id());
$this
->assertEquals($title, $published_node->title->value, 'The published node title has been updated correctly after edit.');
// Test that the unpublish_on date is still stored and is unchanged.
$this
->assertEquals($unpublish_time, $published_node->unpublish_on->value, 'The node unpublish_on value is still stored correctly after edit.');
}