From 382ee5bf93b5c1c00bab0e322aaf52ba9d84fd0b Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 3 Nov 2017 15:44:39 +0100 Subject: [PATCH] Add tests for methods to impersonate users in class 'Administration' --- tests/index.php | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tests/index.php b/tests/index.php index 669e9fe..cee341a 100644 --- a/tests/index.php +++ b/tests/index.php @@ -523,6 +523,63 @@ function processRequestData(\Delight\Auth\Auth $auth) { return 'ID required'; } } + else if ($_POST['action'] === 'admin.logInAsUserById') { + if (isset($_POST['id'])) { + try { + $auth->admin()->logInAsUserById($_POST['id']); + + return 'ok'; + } + catch (\Delight\Auth\UnknownIdException $e) { + return 'unknown ID'; + } + catch (\Delight\Auth\EmailNotVerifiedException $e) { + return 'email address not verified'; + } + } + else { + return 'ID required'; + } + } + else if ($_POST['action'] === 'admin.logInAsUserByEmail') { + if (isset($_POST['email'])) { + try { + $auth->admin()->logInAsUserByEmail($_POST['email']); + + return 'ok'; + } + catch (\Delight\Auth\InvalidEmailException $e) { + return 'unknown email address'; + } + catch (\Delight\Auth\EmailNotVerifiedException $e) { + return 'email address not verified'; + } + } + else { + return 'Email address required'; + } + } + else if ($_POST['action'] === 'admin.logInAsUserByUsername') { + if (isset($_POST['username'])) { + try { + $auth->admin()->logInAsUserByUsername($_POST['username']); + + return 'ok'; + } + catch (\Delight\Auth\UnknownUsernameException $e) { + return 'unknown username'; + } + catch (\Delight\Auth\AmbiguousUsernameException $e) { + return 'ambiguous username'; + } + catch (\Delight\Auth\EmailNotVerifiedException $e) { + return 'email address not verified'; + } + } + else { + return 'Username required'; + } + } else { throw new Exception('Unexpected action: ' . $_POST['action']); } @@ -819,6 +876,24 @@ function showGuestUserForm() { echo ''; echo ''; echo ''; + + echo '
'; + echo ''; + echo ' '; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ' '; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ' '; + echo ''; + echo '
'; } function showConfirmEmailForm() {