ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PluralFormKeyTest.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
31class PluralFormKeyTest extends TestCase
32{
33 public function testOfFormatsTheIdentifierAndForm(): void
34 {
35 $this->assertSame('poll_population [0]', PluralFormKey::of('poll_population', 0));
36 $this->assertSame('poll_population [1]', PluralFormKey::of('poll_population', 1));
37 }
38
39 #[DataProvider('roundTripKeys')]
40 public function testOfAndParseRoundTrip(string $identifier, int $form): void
41 {
42 $this->assertSame([$identifier, $form], PluralFormKey::parse(PluralFormKey::of($identifier, $form)));
43 }
44
48 public static function roundTripKeys(): array
49 {
50 return [
51 'simple' => ['poll_population', 0],
52 'two digit form' => ['poll_population', 10],
53 'identifier containing brackets' => ['weird [legacy]', 1],
54 'identifier containing a space' => ['poll population', 1],
55 ];
56 }
57
58 #[DataProvider('nonFormKeys')]
59 public function testParseReturnsNullForAnythingNotShapedLikeOf(string $key): void
60 {
61 $this->assertNull(PluralFormKey::parse($key));
62 }
63
67 public static function nonFormKeys(): array
68 {
69 return [
70 'plain identifier' => ['poll_population'],
71 'no space before bracket' => ['poll_population[0]'],
72 'no closing bracket' => ['poll_population [0'],
73 'non-numeric form' => ['poll_population [x]'],
74 'leading zero form' => ['poll_population [01]'],
75 'negative form' => ['poll_population [-1]'],
76 'empty identifier' => [' [0]'],
77 'empty string' => [''],
78 'trailing characters after bracket' => ['poll_population [0] extra'],
79 ];
80 }
81
83 {
84 $this->assertSame(['id', 99], PluralFormKey::parse('id [99]'));
85 }
86
87 public function testParseRejectsAThreeDigitForm(): void
88 {
89 $this->assertNull(PluralFormKey::parse('id [100]'));
90 }
91}
A form of a plural message of a migrated module in a flat identifier => value map (admin GUI rows,...
static of(string $identifier, int $form)
PluralFormKey: the "<identifier> [<form>]" shape of admin GUI rows and local changes of a plural mess...