summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core/Log_test.php
blob: d44cbac0fc879174b3160092d896394fb109fca9 (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
<?php

class Log_test extends CI_TestCase {

	public function test_configuration()
	{
		$path       = new ReflectionProperty('CI_Log', '_log_path');
		$path->setAccessible(TRUE);
		$threshold  = new ReflectionProperty('CI_Log', '_threshold');
		$threshold->setAccessible(TRUE);
		$date_fmt   = new ReflectionProperty('CI_Log', '_date_fmt');
		$date_fmt->setAccessible(TRUE);
		$file_ext   = new ReflectionProperty('CI_Log', '_file_ext');
		$file_ext->setAccessible(TRUE);
		$file_perms = new ReflectionProperty('CI_Log', '_file_permissions');
		$file_perms->setAccessible(TRUE);
		$enabled    = new ReflectionProperty('CI_Log', '_enabled');
		$enabled->setAccessible(TRUE);

		$this->ci_set_config('log_path', '/root/');
		$this->ci_set_config('log_threshold', 'z');
		$this->ci_set_config('log_date_format', 'd.m.Y');
		$this->ci_set_config('log_file_extension', '');
		$this->ci_set_config('log_file_permissions', '');
		$instance = new CI_Log();

		$this->assertEquals($path->getValue($instance), '/root/');
		$this->assertEquals($threshold->getValue($instance), 1);
		$this->assertEquals($date_fmt->getValue($instance), 'd.m.Y');
		$this->assertEquals($file_ext->getValue($instance), 'php');
		$this->assertEquals($file_perms->getValue($instance), 0644);
		$this->assertEquals($enabled->getValue($instance), FALSE);

		$this->ci_set_config('log_path', '');
		$this->ci_set_config('log_threshold', '0');
		$this->ci_set_config('log_date_format', '');
		$this->ci_set_config('log_file_extension', '.log');
		$this->ci_set_config('log_file_permissions', 0600);
		$instance = new CI_Log();

		$this->assertEquals($path->getValue($instance), APPPATH.'logs/');
		$this->assertEquals($threshold->getValue($instance), 0);
		$this->assertEquals($date_fmt->getValue($instance), 'Y-m-d H:i:s');
		$this->assertEquals($file_ext->getValue($instance), 'log');
		$this->assertEquals($file_perms->getValue($instance), 0600);
		$this->assertEquals($enabled->getValue($instance), TRUE);
	}

	// --------------------------------------------------------------------

	public function test_format_line()
	{
		$this->ci_set_config('log_path', '');
		$this->ci_set_config('log_threshold', 0);
		$instance = new CI_Log();

		$format_line = new ReflectionMethod($instance, '_format_line');
		$format_line->setAccessible(TRUE);
		$this->assertEquals(
			$format_line->invoke($instance, 'LEVEL', 'Timestamp', 'Message'),
			"LEVEL - Timestamp --> Message\n"
		);
	}
}