4cacf3d467052c8b9339eb061de9f61e98d4b2a5
[yaffs-website] / web / core / modules / media / tests / src / Functional / MediaCacheTagsTest.php
1 <?php
2
3 namespace Drupal\Tests\media\Functional;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\media\Entity\Media;
7 use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
8 use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
9
10 /**
11  * Tests the media items cache tags.
12  *
13  * @group media
14  */
15 class MediaCacheTagsTest extends EntityWithUriCacheTagsTestBase {
16
17   use MediaTypeCreationTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = [
23     'media',
24     'media_test_source',
25   ];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function createEntity() {
31     // Create a media type.
32     $mediaType = $this->createMediaType('test');
33
34     // Create a media item.
35     $media = Media::create([
36       'bundle' => $mediaType->id(),
37       'name' => 'Unnamed',
38     ]);
39     $media->save();
40
41     return $media;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   protected function getAdditionalCacheContextsForEntity(EntityInterface $media) {
48     return ['timezone'];
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   protected function getAdditionalCacheTagsForEntity(EntityInterface $media) {
55     // Each media item must have an author and a thumbnail.
56     return [
57       'user:' . $media->getOwnerId(),
58       'config:image.style.thumbnail',
59       'file:' . $media->get('thumbnail')->entity->id(),
60     ];
61   }
62
63 }