ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
JsonTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25use JsonException;
26use PHPUnit\Framework\Attributes\DataProvider;
27
28require_once __DIR__ . '/ProvideUTF8CodepointRange.php';
29
30class JsonTest extends TestCase
31{
32 use ProvideUTF8CodepointRange;
33
34 public function testConstruct(): void
35 {
36 $this->assertInstanceOf(Json::class, new Json());
37 }
38
39 #[DataProvider('provideTransformData')]
40 public function testTransform(string $exptected, string $in, string $method): void
41 {
42 $this->$method($exptected, (new Json())->transform($in));
43 }
44
45 public function testInvalidEncoding(): void
46 {
47 $this->expectException(JsonException::class);
48 (new Json())->transform(chr(128));
49 }
50
51 public static function provideTransformData(): array
52 {
53 return [
54 'Empty string' => ['""', '', 'assertSame'],
55 'UTF-8' => ['"\uc548\ub155\ud558\uc11c\u3163\uc694"', '안녕하서ㅣ요', 'assertSame'],
56 'HTML special chars' => ['"\\u003C\\u003E\\u0027\\u0022\\u0026"', '<>\'"&', 'assertSame'],
57 'Characters beyond ASCII value 255' => ['"\\u0100"', 'Ā', 'assertSame'],
58 'Characters beyond Unicode BMP' => ['"\\ud800\\udc00"', "\xF0\x90\x80\x80", 'assertSame'],
59 'Basic control characters and null' => ['"\\r\\n\\t\\u0000"', "\r\n\t\0", 'assertSame'],
60 'Single space' => ['" "', ' ', 'assertSame'],
61 'Slash' => ['"\\/"', '/', 'assertSame'],
62 ];
63 }
64}
This class expects a valid UTF-8 string.
Definition: Json.php:35
testTransform(string $exptected, string $in, string $method)
Definition: JsonTest.php:40