IconTest.php in Embed 8
File
tests/src/Kernel/IconTest.php
View source
<?php
namespace Drupal\Tests\embed\Kernel;
use Drupal\embed\EmbedButtonInterface;
use Drupal\embed\Entity\EmbedButton;
use Drupal\KernelTests\KernelTestBase;
class IconTest extends KernelTestBase {
public static $modules = [
'system',
'embed',
'embed_test',
];
protected function setUp() {
parent::setUp();
$this
->installConfig('system');
$this
->installEntitySchema('embed_button');
}
public function testIcon() {
$button = EmbedButton::create([
'id' => 'test',
'label' => 'Test',
'type_id' => 'embed_test_default',
]);
$this
->assertEmpty($button->icon);
$this
->assertIconUrl('/default.png', $button);
$uri = 'public://button.png';
$image_contents = file_get_contents('core/misc/favicon.ico');
file_put_contents($uri, $image_contents);
$button
->set('icon', EmbedButton::convertImageToEncodedData($uri));
$this
->assertSame([
'data' => base64_encode($image_contents),
'uri' => $uri,
], $button->icon);
$this
->assertIconUrl($uri, $button);
unlink($uri);
$this
->assertFalse(is_file($uri));
$this
->assertIconUrl($uri, $button);
$this
->assertTrue(is_file($uri));
$this
->assertSame(file_get_contents($uri), file_get_contents('core/misc/favicon.ico'));
$button
->set('icon', [
'uri' => 'http://www.example.com/button.png',
]);
$this
->assertIconUrl('http://www.example.com/button.png', $button);
}
protected function assertIconUrl($uri, EmbedButtonInterface $button, string $message = '') {
$this
->assertSame(file_url_transform_relative(file_create_url($uri)), $button
->getIconUrl(), $message);
}
}
Classes
Name |
Description |
IconTest |
Tests embed button icon file handling. |