public function SchedulerPermissionsTest::testUserPermissionsAdd in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerPermissionsTest.php \Drupal\Tests\scheduler\Functional\SchedulerPermissionsTest::testUserPermissionsAdd()
Tests that users without permission do not see the scheduler date fields.
File
- tests/
src/ Functional/ SchedulerPermissionsTest.php, line 15
Class
- SchedulerPermissionsTest
- Tests the permissions of the Scheduler module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testUserPermissionsAdd() {
// 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);
// Check that neither of the fields are displayed when creating a node.
$this
->drupalGet('node/add/' . $this->type);
$this
->assertSession()
->fieldNotExists('publish_on[0][value][date]');
$this
->assertSession()
->fieldNotExists('unpublish_on[0][value][date]');
// Initially run tests when publishing and unpublishing are not required.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', FALSE)
->setThirdPartySetting('scheduler', 'unpublish_required', FALSE)
->save();
// Check that a new node can be saved and published.
$title = $this
->randomString(15);
$edit = [
'title[0][value]' => $title,
'status[value]' => TRUE,
];
$this
->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s %s has been created.', $this->typeName, $title));
$this
->assertTrue($this
->drupalGetNodeByTitle($title)
->isPublished(), 'The new node is published');
// Check that a new node can be saved as unpublished.
$title = $this
->randomString(15);
$edit = [
'title[0][value]' => $title,
'status[value]' => FALSE,
];
$this
->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s %s has been created.', $this->typeName, $title));
$this
->assertFalse($this
->drupalGetNodeByTitle($title)
->isPublished(), 'The new node is unpublished');
// Set publishing and unpublishing to required, to make it a stronger test.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', TRUE)
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
// @todo Add tests when scheduled publishing and unpublishing are required.
// Cannot be done until we make a decision on what 'required' means.
// @see https://www.drupal.org/node/2707411
// "Conflict between 'required publishing' and not having scheduler
// permission"
}