3 namespace Drupal\Tests\media_entity\Kernel;
5 use Drupal\Core\Language\Language;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
7 use Drupal\media_entity\Entity\Media;
8 use Drupal\media_entity\Entity\MediaBundle;
11 * Tests token handling.
15 class TokensTest extends EntityKernelTestBase {
22 public static $modules = [
35 protected function setUp() {
37 $this->installEntitySchema('file');
38 $this->installSchema('file', 'file_usage');
39 $this->installEntitySchema('media');
40 $this->installConfig(['language', 'datetime', 'field', 'system']);
44 * Tests some of the tokens provided by media_entity.
46 public function testMediaEntityTokens() {
47 // Create a generic media bundle.
48 $bundle_name = $this->randomMachineName();
52 'label' => $bundle_name,
54 'type_configuration' => [],
57 'new_revision' => FALSE,
60 // Create a media entity.
61 $media = Media::create([
62 'name' => $this->randomMachineName(),
63 'bundle' => $bundle_name,
65 'langcode' => Language::LANGCODE_DEFAULT,
66 'status' => Media::PUBLISHED,
70 $token_service = $this->container->get('token');
72 $replaced_value = $token_service->replace('[media:name]', ['media' => $media]);
73 $this->assertEquals($media->label(), $replaced_value, 'Token replacement for the media label was sucessful.');