Version 1
[yaffs-website] / web / modules / contrib / embed / tests / src / Kernel / IconFileUsageTest.php
1 <?php
2
3 namespace Drupal\Tests\embed\Kernel;
4
5 use Drupal\embed\Entity\EmbedButton;
6 use Drupal\file\Entity\File;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * Tests embed button icon file usage.
11  *
12  * @group embed
13  */
14 class IconFileUsageTest extends KernelTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['embed', 'embed_test'];
22
23   /**
24    * Tests the embed_button and file usage integration.
25    */
26   public function testEmbedButtonIconUsage() {
27     $this->enableModules(['system', 'user', 'file']);
28
29     $this->installSchema('file', ['file_usage']);
30     $this->installConfig(['system']);
31     $this->installEntitySchema('user');
32     $this->installEntitySchema('file');
33     $this->installEntitySchema('embed_button');
34
35     $file1 = file_save_data(file_get_contents('core/misc/druplicon.png'));
36     $file1->setTemporary();
37     $file1->save();
38
39     $file2 = file_save_data(file_get_contents('core/misc/druplicon.png'));
40     $file2->setTemporary();
41     $file2->save();
42
43     $button = [
44       'id' => 'test_button',
45       'label' => 'Testing embed button instance',
46       'type_id' => 'embed_test_default',
47       'icon_uuid' => $file1->uuid(),
48     ];
49
50     $entity = EmbedButton::create($button);
51     $entity->save();
52     $this->assertTrue(File::load($file1->id())->isPermanent());
53
54     // Delete the icon from the button.
55     $entity->icon_uuid = NULL;
56     $entity->save();
57     $this->assertTrue(File::load($file1->id())->isTemporary());
58
59     $entity->icon_uuid = $file1->uuid();
60     $entity->save();
61     $this->assertTrue(File::load($file1->id())->isPermanent());
62
63     $entity->icon_uuid = $file2->uuid();
64     $entity->save();
65     $this->assertTrue(File::load($file1->id())->isTemporary());
66     $this->assertTrue(File::load($file2->id())->isPermanent());
67
68     $entity->delete();
69     $this->assertTrue(File::load($file2->id())->isTemporary());
70   }
71
72 }