ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
JsonTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use JsonException;
27 
28 require_once __DIR__ . '/ProvideUTF8CodepointRange.php';
29 
30 class JsonTest extends TestCase
31 {
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 }
testTransform(string $exptected, string $in, string $method)
Definition: JsonTest.php:40
This class expects a valid UTF-8 string.
Definition: Json.php:34