ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
KeyRulesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use PHPUnit\Framework\Attributes\DataProvider;
25use PHPUnit\Framework\TestCase;
26
27class KeyRulesTest extends TestCase
28{
30
31 protected function setUp(): void
32 {
33 $this->rules = new KeyRules();
34 }
35
36 #[DataProvider('validKeys')]
37 public function testValidKeysPass(string $key): void
38 {
39 $this->rules->check($key);
40
41 $this->addToAssertionCount(1);
42 }
43
47 public static function validKeys(): array
48 {
49 return [
50 'plain' => ['sort_column'],
51 'dotted' => ['view.sort.column'],
52 'php namespace' => ['ILIAS\\UI\\Implementation\\Component\\Table\\Data_my_table'],
53 'braces' => ['{tpl}'],
54 'slash' => ['a/b'],
55 'at sign' => ['user@example'],
56 'unicode' => ['Ümläut'],
57 'maximum length' => [str_repeat('a', KeyRules::MAX_LENGTH)],
58 ];
59 }
60
61 #[DataProvider('invalidKeys')]
62 public function testInvalidKeysAreRejected(string $key): void
63 {
64 $this->expectException(\InvalidArgumentException::class);
65
66 $this->rules->check($key);
67 }
68
72 public static function invalidKeys(): array
73 {
74 return [
75 'empty' => [''],
76 'colon' => ['a:b'],
77 'null byte' => ["a\0b"],
78 'newline' => ["a\nb"],
79 'delete' => ["a\x7Fb"],
80 'too long' => [str_repeat('a', KeyRules::MAX_LENGTH + 1)],
81 ];
82 }
83
85 {
86 $this->rules->check(str_repeat('ü', KeyRules::MAX_LENGTH));
87
88 $this->addToAssertionCount(1);
89 }
90}
The rules every storage key has to follow.
Definition: KeyRules.php:37