From d95846aa88d1b48cdba1c1e4a1b17e5381f97b1d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 1 Dec 2023 15:32:35 +0100 Subject: [PATCH] final set of API tests refactored --- .../ApiCoreCreateUserTest.php} | 83 ++++++++++++---------- inc/Remote/ApiCore.php | 2 +- 2 files changed, 45 insertions(+), 40 deletions(-) rename _test/tests/{inc/remoteapicore_createuser.test.php => Remote/ApiCoreCreateUserTest.php} (72%) diff --git a/_test/tests/inc/remoteapicore_createuser.test.php b/_test/tests/Remote/ApiCoreCreateUserTest.php similarity index 72% rename from _test/tests/inc/remoteapicore_createuser.test.php rename to _test/tests/Remote/ApiCoreCreateUserTest.php index cd51d0c94..cffeac06c 100644 --- a/_test/tests/inc/remoteapicore_createuser.test.php +++ b/_test/tests/Remote/ApiCoreCreateUserTest.php @@ -1,24 +1,28 @@ remote = new Api(); } - public function tearDown() : void { + public function tearDown(): void + { parent::tearDown(); global $USERINFO; @@ -46,7 +51,7 @@ class remoteapicore_createuser_test extends DokuWikiTest { $AUTH_ACL = $this->oldAuthAcl; } - public function test_createUser() + public function testCreateUser() { global $conf, $auth; $conf['remote'] = 1; @@ -77,25 +82,25 @@ class remoteapicore_createuser_test extends DokuWikiTest { $this->assertFalse($actualCallResult); } - public function test_createUserAuthPlain() + public function testCreateUserAuthPlain() { global $conf, $auth; $conf['remote'] = 1; $conf['remoteuser'] = 'testuser'; $_SERVER['REMOTE_USER'] = 'testuser'; - $auth = new auth_plugin_authplain(); + $auth = new \auth_plugin_authplain(); $params = [ - [ - 'user' => 'user1', - 'password' => 'password1', - 'name' => 'user1', - 'mail' => 'user1@localhost', - 'groups' => [ - 'user', - 'test' - ], - 'notify' => false - ] + [ + 'user' => 'user1', + 'password' => 'password1', + 'name' => 'user1', + 'mail' => 'user1@localhost', + 'groups' => [ + 'user', + 'test' + ], + 'notify' => false + ] ]; @@ -103,17 +108,17 @@ class remoteapicore_createuser_test extends DokuWikiTest { $this->assertTrue($callResult); } - public function test_createUserAuthPlainUndefinedUser() + public function testCreateUserAuthPlainUndefinedUser() { global $conf, $auth; $conf['remote'] = 1; $conf['remoteuser'] = 'testuser'; $_SERVER['REMOTE_USER'] = 'testuser'; - $auth = new auth_plugin_authplain(); + $auth = new \auth_plugin_authplain(); $params = [ - [ - 'user' => '' - ], + [ + 'user' => '' + ], ]; $this->expectException(RemoteException::class); @@ -121,13 +126,13 @@ class remoteapicore_createuser_test extends DokuWikiTest { $this->remote->call('dokuwiki.createUser', $params); } - public function test_createUserAuthPlainUndefinedName() + public function testCreateUserAuthPlainUndefinedName() { global $conf, $auth; $conf['remote'] = 1; $conf['remoteuser'] = 'testuser'; $_SERVER['REMOTE_USER'] = 'testuser'; - $auth = new auth_plugin_authplain(); + $auth = new \auth_plugin_authplain(); $params = [ [ 'user' => 'hello' @@ -139,13 +144,13 @@ class remoteapicore_createuser_test extends DokuWikiTest { $this->remote->call('dokuwiki.createUser', $params); } - public function test_createUserAuthPlainBadEmail() + public function testCreateUserAuthPlainBadEmail() { global $conf, $auth; $conf['remote'] = 1; $conf['remoteuser'] = 'testuser'; $_SERVER['REMOTE_USER'] = 'testuser'; - $auth = new auth_plugin_authplain(); + $auth = new \auth_plugin_authplain(); $params = [ [ 'user' => 'hello', @@ -159,7 +164,7 @@ class remoteapicore_createuser_test extends DokuWikiTest { $this->remote->call('dokuwiki.createUser', $params); } - public function test_createUserAuthCanNotDoAddUser() + public function testCreateUserAuthCanNotDoAddUser() { $this->expectException(AccessDeniedException::class); $this->expectExceptionMessageMatches('/can\'t do addUser/'); @@ -170,17 +175,17 @@ class remoteapicore_createuser_test extends DokuWikiTest { $auth = new AuthCreatePlugin(false); $params = [ - [ - 'user' => 'user1', - 'password' => 'password1', - 'name' => 'user1', - 'mail' => 'user1@localhost', - 'groups' => [ - 'user', - 'test' - ], - 'notify' => false + [ + 'user' => 'user1', + 'password' => 'password1', + 'name' => 'user1', + 'mail' => 'user1@localhost', + 'groups' => [ + 'user', + 'test' ], + 'notify' => false + ], ]; $this->remote->call('dokuwiki.createUser', $params); } diff --git a/inc/Remote/ApiCore.php b/inc/Remote/ApiCore.php index e6c8b3b80..7868eee50 100644 --- a/inc/Remote/ApiCore.php +++ b/inc/Remote/ApiCore.php @@ -492,7 +492,7 @@ class ApiCore $mail = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $userStruct['mail'] ?? '')); $groups = $userStruct['groups'] ?? []; - $notify = (bool)$userStruct['notify'] ?? false; + $notify = (bool) ($userStruct['notify'] ?? false); if ($user === '') throw new RemoteException('empty or invalid user', 401); if ($name === '') throw new RemoteException('empty or invalid user name', 402); -- 2.11.4.GIT