summaryrefslogtreecommitdiffstats
path: root/application/test/tests/test_service_user.php
blob: d7e34a71b8211efddd7525e759048dc4c83ea927 (plain)
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
62
63
64
65
<?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");

		$ret = \service\user::delete_invitation_key($userid+1, $key);
		$this->t->is(0, $ret, "Should have removed no keys because incorrect user/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");

		$ret = \service\user::delete_invitation_key($userid+1, "foobar-");
		$this->t->is(0, $ret, "Should have removed no keys because incorrect user/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");

		$ret = \service\user::delete_invitation_key($userid+1, "");
		$this->t->is(0, $ret, "Should have removed no keys because incorrect user/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");

		$ret = \service\user::delete_invitation_key($userid, "");
		$this->t->is(0, $ret, "Should have removed no keys because incorrect user/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");

		$ret = \service\user::delete_invitation_key($userid, $key);
		$this->t->is(1, $ret, "One key should be removed");
		$result = $CI->db->select('user, key, action')->from('actions')->get()->result_array();
		$this->t->is_deeply([], $result, "key has been deleted");

	}

}