/**
* Tests default media name functionality.
*/
public function testDefaultName() { // Make sure that the default name is set if not provided by the user.
/** @var \Drupal\media\MediaInterface $media */
$media = Media::
create(['bundle' =>
$this->testMediaType->
id()]);
$media_source =
$media->
getSource();
$this->
assertSame('default_name',
$media_source->
getPluginDefinition()['default_name_metadata_attribute'
], 'Default metadata attribute is not used for the default name.'
);
$this->
assertSame('media:' .
$media->
bundle() . ':' .
$media->
uuid(),
$media_source->
getMetadata($media, 'default_name'
), 'Value of the default name metadata attribute does not look correct.'
);
$this->
assertSame('media:' .
$media->
bundle() . ':' .
$media->
uuid(),
$media->
getName(), 'Default name was not used correctly by getName().'
);
$this->
assertSame($media->
getName(),
$media->
label(), 'Default name and label are not the same.'
);
$media->
save();
$this->
assertSame('media:' .
$media->
bundle() . ':' .
$media->
uuid(),
$media->
getName(), 'Default name was not saved correctly.'
);
$this->
assertSame($media->
getName(),
$media->
label(), 'The label changed during save.'
);
// Make sure that the user-supplied name is used.
/** @var \Drupal\media\MediaInterface $media */
$name = 'User-supplied name';
$media = Media::
create([ 'bundle' =>
$this->testMediaType->
id(),