|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of ILIAS, a powerful learning management system |
| 5 | + * published by ILIAS open source e-Learning e.V. |
| 6 | + * |
| 7 | + * ILIAS is licensed with the GPL-3.0, |
| 8 | + * see https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | + * You should have received a copy of said license along with the |
| 10 | + * source code, too. |
| 11 | + * |
| 12 | + * If this is not the case or you just want to try ILIAS, you'll find |
| 13 | + * us at: |
| 14 | + * https://www.ilias.de |
| 15 | + * https://github.com/ILIAS-eLearning |
| 16 | + */ |
| 17 | + |
| 18 | +declare(strict_types=1); |
| 19 | + |
| 20 | +namespace String; |
| 21 | + |
| 22 | +use ILIAS\Refinery\String\QRCode; |
| 23 | +use ILIAS\Data\QR\ErrorCorrectionLevel; |
| 24 | +use ILIAS\Data\QR\SVGCode; |
| 25 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 26 | +use PHPUnit\Framework\Attributes\Depends; |
| 27 | +use PHPUnit\Framework\TestCase; |
| 28 | + |
| 29 | +class QRCodeTest extends TestCase |
| 30 | +{ |
| 31 | + public function testConstructorWithZero(): void |
| 32 | + { |
| 33 | + $this->expectException(\InvalidArgumentException::class); |
| 34 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 0); |
| 35 | + } |
| 36 | + |
| 37 | + public function testConstructorWithNegativeNumber(): void |
| 38 | + { |
| 39 | + $this->expectException(\InvalidArgumentException::class); |
| 40 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, -1); |
| 41 | + } |
| 42 | + |
| 43 | + public function testConstructorWithPositiveNumber(): void |
| 44 | + { |
| 45 | + $this->expectNotToPerformAssertions(); |
| 46 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 1); |
| 47 | + } |
| 48 | + |
| 49 | + #[Depends('testConstructorWithPositiveNumber')] |
| 50 | + public function testTransformWithoutString(): void |
| 51 | + { |
| 52 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 1); |
| 53 | + $this->expectException(\InvalidArgumentException::class); |
| 54 | + $transformation->transform(1); |
| 55 | + } |
| 56 | + |
| 57 | + #[Depends('testConstructorWithPositiveNumber')] |
| 58 | + public function testTransformWithEmptyString(): void |
| 59 | + { |
| 60 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 1); |
| 61 | + $this->expectException(\InvalidArgumentException::class); |
| 62 | + $transformation->transform(''); |
| 63 | + } |
| 64 | + |
| 65 | + #[Depends('testConstructorWithPositiveNumber')] |
| 66 | + public function testTransformWithNonEmptyString(): void |
| 67 | + { |
| 68 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 1); |
| 69 | + $this->expectNotToPerformAssertions(); |
| 70 | + $transformation->transform('some arbitrary data.'); |
| 71 | + } |
| 72 | + |
| 73 | + #[Depends('testConstructorWithPositiveNumber')] |
| 74 | + public function testTransformWithEmoji(): void |
| 75 | + { |
| 76 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, 1); |
| 77 | + $this->expectNotToPerformAssertions(); |
| 78 | + $transformation->transform("\xF0\x9F\x98\x82"); // some emoji |
| 79 | + } |
| 80 | + |
| 81 | + /** @return array<ErrorCorrectionLevel[]> */ |
| 82 | + public static function getErrorCorrectionLevels(): array |
| 83 | + { |
| 84 | + return [ |
| 85 | + [ErrorCorrectionLevel::LOW], |
| 86 | + [ErrorCorrectionLevel::MEDIUM], |
| 87 | + [ErrorCorrectionLevel::QUARTILE], |
| 88 | + [ErrorCorrectionLevel::HIGH], |
| 89 | + ]; |
| 90 | + } |
| 91 | + |
| 92 | + #[Depends('testConstructorWithPositiveNumber')] |
| 93 | + #[DataProvider('getErrorCorrectionLevels')] |
| 94 | + public function testTransformWithErrorCorrectionLevels(ErrorCorrectionLevel $level): void |
| 95 | + { |
| 96 | + $transformation = new QRCode($level, 1); |
| 97 | + $this->expectNotToPerformAssertions(); |
| 98 | + $code = $transformation->transform("some arbitrary data."); |
| 99 | + } |
| 100 | + |
| 101 | + /** @return array<int[]> */ |
| 102 | + public static function getSizesInPx(): array |
| 103 | + { |
| 104 | + return [ |
| 105 | + [10], |
| 106 | + [100], |
| 107 | + [400], |
| 108 | + [1_000], |
| 109 | + ]; |
| 110 | + } |
| 111 | + |
| 112 | + #[Depends('testConstructorWithPositiveNumber')] |
| 113 | + #[DataProvider('getSizesInPx')] |
| 114 | + public function testTransformWithSizes(int $size_in_px): void |
| 115 | + { |
| 116 | + $transformation = new QRCode(ErrorCorrectionLevel::LOW, $size_in_px); |
| 117 | + $this->expectNotToPerformAssertions(); |
| 118 | + $code = $transformation->transform("some arbitrary data."); |
| 119 | + } |
| 120 | +} |
0 commit comments