ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LanguageFileDirectoryManagerTest.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
23
25use PHPUnit\Framework\TestCase;
26
28{
30 {
31 $component = $this->anyComponent();
32
33 $manager = new LanguageFileDirectoryManager(
36 new ComponentLanguageFileDirectory($component, 'adve'),
37 new ComponentLanguageFileDirectory($component, 'copg')
38 );
39
40 $this->assertCount(3, iterator_to_array($manager->getDirectories(), false));
41 }
42
44 {
45 $component = $this->anyComponent();
46
47 $this->expectException(\InvalidArgumentException::class);
48 $this->expectExceptionMessage('shipping the same files');
51 new ComponentLanguageFileDirectory($component, 'adve', 'lang/', 'ilias_%s'),
52 new ComponentLanguageFileDirectory($component, 'copg', 'lang/', 'ilias_%s')
53 );
54 }
55
56 public function testTheSamePrefixIsReportedAsSuch(): void
57 {
58 $component = $this->anyComponent();
59
60 $this->expectException(\InvalidArgumentException::class);
61 $this->expectExceptionMessage('with the same prefix');
64 new ComponentLanguageFileDirectory($component, 'copg'),
65 new ComponentLanguageFileDirectory($component, 'copg')
66 );
67 }
68
71 {
72 $invalid = new class () implements LanguageFileDirectory, NamesShippedLanguageFiles {
73 public function getPrefix(): string
74 {
75 return 'broken';
76 }
77
78 public function getPath(): string
79 {
80 return 'components/ILIAS/Broken/lang/';
81 }
82
83 public function getSuffix(): string
84 {
85 return '';
86 }
87
88 public function isLocal(): bool
89 {
90 return false;
91 }
92
93 public function getShippedFileNamePattern(): string
94 {
95 return 'no-placeholder';
96 }
97 };
98
100
101 $this->assertSame([$invalid], iterator_to_array($manager->getDirectories(), false));
102 }
103
104 private function anyComponent(): Component
105 {
106 return new class () implements Component {
107 public function init(
108 array|\ArrayAccess &$define,
109 array|\ArrayAccess &$implement,
110 array|\ArrayAccess &$use,
111 array|\ArrayAccess &$contribute,
112 array|\ArrayAccess &$seek,
113 array|\ArrayAccess &$provide,
114 array|\ArrayAccess &$pull,
115 array|\ArrayAccess &$internal,
116 ): void {
117 }
118 };
119 }
120}
testADirectoryWithAnInvalidPatternIsLeftToTheBuild()
The build warns about an invalid pattern, so it must not stop the manager from being built.
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
Definition: Language.php:44
A directory of language files with a path and a prefix for them.
Optional addition to LanguageFileDirectory for shipped .po files not named <prefix>_<lang>....