You are here

public function SchedulerFunctionalTest::testPermissions in Scheduler 7

Tests that users without permission do not see the scheduler date fields.

File

tests/scheduler.test, line 863
Scheduler module test case file.

Class

SchedulerFunctionalTest
Tests the scheduler interface.

Code

public function testPermissions() {

  // 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(array(
    'access content',
    'create page content',
    'edit own page content',
    'view own unpublished content',
    'administer nodes',
  ));
  $this
    ->drupalLogin($this->webUser);

  // Set the defaults for a new node. Nothing in array means all OFF for
  // 'status', 'promote' and 'sticky'.
  variable_set('node_options_page', array());

  // Check that neither of the fields are displayed when creating a node.
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertNoFieldByName('publish_on', '', 'The Publish-on field is not shown for users who do not have permission to schedule content');
  $this
    ->assertNoFieldByName('unpublish_on', '', 'The Unpublish-on field is not shown for users who do not have permission to schedule content');

  // Initially run tests when publishing and unpublishing are not required.
  variable_set('scheduler_publish_required_page', FALSE);
  variable_set('scheduler_unpublish_required_page', FALSE);

  // Check that a new node can be saved and published.
  $title = $this
    ->randomString(15);
  $this
    ->drupalPost('node/add/page', array(
    'title' => $title,
    'status' => TRUE,
  ), t('Save'));

  // check_plain() is required because the title may have % & or ' in it.
  // Could use randomName() to get round this instead but it is good to use
  // the full variety of characters available in randomString.
  $this
    ->assertText(sprintf('%s %s has been created.', 'Basic page', check_plain($title)), 'A node can be created and published when the user does not have scheduler permissions, and scheduling is not required.');
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertTrue($node->status, 'The new node is published.');

  // Check that a new node can be saved as unpublished.
  $title = $this
    ->randomString(15);
  $this
    ->drupalPost('node/add/page', array(
    'title' => $title,
    'status' => FALSE,
  ), t('Save'));
  $this
    ->assertText(sprintf('%s %s has been created.', 'Basic page', check_plain($title)), 'A node can be created and saved as unpublished when the user does not have scheduler permissions, and scheduling is not required.');
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertFalse($node->status, 'The new node is unpublished.');

  // Set publishing and unpublishing to required, to make it a stronger test.
  variable_set('scheduler_publish_required_page', TRUE);
  variable_set('scheduler_unpublish_required_page', TRUE);

  // @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 permission"
}