ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
FromSvgTransformationTest.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
21
23use PHPUnit\Framework\Attributes\Depends;
24use PHPUnit\Framework\MockObject\MockObject;
25use PHPUnit\Framework\TestCase;
26
27class FromSvgTransformationTest extends TestCase
28{
29 public function testTransformWithoutSvgInstance(): void
30 {
31 $transformation = new FromSvgTransformation();
32 $this->expectException(\InvalidArgumentException::class);
33 $transformation->transform('<svg></svg>');
34 }
35
36 public function testTransformWithSvgInstance(): void
37 {
38 $transformation = new FromSvgTransformation();
39 $this->expectNotToPerformAssertions();
40 $transformation->transform($this->createSvgMock());
41 }
42
43 #[Depends('testTransformWithSvgInstance')]
44 public function testTransformResult(): void
45 {
46 $transformation = new FromSvgTransformation();
47 $svg_mock = $this->createSvgMock();
48 $result = $transformation->transform($svg_mock);
49 $this->assertIsString($result);
50 $this->assertStringStartsWith("data:image/svg+xml;base64,", $result); // ensure correct data uri format
51 $this->assertStringEndsWith(base64_encode($svg_mock->__toString()), $result); // ensure base64 encoded value
52 }
53
54 protected function createSvgMock(): \ILIAS\Data\SVG & MockObject
55 {
56 $svg_mock = $this->createMock(\ILIAS\Data\SVG::class);
57 $svg_mock->method('__toString')->willReturn('<svg></svg>');
58 return $svg_mock;
59 }
60}
Data transfer object that carries the raw SVG data as a string, created from trusted sources.
Definition: SVG.php:30
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.