diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml new file mode 100644 index 0000000000..2ce2643d26 --- /dev/null +++ b/tests/log/fixtures/full_log.xml @@ -0,0 +1,166 @@ + + + + log_id + log_type + user_id + forum_id + topic_id + reportee_id + log_ip + log_time + log_operation + log_data + + 1 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_INSTALL_INSTALLED + a:1:{i:0;s:9:"3.1.0-dev";} + + + 2 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_KEY_NOT_EXISTS + a:1:{i:0;s:15:"additional_data";} + + + 3 + 2 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_CRITICAL + a:1:{i:0;s:13:"critical data";} + + + 4 + 1 + 1 + 12 + 34 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 5 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 6 + 1 + 1 + 23 + 56 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 7 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD2 + + + + 8 + 3 + 1 + 0 + 0 + 2 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"admin";} + + + 9 + 3 + 1 + 0 + 0 + 1 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"guest";} + +
+ + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + Anonymous + Anonymous + + + + + + + 2 + admin + admin + + + + + +
+ + topic_id + forum_id + + 34 + 12 + + + 45 + 12 + + + 56 + 23 + +
+
diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php new file mode 100644 index 0000000000..7c44413330 --- /dev/null +++ b/tests/log/function_view_log_test.php @@ -0,0 +1,341 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml'); + } + + public static function test_view_log_function_data() + { + global $phpEx; + + $expected_data_sets = array( + 1 => array( + 'id' => 1, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => 'installed: 3.1.0-dev', + ), + 2 => array( + 'id' => 2, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG KEY NOT EXISTS}
additional_data', + ), + 3 => array( + 'id' => 3, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG CRITICAL}
critical data', + ), + 4 => array( + 'id' => 4, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 34, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 5 => array( + 'id' => 5, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 6 => array( + 'id' => 6, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 23, + 'topic_id' => 56, + + 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'), + 'action' => '{LOG MOD}', + 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&t=56'), + 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&mode=topic_logs&t=56'), + ), + 7 => array( + 'id' => 7, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 12, + 'topic_id' => 45, + + 'viewforum' => '', + 'action' => '{LOG MOD2}', + 'viewtopic' => '', + 'viewlogs' => '', + ), + 8 => array( + 'id' => 8, + + 'reportee_id' => 2, + 'reportee_username' => 'admin', + 'reportee_username_full'=> 'admin', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}
admin', + ), + 9 => array( + 'id' => 9, + + 'reportee_id' => 1, + 'reportee_username' => 'Anonymous', + 'reportee_username_full'=> 'Anonymous', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 0, + 'topic_id' => 0, + + 'viewforum' => '', + 'action' => '{LOG USER}
guest', + ), + ); + + $test_cases = array( + array( + 'expected' => array(1, 2), + 'expected_returned' => 0, + false, + 'admin', + ), + array( + 'expected' => array(1), + 'expected_returned' => 0, + false, + 'admin', 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + false, + 'admin', 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 0, + 'admin', 1, 1, + ), + array( + 'expected' => array(2), + 'expected_returned' => 1, + 0, + 'admin', 1, 5, + ), + array( + 'expected' => array(3), + 'expected_returned' => 0, + false, + 'critical', + ), + array( + 'expected' => array(), + 'expected_returned' => null, + false, + 'mode_does_not_exist', + ), + array( + 'expected' => array(4, 5, 7), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 12, + ), + array( + 'expected' => array(5, 7), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 12, 45, + ), + array( + 'expected' => array(6), + 'expected_returned' => 0, + 0, + 'mod', 5, 0, 23, + ), + array( + 'expected' => array(8), + 'expected_returned' => 0, + 0, + 'user', 5, 0, 0, 0, 2, + ), + array( + 'expected' => array(8, 9), + 'expected_returned' => 0, + 0, + 'users', + ), + ); + + foreach ($test_cases as $case => $case_data) + { + foreach ($case_data['expected'] as $data_set => $expected) + { + $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected]; + } + } + + return $test_cases; + } + + /** + * @dataProvider test_view_log_function_data + */ + public function test_view_log_function($expected, $expected_returned, $log_count, $mode, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') + { + global $cache, $db, $user, $auth; + + $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; + + // Create auth mock + $auth = $this->getMock('auth'); + $acl_get_map = array( + array('f_read', 23, true), + array('m_', 23, true), + ); + $acl_gets_map = array( + array('a_', 'm_', 23, true), + ); + + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_get_map)); + $auth->expects($this->any()) + ->method('acl_gets') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_gets_map)); + + $user = new phpbb_mock_user; + $user->optionset('viewcensors', false); + // Test sprintf() of the data into the action + $user->lang = array( + 'LOG_INSTALL_INSTALLED' => 'installed: %s', + ); + + $log = array(); + $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); + + $this->assertEquals($expected, $log); + } +}