MediaTest.php in Drupal 9
File
core/modules/media/tests/src/Kernel/MediaTest.php
View source
<?php
namespace Drupal\Tests\media\Kernel;
use Drupal\media\Entity\Media;
class MediaTest extends MediaKernelTestBase {
public function testEntity() {
$media = Media::create([
'bundle' => $this->testMediaType
->id(),
]);
$this
->assertSame($media, $media
->setOwnerId($this->user
->id()), 'setOwnerId() method returns its own entity.');
}
public function testNameBaseField() {
$field_definitions = $this->container
->get('entity_field.manager')
->getBaseFieldDefinitions('media');
$this
->assertTrue($field_definitions['name']
->isDisplayConfigurable('view'));
$this
->assertSame($field_definitions['name']
->getDisplayOptions('view'), [
'region' => 'hidden',
]);
}
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']);
}
}