You are here

protected function SchedulerViewsAccessTest::createScheduledItems in Scheduler 2.x

Create users and scheduled content for the entity type being tested.

2 calls to SchedulerViewsAccessTest::createScheduledItems()
SchedulerViewsAccessTest::testViewScheduledContentOverview in tests/src/Functional/SchedulerViewsAccessTest.php
Tests the scheduled content overview.
SchedulerViewsAccessTest::testViewScheduledContentUser in tests/src/Functional/SchedulerViewsAccessTest.php
Tests the scheduled content tab on the user page.

File

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

Class

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

Namespace

Drupal\Tests\scheduler\Functional

Code

protected function createScheduledItems($entityTypeId, $bundle) {

  // For backwards-compatibility the node permission names have to end with
  // 'nodes' and 'content'. For all other entity types we use $entityTypeId.
  if ($entityTypeId == 'node') {
    $edit_key = 'nodes';
    $view_key = 'content';
  }
  else {
    $edit_key = $view_key = $entityTypeId;
  }
  $base_permissions = [
    "view own unpublished {$view_key}",
  ];
  $this->webUser = $this
    ->drupalCreateUser(array_merge($base_permissions, [
    "access {$view_key} overview",
  ]));
  $this->webUser
    ->set('name', 'Webisa the Web User')
    ->save();
  $this->schedulerEditor = $this
    ->drupalCreateUser(array_merge($base_permissions, [
    "schedule publishing of {$edit_key}",
  ]));
  $this->schedulerEditor
    ->set('name', 'Eddie the Scheduler Editor')
    ->save();
  $this->schedulerViewer = $this
    ->drupalCreateUser(array_merge($base_permissions, [
    "view scheduled {$view_key}",
  ]));
  $this->schedulerViewer
    ->set('name', 'Vicenza the Scheduler Viewer')
    ->save();
  $this
    ->addPermissionsToUser($this->adminUser, [
    'access user profiles',
  ]);

  // Create content scheduled for publishing and for unpublishing. The first
  // two are authored by schedulerEditor, the second two by schedulerViewer.
  $this
    ->createEntity($entityTypeId, $bundle, [
    'title' => "{$entityTypeId} created by Scheduler Editor for publishing",
    'uid' => $this->schedulerEditor
      ->id(),
    'status' => FALSE,
    'publish_on' => strtotime('+1 week'),
  ]);
  $this
    ->createEntity($entityTypeId, $bundle, [
    'title' => "{$entityTypeId} created by Scheduler Editor for unpublishing",
    'uid' => $this->schedulerEditor
      ->id(),
    'status' => TRUE,
    'unpublish_on' => strtotime('+1 week'),
  ]);
  $this
    ->createEntity($entityTypeId, $bundle, [
    'title' => "{$entityTypeId} created by Scheduler Viewer for publishing",
    'uid' => $this->schedulerViewer
      ->id(),
    'status' => FALSE,
    'publish_on' => strtotime('+1 week'),
  ]);
  $this
    ->createEntity($entityTypeId, $bundle, [
    'title' => "{$entityTypeId} created by Scheduler Viewer for unpublishing",
    'uid' => $this->schedulerViewer
      ->id(),
    'status' => TRUE,
    'unpublish_on' => strtotime('+1 week'),
  ]);
}