You are here

public function SchedulerSetupTrait::schedulerSetUp in Scheduler 2.x

Same name and namespace in other branches
  1. 8 tests/src/Traits/SchedulerSetupTrait.php \Drupal\Tests\scheduler\Traits\SchedulerSetupTrait::schedulerSetUp()

Set common properties, define content types and create users.

2 calls to SchedulerSetupTrait::schedulerSetUp()
SchedulerBrowserTestBase::setUp in tests/src/Functional/SchedulerBrowserTestBase.php
SchedulerJavascriptTestBase::setUp in tests/src/FunctionalJavascript/SchedulerJavascriptTestBase.php

File

tests/src/Traits/SchedulerSetupTrait.php, line 117

Class

SchedulerSetupTrait
Generic setup for all Scheduler tests.

Namespace

Drupal\Tests\scheduler\Traits

Code

public function schedulerSetUp() {

  // Create a test content type using the type and name constants defined
  // above. The tests should use $this->type and $this->typeName and not use
  // $this->nodetype->get('type') or $this->nodetype->get('name'), nor have
  // the hard-coded strings 'testpage' or 'Test Page'.

  /** @var NodeTypeInterface $nodetype */
  $this->nodetype = $this
    ->drupalCreateContentType([
    'type' => $this->type,
    'name' => $this->typeName,
  ]);

  // Add scheduler functionality to the content type.
  $this->nodetype
    ->setThirdPartySetting('scheduler', 'publish_enable', TRUE)
    ->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
    ->save();

  // The majority of tests use the standard Scheduler-enabled content type but
  // we also need a content type which is not enabled for Scheduler.
  $this->nonSchedulerNodeType = $this
    ->drupalCreateContentType([
    'type' => $this->nonSchedulerType,
    'name' => $this->nonSchedulerTypeName,
  ]);

  // Define nodeStorage for use in many tests.

  /** @var EntityStorageInterface $nodeStorage */
  $this->nodeStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');

  // Create an administrator user having the main admin permissions, full
  // rights on the test content type and all of the Scheduler permissions.
  // 'access site reports' is required for admin/reports/dblog.
  // 'administer site configuration' is required for admin/reports/status.
  // 'administer content types' is required for admin/structure/types/manage.
  $this->adminUser = $this
    ->drupalCreateUser([
    'access content',
    'access content overview',
    'access site reports',
    'administer nodes',
    'administer content types',
    'administer site configuration',
    'create ' . $this->type . ' content',
    'edit any ' . $this->type . ' content',
    'delete any ' . $this->type . ' content',
    'create ' . $this->nonSchedulerType . ' content',
    'edit any ' . $this->nonSchedulerType . ' content',
    'delete any ' . $this->nonSchedulerType . ' content',
    'view own unpublished content',
    'administer scheduler',
    'schedule publishing of nodes',
    'view scheduled content',
  ]);
  $this->adminUser
    ->set('name', 'Admolly the Admin user')
    ->save();

  // Create an ordinary Scheduler user, with permission to create and schedule
  // content but not with administrator permissions.
  $this->schedulerUser = $this
    ->drupalCreateUser([
    'create ' . $this->type . ' content',
    'edit own ' . $this->type . ' content',
    'delete own ' . $this->type . ' content',
    'view own unpublished content',
    'schedule publishing of nodes',
  ]);
  $this->schedulerUser
    ->set('name', 'Shelly the Scheduler user')
    ->save();

  // Store the database connection for re-use in the actual tests.
  $this->database = $this->container
    ->get('database');

  // Determine the request time and save for re-use in the actual tests.
  $this->requestTime = $this->container
    ->get('datetime.time')
    ->getRequestTime();

  // Store the core dateFormatter service for re-use in the actual tests.
  $this->dateFormatter = $this->container
    ->get('date.formatter');
}