aboutsummaryrefslogtreecommitdiffstats
path: root/tests/log/add_test.php
blob: a2b763f2b74c89e4c47005b9b42768394ab9b571 (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
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';

class phpbb_log_add_test extends phpbb_database_test_case
{
	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml');
	}

	public function test_log_enabled()
	{
		$log = new phpbb_log(LOG_TABLE);
		$this->assertTrue($log->is_enabled());

		$log->disable();
		$this->assertFalse($log->is_enabled());

		$log->enable();
		$this->assertTrue($log->is_enabled());
	}

	public function test_log_add()
	{
		global $db;

		$db = $this->new_dbal();

		$mode = 'critical';
		$user_id = ANONYMOUS;
		$log_ip = 'user_ip';
		$log_time = time();
		$log_operation = 'LOG_OPERATION';
		$additional_data = array();

		// Add an entry successful
		$log = new phpbb_log(LOG_TABLE);
		$this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));

		// Disable logging
		$log->disable();
		$this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
		$log->enable();

		// Invalid mode specified
		$this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time));
	}
}