You are here

public function SchedulerMediaSetupTrait::schedulerMediaSetUp in Scheduler 2.x

Set common properties, define content types and create users.

3 calls to SchedulerMediaSetupTrait::schedulerMediaSetUp()
SchedulerAdminSettingsTest::testAdminSettings in tests/src/Functional/SchedulerAdminSettingsTest.php
Test the admin settings page.
SchedulerBrowserTestBase::setUp in tests/src/Functional/SchedulerBrowserTestBase.php
SchedulerJavascriptTestBase::setUp in tests/src/FunctionalJavascript/SchedulerJavascriptTestBase.php

File

tests/src/Traits/SchedulerMediaSetupTrait.php, line 68

Class

SchedulerMediaSetupTrait
Additional setup trait for Scheduler tests that use Media.

Namespace

Drupal\Tests\scheduler\Traits

Code

public function schedulerMediaSetUp() {

  // Create a test media type for video that is enabled for scheduling.

  /** @var \Drupal\media\Entity\MediaTypeInterface $mediaType */
  $this->mediaType = $this
    ->createMediaType('video_file', [
    'id' => $this->mediaTypeName,
    'label' => $this->mediaTypeLabel,
  ]);

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

  // Create a test media type for audio which is not enabled for scheduling.

  /** @var \Drupal\media\Entity\MediaTypeInterface $nonSchedulerMediaType */
  $this->nonSchedulerMediaType = $this
    ->createMediaType('audio_file', [
    'id' => $this->nonSchedulerMediaTypeName,
    'label' => $this->nonSchedulerMediaTypeLabel,
  ]);

  // Define mediaStorage for use in many tests.

  /** @var MediaStorageInterface $mediaStorage */
  $this->mediaStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('media');

  // Add extra permisssions to the role assigned to the adminUser.
  $this
    ->addPermissionsToUser($this->adminUser, [
    'create ' . $this->mediaTypeName . ' media',
    'edit any ' . $this->mediaTypeName . ' media',
    'delete any ' . $this->mediaTypeName . ' media',
    'create ' . $this->nonSchedulerMediaTypeName . ' media',
    'edit any ' . $this->nonSchedulerMediaTypeName . ' media',
    'delete any ' . $this->nonSchedulerMediaTypeName . ' media',
    'access media overview',
    'view own unpublished media',
    'schedule publishing of media',
    'view scheduled media',
  ]);

  // Add extra permisssions to the role assigned to the schedulerUser.
  $this
    ->addPermissionsToUser($this->schedulerUser, [
    'create ' . $this->mediaTypeName . ' media',
    'edit own ' . $this->mediaTypeName . ' media',
    'delete own ' . $this->mediaTypeName . ' media',
    'view own unpublished media',
    'schedule publishing of media',
  ]);

  // By default, media items cannot be viewed directly, and the url media/mid
  // gives a 404 not found. Changing this setting makes debugging the tests
  // easier. It is also required for the meta information test.
  $configFactory = $this->container
    ->get('config.factory');
  $configFactory
    ->getEditable('media.settings')
    ->set('standalone_url', TRUE)
    ->save(TRUE);
  $this->container
    ->get('router.builder')
    ->rebuild();

  // Set the media file attachments to be optional not required, to simplify
  // editing and saving media entities.
  $configFactory
    ->getEditable('field.field.media.test_video.field_media_video_file')
    ->set('required', FALSE)
    ->save(TRUE);
  $configFactory
    ->getEditable('field.field.media.test_audio_not_enabled.field_media_audio_file')
    ->set('required', FALSE)
    ->save(TRUE);
}