class MediaTest in Drupal 10
Same name in this branch
- 10 core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest
- 10 core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\MediaTest
- 10 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest
- 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest
- 9 core/modules/media/tests/src/Kernel/MediaTest.php \Drupal\Tests\media\Kernel\MediaTest
Tests Media.
@group media
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\media\Kernel\MediaKernelTestBase uses MediaTypeCreationTrait
- class \Drupal\Tests\media\Kernel\MediaTest
- class \Drupal\Tests\media\Kernel\MediaKernelTestBase uses MediaTypeCreationTrait
Expanded class hierarchy of MediaTest
File
- core/
modules/ media/ tests/ src/ Kernel/ MediaTest.php, line 12
Namespace
Drupal\Tests\media\KernelView 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']);
}
}