class MediaMappingsConstraintValidatorTest
Same name and namespace in other branches
- 11.x core/modules/media/tests/src/Kernel/MediaMappingsConstraintValidatorTest.php \Drupal\Tests\media\Kernel\MediaMappingsConstraintValidatorTest
@coversDefaultClass \Drupal\media\Plugin\Validation\Constraint\MediaMappingsConstraintValidator
@group media
Hierarchy
- class \Drupal\Tests\media\Kernel\MediaMappingsConstraintValidatorTest
Expanded class hierarchy of MediaMappingsConstraintValidatorTest
File
-
core/
modules/ media/ tests/ src/ Kernel/ MediaMappingsConstraintValidatorTest.php, line 17
Namespace
Drupal\Tests\media\KernelView source
class MediaMappingsConstraintValidatorTest extends KernelTestBase {
use MediaTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'file',
'image',
'media',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('file');
$this->installEntitySchema('user');
}
/**
* @covers ::validate
*/
public function testMediaMappingSource() : void {
$media_type = $this->createMediaType('image', [
'id' => 'test',
]);
$source_field_name = $media_type->getSource()
->getSourceFieldDefinition($media_type)
->getName();
$field_map = $media_type->getFieldMap();
$field_map[File::METADATA_ATTRIBUTE_MIME] = $source_field_name;
$media_type->setFieldMap($field_map);
$media_type->save();
$typed_data = $this->container
->get('typed_data_manager');
$definition = $typed_data->createDataDefinition('entity:media_type');
$violations = $typed_data->create($definition, $media_type)
->validate();
assert($violations instanceof ConstraintViolationListInterface);
$this->assertCount(1, $violations);
$this->assertEquals('It is not possible to map the source field ' . $source_field_name . ' of a media type.', $violations[0]->getMessage());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. |
ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. |
MediaMappingsConstraintValidatorTest::$modules | protected static | property | Modules to install. |
MediaMappingsConstraintValidatorTest::setUp | protected | function | |
MediaMappingsConstraintValidatorTest::testMediaMappingSource | public | function | @covers ::validate[[api-linebreak]] |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.