You are here

public function SchedulerViewsAccessTest::testViewScheduledContentOverview in Scheduler 2.x

Tests the scheduled content overview.

@dataProvider dataStandardEntityTypes()

File

tests/src/Functional/SchedulerViewsAccessTest.php, line 161

Class

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

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testViewScheduledContentOverview($entityTypeId, $bundle) {
  $this
    ->createScheduledItems($entityTypeId, $bundle);
  $scheduled_urls = [
    'node' => 'admin/content/scheduled',
    'media' => 'admin/content/media/scheduled',
    'commerce_product' => 'admin/commerce/products/scheduled',
  ];
  $scheduled_url = $scheduled_urls[$entityTypeId];
  $assert = $this
    ->assertSession();

  // Try to access the scheduled content overview as an anonymous visitor.
  $this
    ->drupalGet($scheduled_url);
  $assert
    ->statusCodeEquals(403);

  // Try to access the scheduled content overview as a user who has no
  // scheduler permissions. This should not be possible.
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet($scheduled_url);
  $assert
    ->statusCodeEquals(403);

  // Try to access the scheduled content overview as a user with only
  // 'schedule publishing of {type}' permission. This should not be possible.
  $this
    ->drupalLogin($this->schedulerEditor);
  $this
    ->drupalGet($scheduled_url);
  $assert
    ->statusCodeEquals(403);

  // Access the scheduled content overview as a user who only has
  // 'view scheduled {type}' permission. This is allowed and they should see
  // the scheduled published content by all users and their own unpublished
  // content. Unpublished node and media items by other users are also listed
  // but products are not. Therefore do not check for the unpublished item
  // by Scheduler Editor.
  $this
    ->drupalLogin($this->schedulerViewer);
  $this
    ->drupalGet($scheduled_url);
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains("{$entityTypeId} created by Scheduler Editor for unpublishing");
  $assert
    ->pageTextContains("{$entityTypeId} created by Scheduler Viewer for publishing");
  $assert
    ->pageTextContains("{$entityTypeId} created by Scheduler Viewer for unpublishing");
}