<commit_before><?php
/*
 * Copyright 2018 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * 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");
<commit_msg>Test result of delete_invitation_key<commit_after><?php
/*
 * Copyright 2018 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * 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");

{'fraction_non_alphanumeric': 0.23246935905163754, 'fraction_numerical': 0.004621257785814748, 'mean_word_length': 5.481770833333333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923593', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1656, 'n_words': 361}