ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ParsesLanguageKeyListTest.php
Go to the documentation of this file.
1<?php
2
14declare(strict_types=1);
15
17
20use PHPUnit\Framework\Attributes\DataProvider;
21use PHPUnit\Framework\TestCase;
22
27class ParsesLanguageKeyListTest extends TestCase
28{
32 private function parse(mixed $value): array
33 {
34 $host = new class () {
36
40 public function parse(mixed $value): array
41 {
42 return $this->toLanguageKeyList($value);
43 }
44 };
45
46 return $host->parse($value);
47 }
48
50 {
51 $this->assertSame(['de'], $this->parse('de'));
52 }
53
58 #[DataProvider('whitespaceWrappedDeProvider')]
60 {
61 $this->assertSame(['de'], $this->parse($value));
62 }
63
67 public static function whitespaceWrappedDeProvider(): array
68 {
69 return [
70 'plain spaces' => [' de '],
71 'trailing newline' => ["de\n"],
72 'trailing CRLF' => ["de\r\n"],
73 ];
74 }
75
79 #[DataProvider('invalidLanguageKeysProvider')]
80 public function testRejectsAMalformedLanguageKey(string $value): void
81 {
82 $this->expectException(InvalidInputException::class);
83
84 $this->parse($value);
85 }
86
90 public static function invalidLanguageKeysProvider(): array
91 {
92 return [
93 'uppercase' => ['DE'],
94 'one letter' => ['d'],
95 'three letters' => ['deu'],
96 'contains a digit' => ['de1'],
97 'contains a hyphen' => ['de-at'],
98 ];
99 }
100
102 {
103 $this->assertSame(['de', 'fr'], $this->parse([' de, fr ', 'de']));
104 }
105
107 {
108 $this->expectException(InvalidInputException::class);
109
110 $this->parse(' , ');
111 }
112
114 {
115 $this->expectException(InvalidInputException::class);
116
117 $this->parse(42);
118 }
119
120 public function testRejectsANestedArrayValue(): void
121 {
122 $this->expectException(InvalidInputException::class);
123
124 $this->parse(['de', ['fr']]);
125 }
126}
ParsesLanguageKeyList is a trait, exercised through a test double exposing its private toLanguageKeyL...
testTrimsSurroundingWhitespaceIncludingNewlinesBeforeValidating(string $value)
Items are trimmed before validation, including a trailing newline (comma-separated request values car...
testRejectsAMalformedLanguageKey(string $value)
LANGUAGE_KEY_FORMAT after trimming: exactly two lowercase ASCII letters.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...