aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-11-06 21:31:41 +0100
committerJoas Schilling <coding@schilljs.com>2024-11-06 21:31:41 +0100
commitc3c8b7e2a3cbb7809891bdd13559127d984ad7f8 (patch)
tree88a93a8572f52b32fead6c648ddb09c364ab2175 /tests
parent4bf6cd8f0bcc5262ec6edc54a60b299cd128fcfe (diff)
downloadnextcloud-server-c3c8b7e2a3cbb7809891bdd13559127d984ad7f8.tar.gz
nextcloud-server-c3c8b7e2a3cbb7809891bdd13559127d984ad7f8.zip
fix(richobjectstrings): Add missing placeholder validation
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/RichObjectStrings/ValidatorTest.php47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/lib/RichObjectStrings/ValidatorTest.php b/tests/lib/RichObjectStrings/ValidatorTest.php
index e5230efe462..c5ce1f04dad 100644
--- a/tests/lib/RichObjectStrings/ValidatorTest.php
+++ b/tests/lib/RichObjectStrings/ValidatorTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,7 +14,7 @@ use OCP\RichObjectStrings\InvalidObjectExeption;
use Test\TestCase;
class ValidatorTest extends TestCase {
- public function test(): void {
+ public function testValidate(): void {
$v = new Validator(new Definitions());
$v->validate('test', []);
$v->validate('test {string1} test {foo} test {bar}.', [
@@ -57,4 +59,47 @@ class ValidatorTest extends TestCase {
],
]);
}
+
+ public static function dataValidateParameterKeys(): array {
+ return [
+ 'not a string' => ['key' => 0, 'throws' => 'Parameter key is invalid'],
+ '@ is not allowed' => ['key' => 'user@0', 'throws' => 'Parameter key is invalid'],
+ '? is not allowed' => ['key' => 'user?0', 'throws' => 'Parameter key is invalid'],
+ 'slash is not allowed' => ['key' => 'user/0', 'throws' => 'Parameter key is invalid'],
+ 'backslash is not allowed' => ['key' => 'user\\0', 'throws' => 'Parameter key is invalid'],
+ 'hash is not allowed' => ['key' => 'user#0', 'throws' => 'Parameter key is invalid'],
+ 'space is not allowed' => ['key' => 'user 0', 'throws' => 'Parameter key is invalid'],
+ 'has to start with letter, but is number' => ['key' => '0abc', 'throws' => 'Parameter key is invalid'],
+ 'has to start with letter, but is dot' => ['key' => '.abc', 'throws' => 'Parameter key is invalid'],
+ 'has to start with letter, but is slash' => ['key' => '-abc', 'throws' => 'Parameter key is invalid'],
+ 'has to start with letter, but is underscore' => ['key' => '_abc', 'throws' => 'Parameter key is invalid'],
+ ['key' => 'user-0', 'throws' => null],
+ ['key' => 'user_0', 'throws' => null],
+ ['key' => 'user.0', 'throws' => null],
+ ['key' => 'a._-0', 'throws' => null],
+ ];
+ }
+
+ /**
+ * @dataProvider dataValidateParameterKeys
+ */
+ public function testValidateParameterKeys(mixed $key, ?string $throws): void {
+
+ if ($throws !== null) {
+ $this->expectExceptionMessage($throws);
+ }
+
+ $v = new Validator(new Definitions());
+ $v->validate('{' . $key . '}', [
+ $key => [
+ 'type' => 'highlight',
+ 'id' => 'identifier',
+ 'name' => 'Display name',
+ ],
+ ]);
+
+ if ($throws === null) {
+ $this->addToAssertionCount(1);
+ }
+ }
}