You are here

public function SchedulerScheduledContentListAccessTest::testViewScheduledContentUser in Scheduler 8

Tests the scheduled content tab on the user page.

File

tests/src/Functional/SchedulerScheduledContentListAccessTest.php, line 69

Class

SchedulerScheduledContentListAccessTest
Tests access to the scheduled content overview page and user tab.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testViewScheduledContentUser() {
  $assert = $this
    ->assertSession();

  // Access a scheduled content user tab as an anonymous visitor.
  $this
    ->drupalGet("user/{$this->schedulerUser->id()}/scheduled");

  // An anonymous visitor cannot access a user's scheduled content tab.
  $assert
    ->statusCodeEquals(403);

  // Try to access a users own scheduled content tab when they do not have
  // any scheduler permissions. This should give "403 Access Denied".
  $this
    ->drupalLogin($this->editorUser);
  $this
    ->drupalGet("user/{$this->editorUser->id()}/scheduled");
  $assert
    ->statusCodeEquals(403);

  // Access a users own scheduled content tab when they have only
  // 'schedule publishing of nodes' permission. This will give "200 OK".
  $this
    ->drupalLogin($this->schedulerUser);
  $this
    ->drupalGet("user/{$this->schedulerUser->id()}/scheduled");
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('Node created by Scheduler User for publishing');
  $assert
    ->pageTextContains('Node created by Scheduler User for unpublishing');
  $assert
    ->pageTextNotContains('Node created by Scheduler Manager for unpublishing');

  // Access another users scheduled content tab as "Scheduler User". This
  // should not be possible and will give "403 Access Denied".
  $this
    ->drupalGet("user/{$this->schedulerManager->id()}/scheduled");
  $assert
    ->statusCodeEquals(403);

  // Access the users own scheduled content tab as "Scheduler Manager" with
  // only 'view scheduled content' permission.
  $this
    ->drupalLogin($this->schedulerManager);
  $this
    ->drupalGet("user/{$this->schedulerManager->id()}/scheduled");
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('Node created by Scheduler Manager for publishing');
  $assert
    ->pageTextContains('Node created by Scheduler Manager for unpublishing');
  $assert
    ->pageTextNotContains('Node created by Scheduler User for unpublishing');

  // Access another users scheduled content tab as "Scheduler Manager".
  // The published and unpublished content should be listed.
  $this
    ->drupalGet("user/{$this->schedulerUser->id()}/scheduled");
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('Node created by Scheduler User for publishing');
  $assert
    ->pageTextContains('Node created by Scheduler User for unpublishing');
}