ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
ToSvgTransformationTest.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
21
24use PHPUnit\Framework\Attributes\DataProvider;
25use PHPUnit\Framework\Attributes\Depends;
26use PHPUnit\Framework\MockObject\MockObject;
27use PHPUnit\Framework\TestCase;
28
29class ToSvgTransformationTest extends TestCase
30{
31 public function testConstructorWithZero(): void
32 {
33 $this->expectException(\InvalidArgumentException::class);
34 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, 0);
35 }
36
37 public function testConstructorWithNegativeNumber(): void
38 {
39 $this->expectException(\InvalidArgumentException::class);
40 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, -1);
41 }
42
43 public function testConstructorWithPositiveNumber(): void
44 {
45 $this->expectNotToPerformAssertions();
46 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, 1);
47 }
48
49 #[Depends('testConstructorWithPositiveNumber')]
50 public function testTransformWithoutUriInstance(): void
51 {
52 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, 1);
53 $this->expectException(\InvalidArgumentException::class);
54 $transformation->transform('https://ilias.ch');
55 }
56
57 #[Depends('testConstructorWithPositiveNumber')]
58 public function testTransformWithUriInstance(): void
59 {
60 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, 1);
61 $this->expectNotToPerformAssertions();
62 $transformation->transform($this->createUriMock());
63 }
64
66 public static function getErrorCorrectionLevels(): array
67 {
68 return [
69 [ErrorCorrectionLevel::LOW],
70 [ErrorCorrectionLevel::MEDIUM],
71 [ErrorCorrectionLevel::QUARTILE],
73 ];
74 }
75
76 #[Depends('testConstructorWithPositiveNumber')]
77 #[DataProvider('getErrorCorrectionLevels')]
79 {
80 $transformation = new ToSvgQrCodeTransformation($level, 1);
81 $this->expectNotToPerformAssertions();
82 $code = $transformation->transform($this->createUriMock());
83 }
84
86 public static function getSizesInPx(): array
87 {
88 return [
89 [10],
90 [100],
91 [400],
92 [1_000],
93 ];
94 }
95
96 #[Depends('testConstructorWithPositiveNumber')]
97 #[DataProvider('getSizesInPx')]
98 public function testTransformWithSizes(int $size_in_px): void
99 {
100 $transformation = new ToSvgQrCodeTransformation(ErrorCorrectionLevel::LOW, $size_in_px);
101 $this->expectNotToPerformAssertions();
102 $code = $transformation->transform($this->createUriMock());
103 }
104
105 protected function createUriMock(): \ILIAS\Data\URI & MockObject
106 {
107 $uri_mock = $this->createMock(\ILIAS\Data\URI::class);
108 $uri_mock->method('__toString')->willReturn('https://ilias.ch');
109 return $uri_mock;
110 }
111}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
ErrorCorrectionLevel
Error correction levels as defined by ISO/IEC 18004.
@ HIGH
~7% of codewords can be restored.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.