3 require_once 'PHPUnit.php';
4 require_once 'diogenes/diogenes.logger-view.inc.php';
5 require_once 'diogenes/diogenes.core.globals.inc.php';
6 require_once 'TestHelpers.php';
8 class DiogenesLoggerViewTest
extends PHPUnit_TestCase
14 $globals = new DiogenesCoreGlobals
;
16 $globals->database_error_fatal
= true
;
17 $globals->db
= new DiogenesDatabase('test', 'localhost', 'test', '');
18 $globals->db
->_fatal
= true
;
20 if ($globals->db
->err())
22 echo "DB err: " . $globals->db
->error() . "\n";
25 $this->o
= new DiogenesLoggerView();
28 function testConstructor()
32 $this->assertEquals($this->o
->dbh
, $globals->db
);
33 $this->assertTrue(is_a($this->o
->dbh
, 'diogenesdatabase'));
36 function test_getAuths()
39 $globals->table_log_sessions
= 'diogenes_logsessions';
41 $this->assertEquals(array(0 => __('all'), 'native' => 'native', 'external' => 'external'), $this->o
->_getAuths());
43 $globals->db
->query("CREATE TABLE logsesh (auth enum('x', 'y', 'z', 'heh'))");
44 $this->assertFalse($globals->db
->err());
46 $globals->table_log_sessions
= 'logsesh';
47 $this->assertEquals(array(0 => __('all'), 'x' => 'x', 'y' => 'y', 'z' => 'z', 'heh' => 'heh'), $this->o
->_getAuths());
50 function test_getDays()
54 $rows[] = "DELETE FROM diogenes_logsessions";
55 $rows[] = "INSERT INTO diogenes_logsessions (start)
56 VALUES (20040215000000)";
57 $rows[] = "INSERT INTO diogenes_logsessions (start)
58 VALUES (20040315000000)";
59 $rows[] = "INSERT INTO diogenes_logsessions (start)
60 VALUES (20040415000000)";
63 $globals->table_log_sessions
= 'diogenes_logsessions';
65 $febdays[0] = __('all');
66 $mardays[0] = __('all');
67 $aprdays[0] = __('all');
69 // Febdays should be 16 to 29 (leap year), mardays should be
70 // all month, and aprdays should be up to and including
73 for ($i = 1; $i < 16; $i++
)
75 $aprdays[$i] = $mardays[$i] = $i;
78 for ($i = 15; $i < 30; $i++
)
80 $mardays[$i] = $febdays[$i] = $i;
86 $this->assertTrue(checkdate(2,29,2004), "Checkdate giving dodgy results");
87 $this->assertEquals(array(), $this->o
->_getDays(2003, 1));
88 $this->assertEquals(array(), $this->o
->_getDays(2003, 3));
89 $this->assertEquals(array(), $this->o
->_getDays(2003, 6));
90 $this->assertEquals(array(), $this->o
->_getDays(2004, 1));
91 $this->assertEquals($febdays, $this->o
->_getDays(2004, 2));
92 $this->assertEquals($mardays, $this->o
->_getDays(2004, 3));
93 $this->assertEquals($aprdays, $this->o
->_getDays(2004, 4));
94 $this->assertEquals(array(), $this->o
->_getDays(2004, 6));
95 $this->assertEquals(array(), $this->o
->_getDays(2005, 1));
96 $this->assertEquals(array(), $this->o
->_getDays(2005, 3));
97 $this->assertEquals(array(), $this->o
->_getDays(2005, 8));
100 function test_getMonths()
104 $rows[] = "DELETE FROM diogenes_logsessions";
105 $rows[] = "INSERT INTO diogenes_logsessions (start)
106 VALUES (20020401000000)";
107 $rows[] = "INSERT INTO diogenes_logsessions (start)
108 VALUES (20030401000000)";
109 $rows[] = "INSERT INTO diogenes_logsessions (start)
110 VALUES (20040401000000)";
113 $this->assertEquals(array(), $this->o
->_getMonths(2001));
114 $this->assertEquals(array(0=>__('all'), 4=>4, 5=>5, 6=>6, 7=>7, 8=>8,
115 9=>9, 10=>10, 11=>11, 12=>12),
116 $this->o
->_getMonths(2002));
117 $this->assertEquals(array(0=>__('all'), 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6,
118 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12),
119 $this->o
->_getMonths(2003));
120 $this->assertEquals(array(0=>__('all'), 1=>1, 2=>2, 3=>3, 4=>4),
121 $this->o
->_getMonths(2004));
122 $this->assertEquals(array(), $this->o
->_getMonths(2005));
125 function test_getYears()
129 $rows[] = "DELETE FROM diogenes_logsessions";
130 $rows[] = "INSERT INTO diogenes_logsessions (start)
131 VALUES (20020401000000)";
132 $rows[] = "INSERT INTO diogenes_logsessions (start)
133 VALUES (20040401000000)";
136 $this->assertEquals(array(0=>__('all'), 2002=>2002, 2003=>2003, 2004=>2004),
137 $this->o
->_getYears());