3 namespace Drupal\Tests\embed\Kernel;
5 use Drupal\embed\Entity\EmbedButton;
6 use Drupal\file\Entity\File;
7 use Drupal\KernelTests\KernelTestBase;
10 * Tests embed button icon file usage.
14 class IconFileUsageTest extends KernelTestBase {
21 public static $modules = ['embed', 'embed_test'];
24 * Tests the embed_button and file usage integration.
26 public function testEmbedButtonIconUsage() {
27 $this->enableModules(['system', 'user', 'file']);
29 $this->installSchema('file', ['file_usage']);
30 $this->installConfig(['system']);
31 $this->installEntitySchema('user');
32 $this->installEntitySchema('file');
33 $this->installEntitySchema('embed_button');
35 $file1 = file_save_data(file_get_contents('core/misc/druplicon.png'));
36 $file1->setTemporary();
39 $file2 = file_save_data(file_get_contents('core/misc/druplicon.png'));
40 $file2->setTemporary();
44 'id' => 'test_button',
45 'label' => 'Testing embed button instance',
46 'type_id' => 'embed_test_default',
47 'icon_uuid' => $file1->uuid(),
50 $entity = EmbedButton::create($button);
52 $this->assertTrue(File::load($file1->id())->isPermanent());
54 // Delete the icon from the button.
55 $entity->icon_uuid = NULL;
57 $this->assertTrue(File::load($file1->id())->isTemporary());
59 $entity->icon_uuid = $file1->uuid();
61 $this->assertTrue(File::load($file1->id())->isPermanent());
63 $entity->icon_uuid = $file2->uuid();
65 $this->assertTrue(File::load($file1->id())->isTemporary());
66 $this->assertTrue(File::load($file2->id())->isPermanent());
69 $this->assertTrue(File::load($file2->id())->isTemporary());