From 11ea08df8d4784aad4836852180098c45b90c5a2 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 18 May 2018 23:06:40 +0200 Subject: Add invitation key deletion Signed-off-by: Florian Pritz --- application/test/tests/test_service_user.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 application/test/tests/test_service_user.php (limited to 'application/test/tests/test_service_user.php') diff --git a/application/test/tests/test_service_user.php b/application/test/tests/test_service_user.php new file mode 100644 index 000000000..4cbbdfac0 --- /dev/null +++ b/application/test/tests/test_service_user.php @@ -0,0 +1,61 @@ + + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +namespace test\tests; + +class test_service_user extends \test\Test { + + public function __construct() { + parent::__construct(); + } + + public function init() { + } + + public function cleanup() { + } + + public function test_invitation_key_delete() { + $CI =& get_instance(); + + $userid = 1; + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([], $result, "database contains no actions"); + + $key = \service\user::create_invitation_key($userid); + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key"); + + \service\user::delete_invitation_key($userid+1, $key); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid+1, "foobar-"); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid+1, ""); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key after incorrect deletion"); + + \service\user::delete_invitation_key($userid, ""); + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([['user' => "".$userid, 'key' => $key, 'action' => 'invitation']], $result, "database contains new key"); + + \service\user::delete_invitation_key($userid, $key); + + $result = $CI->db->select('user, key, action')->from('actions')->get()->result_array(); + $this->t->is_deeply([], $result, "key has been deleted"); + + } + +} + -- cgit v1.2.3-24-g4f1b