ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
StorageNamespaceTest.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 StorageNamespaceTest extends TestCase
28{
32 #[DataProvider('validNamespaces')]
33 public function testValidNamespacesAreAccepted(array $segments, string $value): void
34 {
35 $namespace = new StorageNamespace($segments);
36
37 $this->assertSame($value, $namespace->value());
38 $this->assertSame($value, (string) $namespace);
39 }
40
44 public static function validNamespaces(): array
45 {
46 return [
47 'single segment' => [['ui'], 'ui'],
48 'two segments' => [['ui', 'storage'], 'ui.storage'],
49 'many segments' => [['my_component', 'view_state', 'table'], 'my_component.view_state.table'],
50 'uppercase' => [['Ui', 'Storage'], 'Ui.Storage'],
51 'leading digit' => [['1ui'], '1ui'],
52 'hyphen' => [['ui-storage'], 'ui-storage'],
53 'backslash' => [['ILIAS\\UI'], 'ILIAS\\UI'],
55 'maximum length in characters' => [[str_repeat('ä', StorageNamespace::MAX_LENGTH)], str_repeat('ä', StorageNamespace::MAX_LENGTH)],
56 ];
57 }
58
62 #[DataProvider('invalidNamespaces')]
63 public function testInvalidNamespacesAreRejected(array $segments): void
64 {
65 $this->expectException(\InvalidArgumentException::class);
66
67 new StorageNamespace($segments);
68 }
69
73 public static function invalidNamespaces(): array
74 {
75 return [
76 'empty list' => [[]],
77 'empty segment' => [['ui', '']],
78 'dot in segment' => [['ui.storage']],
79 'colon in segment' => [['ui:storage']],
80 'control character' => [["ui\nstorage"]],
81 'non-string segment' => [['ui', 1]],
82 'too long' => [[str_repeat('a', StorageNamespace::MAX_LENGTH + 1)]],
83 'too long in characters' => [[str_repeat('ä', StorageNamespace::MAX_LENGTH + 1)]],
84 ];
85 }
86}
Isolates the keys of one consumer from every other consumer of a storage.