You are here

protected function SchedulerPermissionsTest::setUp in Scheduler 2.x

Overrides SchedulerBrowserTestBase::setUp

File

tests/src/Functional/SchedulerPermissionsTest.php, line 19

Class

SchedulerPermissionsTest
Tests some permissions of the Scheduler module.

Namespace

Drupal\Tests\scheduler\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Define a set of permissions which all users get. Then in addition, each
  // user gets the specific permission to schedule their own entity type.
  // The permission 'administer nodes' is needed when setting the node status
  // field on edit. There is no corresponding separate permission for media or
  // product entity types.
  $permissions = [
    'create ' . $this->type . ' content',
    'edit own ' . $this->type . ' content',
    'administer nodes',
    'create ' . $this->mediaTypeName . ' media',
    'edit own ' . $this->mediaTypeName . ' media',
    'view own unpublished media',
    'create ' . $this->productTypeName . ' commerce_product',
    'update own ' . $this->productTypeName . ' commerce_product',
    'view own unpublished commerce_product',
    // 'administer commerce_store' is needed to see and use any store, i.e
    // cannot add a product without this. Is it a bug?
    'administer commerce_store',
  ];

  // Create a user who can add and edit the standard scheduler-enabled node,
  // media and product entity types, but only schedule nodes.
  $this->nodeUser = $this
    ->drupalCreateUser(array_merge($permissions, [
    'schedule publishing of nodes',
  ]));
  $this->nodeUser
    ->set('name', 'Noddy the Node Editor')
    ->save();

  // Create a user who can add and edit the standard scheduler-enabled node,
  // media and product entity types, but only schedule media.
  $this->mediaUser = $this
    ->drupalCreateUser(array_merge($permissions, [
    'schedule publishing of media',
  ]));
  $this->mediaUser
    ->set('name', 'Medina the Media Editor')
    ->save();

  // Create a user who can add and edit the standard scheduler-enabled node,
  // media and product entity types, but only schedule products.
  $this->commerce_productUser = $this
    ->drupalCreateUser(array_merge($permissions, [
    'schedule publishing of commerce_product',
  ]));
  $this->commerce_productUser
    ->set('name', 'Proctor the Product Editor')
    ->save();
}