You are here

class MediaTest in Drupal 10

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest
  2. 10 core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\MediaTest
  3. 10 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest
  4. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest
Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest
  2. 9 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest

Tests Media.

@group media

Hierarchy

Expanded class hierarchy of MediaTest

File

core/modules/media/tests/src/Kernel/MediaTest.php, line 12

Namespace

Drupal\Tests\media\Kernel
View source
class MediaTest extends MediaKernelTestBase {

  /**
   * Tests various aspects of a media item.
   */
  public function testEntity() {
    $media = Media::create([
      'bundle' => $this->testMediaType
        ->id(),
    ]);
    $this
      ->assertSame($media, $media
      ->setOwnerId($this->user
      ->id()), 'setOwnerId() method returns its own entity.');
  }

  /**
   * Tests the Media "name" base field behavior.
   */
  public function testNameBaseField() {

    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $field_definitions */
    $field_definitions = $this->container
      ->get('entity_field.manager')
      ->getBaseFieldDefinitions('media');

    // Ensure media name is configurable on manage display.
    $this
      ->assertTrue($field_definitions['name']
      ->isDisplayConfigurable('view'));

    // Ensure it is not visible by default.
    $this
      ->assertSame($field_definitions['name']
      ->getDisplayOptions('view'), [
      'region' => 'hidden',
    ]);
  }

  /**
   * Tests permissions based on a media type have the correct permissions.
   */
  public function testPermissions() {
    $permissions = $this->container
      ->get('user.permissions')
      ->getPermissions();
    $name = "create {$this->testMediaType->id()} media";
    $this
      ->assertArrayHasKey($name, $permissions);
    $this
      ->assertSame([
      'config' => [
        $this->testMediaType
          ->getConfigDependencyName(),
      ],
    ], $permissions[$name]['dependencies']);
  }

}

Members