1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?php
/*
* Copyright 2018 Florian "Bluewind" Pritz <bluewind@server-speed.net>
*
* 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");
}
}
|