ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DuplicateIdentifierMessageTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
27use ILIAS\Refinery\Factory as Refinery;
28use PHPUnit\Framework\TestCase;
29
30class DuplicateIdentifierMessageTest extends TestCase
31{
32 private function lng(string $text): Language
33 {
34 $lng = $this->createStub(Language::class);
35 $lng->method('txt')->willReturn($text);
36
37 return $lng;
38 }
39
40 private function refinery(): Refinery
41 {
42 return new Refinery($this->createStub(DataFactory::class), $this->createStub(Language::class));
43 }
44
46 {
47 $this->assertSame(
48 'tos#:#x (common: x, mme: X)',
49 DuplicateIdentifierMessage::entry('tos#:#x', ['common: x', 'mme: X'])
50 );
51 }
52
54 {
56 $this->lng('Not unique: %s'),
57 $this->refinery(),
58 ['a#:#<b> (x: "<b>")', 'c#:#d (e: d)']
59 );
60
61 $this->assertSame('Not unique: a#:#&lt;b&gt; (x: &quot;&lt;b&gt;&quot;); c#:#d (e: d)', $message);
62 }
63
66 {
67 $this->assertSame(
68 'Not unique 100% right. a (b: a)',
69 DuplicateIdentifierMessage::of($this->lng('Not unique 100% right.'), $this->refinery(), ['a (b: a)'])
70 );
71 $this->assertSame(
72 '100% unique: a (b: a)',
73 DuplicateIdentifierMessage::of($this->lng('100% unique: %s'), $this->refinery(), ['a (b: a)'])
74 );
75 }
76
79 {
80 $long = str_repeat('k', 300);
81 $entries = [$long];
82 for ($i = 1; $i <= PlainLogText::MAX_LISTED_KEYS + 4; $i++) {
83 $entries[] = 'e' . $i;
84 }
85
86 $message = DuplicateIdentifierMessage::of($this->lng('%s'), $this->refinery(), $entries);
87
88 $this->assertStringStartsWith(str_repeat('k', 199) . '…; e1; ', $message);
89 $this->assertStringNotContainsString(str_repeat('k', 200), $message);
90 $this->assertStringContainsString('… (+5)', $message);
91 $this->assertStringNotContainsString('e' . (PlainLogText::MAX_LISTED_KEYS + 4), $message);
92 }
93
95 {
96 $entries = [str_repeat('k', 300)];
97 for ($i = 1; $i < 250; $i++) {
98 $entries[] = 'e' . $i;
99 }
100
101 $line = DuplicateIdentifierMessage::forLog($entries);
102
103 $this->assertStringContainsString(str_repeat('k', 199) . '…; e1; ', $line);
104 $this->assertStringNotContainsString(str_repeat('k', 200), $line);
105 $this->assertStringContainsString('e199', $line);
106 $this->assertStringNotContainsString('e200;', $line);
107 $this->assertStringEndsWith(' … (+50)', $line);
108 }
109
111 {
112 $line = DuplicateIdentifierMessage::forLog(["a#:#b\x1b[31m (c: b)"]);
113
114 $this->assertStringContainsString('a#:#b?[31m (c: b)', $line);
115 $this->assertStringNotContainsString('(+', $line);
116 $this->assertStringNotContainsString("\x1b", $line);
117 }
118}
Builds data types.
Definition: Factory.php:36
Texts naming entries left out or rejected because their identifier exists in another module (see Iden...
static of(Language $lng, Refinery $refinery, array $entries)
Text taken from language files or entries (keys, values, file names) for a terminal or log line: cont...
testEntriesAreShortenedAndTheListIsLimited()
The keys come from an uploaded file: one entry is cut to 200 characters, the list to the first entrie...
testATextWithoutPlaceholderGetsTheListAppendedAndAFurtherPercentSignIsKept()
A translation without the placeholder, or with another "%", still names the entries and does not fail...
global $lng
Definition: privfeed.php:26
$text
Definition: xapiexit.php:21