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