19declare(strict_types=1);
21use PHPUnit\Framework\Attributes\DataProvider;
22use PHPUnit\Framework\TestCase;
36 [
'save',
'upload',
'maintainExecute',
'saveSettings',
'saveNewEntry'],
37 $gui->getUnsafeGetCommands()
46 $this->assertSame([], $gui->getSafePostCommands());
53 'HTML-significant characters are escaped' => [
54 '<script>x</script>.lang',
55 static function (
self $test,
string $message):
void {
56 $test->assertStringNotContainsString(
'<script>',
$message);
57 $test->assertStringContainsString(
'<script>',
$message);
58 $test->assertStringContainsString(
'</script>',
$message);
61 'an ordinary file name is left unchanged' => [
63 static function (
self $test,
string $message):
void {
64 $test->assertStringContainsString(
'ilias_de.lang',
$message);
71 #[DataProvider('importedMessageProvider')]
74 \Closure $assertOnMessage
77 $lng->method(
'txt')->willReturnCallback(
78 static fn(
string $key):
string => $key ===
'language_file_imported' ?
'Imported %s.' : $key
83 $this->
inject($gui,
'refinery',
new \
ILIAS\Refinery\Factory(
84 $this->createStub(\
ILIAS\Data\Factory::class),
85 $this->createStub(\
ILIAS\Language\Language::class)
88 $method =
new ReflectionMethod(ilObjLanguageExtGUI::class,
'importedMessage');
89 $message = $method->invoke($gui, $file_name);
91 $this->assertStringStartsWith(
'Imported ',
$message);
99 $this->
inject($gui,
'lng', $this->createStub(ilLanguage::class));
101 return (
new ReflectionMethod(ilObjLanguageExtGUI::class,
'remarkOf'))->invoke($gui,
$comments, $name);
108 $this->callRemarkOf([
'pilot#:#greeting' =>
'Bitte prüfen'],
'pilot#:#greeting')
117 $this->callRemarkOf([
'pilot#:#item' =>
'Bitte prüfen'],
'pilot#:#item [1]')
127 [
'pilot#:#item' =>
'Identifier-Bemerkung',
'pilot#:#item [1]' =>
'Form-spezifisch'],
135 $this->assertSame(
'', $this->callRemarkOf([],
'pilot#:#unknown'));
136 $this->assertSame(
'', $this->callRemarkOf([
'pilot#:#other' =>
'X'],
'pilot#:#greeting'));
142 $this->assertSame(
'', $this->callRemarkOf([
'pilot#:#item' =>
'Bemerkung'],
'pilot#:#greeting'));
149 'HTML' => [
'<b>x</b>',
'%3Cb%3Ex%3C%2Fb%3E',
'<b>x</b>'],
150 'quote, ampersand, space and hash' => [
'a"b&c d#e',
'a%22b%26c%20d%23e',
'a"b&c d#e'],
151 'a numeric topic arrives as int' => [123,
'123',
'123'],
156 #[DataProvider('missingTopicProvider')]
160 $ctrl = $this->createStub(ilCtrl::class);
161 $ctrl->method(
'setParameter')->willReturnCallback(
162 static function (
object $gui,
string $name, mixed $value) use (&
$parameters):
void {
166 $ctrl->method(
'getLinkTarget')->willReturn(
'ilias.php?a=1&b="2"');
167 $GLOBALS[
'DIC'] = new \ILIAS\DI\Container();
171 $this->
inject($gui,
'refinery',
new \
ILIAS\Refinery\Factory(
172 $this->createStub(\
ILIAS\Data\Factory::class),
173 $this->createStub(\
ILIAS\Language\Language::class)
176 $html = (
new ReflectionMethod(ilObjLanguageExtGUI::class,
'buildMissingEntries'))->invoke($gui, [$topic]);
178 $this->assertSame([[
'eid', $eid], [
'eid',
'']],
$parameters);
179 $this->assertStringContainsString(
'<li>' .
$text .
' <a href="ilias.php?a=1&b="2"">', $html);
trait RestoresProcessState
Whatever a test does to the process (locale, LANGUAGE/LC_*, LOCPATH, the static state of the runtime ...
testRemarkOfFallsBackToTheIdentifiersCommentForAPluralFormKeyWithoutItsOwn()
A plural form ("identifier [form]") without a comment of its own falls back to the comment of its ide...
testGetUnsafeGetCommandsListsEveryDataChangingCommand()
A data-changing command missing here would be triggerable via GET without the CSRF token.
callRemarkOf(array $comments, string $name)
testGetSafePostCommandsIsEmpty()
No POST command is exempt from the CSRF token.
static missingTopicProvider()
testRemarkOfIsEmptyWithoutAnyMatchingComment()
testRemarkOfReturnsTheCommentOfTheGivenKeyItselfWhenPresent()
testRemarkOfIsEmptyForAnOrdinaryIdentifierWithoutAComment()
An ordinary identifier without a comment must not fall back to anything.
static importedMessageProvider()
testImportedMessageEscapesHtmlSignificantCharactersAndKeepsTheLngText(string $file_name, \Closure $assertOnMessage)
Calls the real private importedMessage() via reflection: an uploaded file name must come out HTML-esc...
testRemarkOfPrefersThePluralFormsOwnCommentOverTheIdentifiersWhenBothArePresent()
A plural form's own comment wins over the identifier's.
testBuildMissingEntriesEscapesTheTopicForTextParameterAndLink(string|int $topic, string $eid, string $text)
The list text is HTML-escaped, the "eid" parameter URL-encoded and the link target safe inside the hr...
trait ilObjLanguageExtGUITestFixture
createLanguageMockReturningTopicAsIs(array $installed_languages=[])
newGuiWithoutConstructor(string $class)
@template T of object
inject(object $gui, string $property_name, mixed $value)
For a mock the property is looked up on its declaring class: a plain ReflectionProperty on the mock c...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.