Exemple #1
0
 public function test_log_add()
 {
     global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
     $db = $this->new_dbal();
     $cache = new phpbb_mock_cache();
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
     $lang = new \phpbb\language\language($lang_loader);
     $user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $auth = $this->getMock('\\phpbb\\auth\\auth');
     $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
     $mode = 'critical';
     $user_id = ANONYMOUS;
     $log_ip = 'user_ip';
     $log_time = time();
     $log_operation = 'LOG_OPERATION';
     $additional_data = array();
     // Add an entry successful
     $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
     // Disable logging for all types
     $log->disable();
     $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed');
     $log->enable();
     // Disable logging for same type
     $log->disable('critical');
     $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed');
     $log->enable();
     // Disable logging for different type
     $log->disable('admin');
     $this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed');
     $log->enable();
     // Invalid mode specified
     $this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time));
 }
Exemple #2
0
 public function test_log_add()
 {
     global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
     $db = $this->new_dbal();
     $cache = new phpbb_mock_cache();
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
     $lang = new \phpbb\language\language($lang_loader);
     $user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $auth = $this->getMock('\\phpbb\\auth\\auth');
     $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
     $mode = 'critical';
     $user_id = ANONYMOUS;
     $log_ip = 'user_ip';
     $log_time = time();
     $log_operation = 'LOG_OPERATION';
     $additional_data = array();
     // Add an entry successful
     $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
     // Disable logging for all types
     $log->disable();
     $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed');
     $log->enable();
     // Disable logging for same type
     $log->disable('critical');
     $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed');
     $log->enable();
     // Disable logging for different type
     $log->disable('admin');
     $this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed');
     $log->enable();
     // Invalid mode specified
     $this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time));
     // null user and null ip given
     $this->assertEquals(3, $log->add($mode, null, null, $log_operation, $log_time), 'Adding log with null user_id and null user_ip failed');
     $sql = 'SELECT user_id, log_ip FROM ' . LOG_TABLE . ' WHERE log_id = 3';
     $result = $db->sql_query($sql);
     $row = $db->sql_fetchrow($result);
     $db->sql_freeresult($result);
     $this->assertEquals(ANONYMOUS, $row['user_id'], 'Adding log with null user_id failed');
     $this->assertEquals('', $row['log_ip'], 'Adding log with null user_ip failed');
 }