PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/log/function_view_log_test.php

http://github.com/phpbb/phpbb
PHP | 424 lines | 337 code | 59 blank | 28 comment | 0 complexity | ff2dccdcff1be354e81c5f8497808b31 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';
  14. require_once dirname(__FILE__) . '/../mock/user.php';
  15. require_once dirname(__FILE__) . '/../mock/cache.php';
  16. class phpbb_log_function_view_log_test extends phpbb_database_test_case
  17. {
  18. public function getDataSet()
  19. {
  20. return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml');
  21. }
  22. public static function view_log_function_data()
  23. {
  24. global $phpEx, $phpbb_dispatcher;
  25. $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
  26. $expected_data_sets = array(
  27. 1 => array(
  28. 'id' => 1,
  29. 'reportee_id' => 0,
  30. 'reportee_username' => '',
  31. 'reportee_username_full'=> '',
  32. 'user_id' => 1,
  33. 'username' => 'Anonymous',
  34. 'username_full' => '<span class="username">Anonymous</span>',
  35. 'ip' => '127.0.0.1',
  36. 'time' => 1,
  37. 'forum_id' => 0,
  38. 'topic_id' => 0,
  39. 'post_id' => 0,
  40. 'viewforum' => '',
  41. 'action' => 'LOG_INSTALL_INSTALLED 3.1.0-dev',
  42. ),
  43. 2 => array(
  44. 'id' => 2,
  45. 'reportee_id' => 0,
  46. 'reportee_username' => '',
  47. 'reportee_username_full'=> '',
  48. 'user_id' => 1,
  49. 'username' => 'Anonymous',
  50. 'username_full' => '<span class="username">Anonymous</span>',
  51. 'ip' => '127.0.0.1',
  52. 'time' => 1,
  53. 'forum_id' => 0,
  54. 'topic_id' => 0,
  55. 'post_id' => 0,
  56. 'viewforum' => '',
  57. 'action' => '{LOG KEY NOT EXISTS}<br />additional_data',
  58. ),
  59. 3 => array(
  60. 'id' => 3,
  61. 'reportee_id' => 0,
  62. 'reportee_username' => '',
  63. 'reportee_username_full'=> '',
  64. 'user_id' => 1,
  65. 'username' => 'Anonymous',
  66. 'username_full' => '<span class="username">Anonymous</span>',
  67. 'ip' => '127.0.0.1',
  68. 'time' => 1,
  69. 'forum_id' => 0,
  70. 'topic_id' => 0,
  71. 'post_id' => 0,
  72. 'viewforum' => '',
  73. 'action' => '{LOG CRITICAL}<br />critical data',
  74. ),
  75. 4 => array(
  76. 'id' => 4,
  77. 'reportee_id' => 0,
  78. 'reportee_username' => '',
  79. 'reportee_username_full'=> '',
  80. 'user_id' => 1,
  81. 'username' => 'Anonymous',
  82. 'username_full' => '<span class="username">Anonymous</span>',
  83. 'ip' => '127.0.0.1',
  84. 'time' => 1,
  85. 'forum_id' => 12,
  86. 'topic_id' => 34,
  87. 'post_id' => 0,
  88. 'viewforum' => '',
  89. 'action' => '{LOG MOD}',
  90. 'viewtopic' => '',
  91. 'viewpost' => '',
  92. 'viewlogs' => '',
  93. ),
  94. 5 => array(
  95. 'id' => 5,
  96. 'reportee_id' => 0,
  97. 'reportee_username' => '',
  98. 'reportee_username_full'=> '',
  99. 'user_id' => 1,
  100. 'username' => 'Anonymous',
  101. 'username_full' => '<span class="username">Anonymous</span>',
  102. 'ip' => '127.0.0.1',
  103. 'time' => 1,
  104. 'forum_id' => 12,
  105. 'topic_id' => 45,
  106. 'post_id' => 0,
  107. 'viewforum' => '',
  108. 'action' => '{LOG MOD}',
  109. 'viewtopic' => '',
  110. 'viewpost' => '',
  111. 'viewlogs' => '',
  112. ),
  113. 6 => array(
  114. 'id' => 6,
  115. 'reportee_id' => 0,
  116. 'reportee_username' => '',
  117. 'reportee_username_full'=> '',
  118. 'user_id' => 1,
  119. 'username' => 'Anonymous',
  120. 'username_full' => '<span class="username">Anonymous</span>',
  121. 'ip' => '127.0.0.1',
  122. 'time' => 1,
  123. 'forum_id' => 23,
  124. 'topic_id' => 56,
  125. 'post_id' => 0,
  126. 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'),
  127. 'action' => '{LOG MOD}',
  128. 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&amp;t=56'),
  129. 'viewpost' => '',
  130. 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&amp;mode=topic_logs&amp;t=56'),
  131. ),
  132. 7 => array(
  133. 'id' => 7,
  134. 'reportee_id' => 0,
  135. 'reportee_username' => '',
  136. 'reportee_username_full'=> '',
  137. 'user_id' => 1,
  138. 'username' => 'Anonymous',
  139. 'username_full' => '<span class="username">Anonymous</span>',
  140. 'ip' => '127.0.0.1',
  141. 'time' => 1,
  142. 'forum_id' => 12,
  143. 'topic_id' => 45,
  144. 'post_id' => 0,
  145. 'viewforum' => '',
  146. 'action' => 'LOG_MOD2',
  147. 'viewtopic' => '',
  148. 'viewpost' => '',
  149. 'viewlogs' => '',
  150. ),
  151. 8 => array(
  152. 'id' => 8,
  153. 'reportee_id' => 2,
  154. 'reportee_username' => 'admin',
  155. 'reportee_username_full'=> '<span class="username">admin</span>',
  156. 'user_id' => 1,
  157. 'username' => 'Anonymous',
  158. 'username_full' => '<span class="username">Anonymous</span>',
  159. 'ip' => '127.0.0.1',
  160. 'time' => 1,
  161. 'forum_id' => 0,
  162. 'topic_id' => 0,
  163. 'post_id' => 0,
  164. 'viewforum' => '',
  165. 'action' => 'LOG_USER admin',
  166. ),
  167. 9 => array(
  168. 'id' => 9,
  169. 'reportee_id' => 1,
  170. 'reportee_username' => 'Anonymous',
  171. 'reportee_username_full'=> '<span class="username">Anonymous</span>',
  172. 'user_id' => 1,
  173. 'username' => 'Anonymous',
  174. 'username_full' => '<span class="username">Anonymous</span>',
  175. 'ip' => '127.0.0.1',
  176. 'time' => 1,
  177. 'forum_id' => 0,
  178. 'topic_id' => 0,
  179. 'post_id' => 0,
  180. 'viewforum' => '',
  181. 'action' => 'LOG_USER guest',
  182. ),
  183. 10 => array(
  184. 'id' => 10,
  185. 'reportee_id' => 0,
  186. 'reportee_username' => '',
  187. 'reportee_username_full'=> '',
  188. 'user_id' => 1,
  189. 'username' => 'Anonymous',
  190. 'username_full' => '<span class="username">Anonymous</span>',
  191. 'ip' => '127.0.0.1',
  192. 'time' => 1,
  193. 'forum_id' => 0,
  194. 'topic_id' => 0,
  195. 'post_id' => 0,
  196. 'viewforum' => '',
  197. 'action' => 'LOG_SINGULAR_PLURAL 2',
  198. ),
  199. 11 => array(
  200. 'id' => 11,
  201. 'reportee_id' => 0,
  202. 'reportee_username' => '',
  203. 'reportee_username_full'=> '',
  204. 'user_id' => 1,
  205. 'username' => 'Anonymous',
  206. 'username_full' => '<span class="username">Anonymous</span>',
  207. 'ip' => '127.0.0.1',
  208. 'time' => 1,
  209. 'forum_id' => 15,
  210. 'topic_id' => 3,
  211. 'post_id' => 0,
  212. 'viewforum' => '',
  213. 'action' => 'LOG_MOD3 guest ',
  214. 'viewtopic' => '',
  215. 'viewpost' => '',
  216. 'viewlogs' => '',
  217. ),
  218. );
  219. $test_cases = array(
  220. /**
  221. * Case documentation
  222. array(
  223. // Array of datasets that should be in $log after running the function
  224. 'expected' => array(5, 7),
  225. // Offset that will be returned from the function
  226. 'expected_returned' => 0,
  227. // view_log parameters (see includes/functions_admin.php for docblock)
  228. // $log is omitted!
  229. 'mod', 5, 0, 12, 45,
  230. ),
  231. */
  232. array(
  233. 'expected' => array(1, 2),
  234. 'expected_returned' => 0,
  235. 'admin', false,
  236. ),
  237. array(
  238. 'expected' => array(1),
  239. 'expected_returned' => 0,
  240. 'admin', false, 1,
  241. ),
  242. array(
  243. 'expected' => array(2),
  244. 'expected_returned' => 1,
  245. 'admin', false, 1, 1,
  246. ),
  247. array(
  248. 'expected' => array(2),
  249. 'expected_returned' => 1,
  250. 'admin', 0, 1, 1,
  251. ),
  252. array(
  253. 'expected' => array(2),
  254. 'expected_returned' => 1,
  255. 'admin', 0, 1, 5,
  256. ),
  257. array(
  258. 'expected' => array(3),
  259. 'expected_returned' => 0,
  260. 'critical', false,
  261. ),
  262. array(
  263. 'expected' => array(),
  264. 'expected_returned' => null,
  265. 'mode_does_not_exist', false,
  266. ),
  267. array(
  268. 'expected' => array(4, 5, 7),
  269. 'expected_returned' => 0,
  270. 'mod', 0, 5, 0, 12,
  271. ),
  272. array(
  273. 'expected' => array(5, 7),
  274. 'expected_returned' => 0,
  275. 'mod', 0, 5, 0, 12, 45,
  276. ),
  277. array(
  278. 'expected' => array(6),
  279. 'expected_returned' => 0,
  280. 'mod', 0, 5, 0, 23,
  281. ),
  282. array(
  283. 'expected' => array(8),
  284. 'expected_returned' => 0,
  285. 'user', 0, 5, 0, 0, 0, 2,
  286. ),
  287. array(
  288. 'expected' => array(8, 9, 10),
  289. 'expected_returned' => 0,
  290. 'users', 0,
  291. ),
  292. array(
  293. 'expected' => array(1),
  294. 'expected_returned' => 0,
  295. 'admin', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'install',
  296. ),
  297. array(
  298. 'expected' => array(10),
  299. 'expected_returned' => 0,
  300. 'user', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'plural',
  301. ),
  302. array(
  303. 'expected' => array(11),
  304. 'expected_returned' => 0,
  305. 'mod', 0, 5, 0, 15, 3,
  306. ),
  307. );
  308. foreach ($test_cases as $case => $case_data)
  309. {
  310. foreach ($case_data['expected'] as $data_set => $expected)
  311. {
  312. $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected];
  313. }
  314. }
  315. return $test_cases;
  316. }
  317. /**
  318. * @dataProvider view_log_function_data
  319. */
  320. public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '')
  321. {
  322. global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
  323. $db = $this->new_dbal();
  324. $cache = new phpbb_mock_cache;
  325. $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
  326. // Create auth mock
  327. $auth = $this->createMock('\phpbb\auth\auth');
  328. $acl_get_map = array(
  329. array('f_read', 23, true),
  330. array('m_', 23, true),
  331. );
  332. $acl_gets_map = array(
  333. array('a_', 'm_', 23, true),
  334. );
  335. $auth->expects($this->any())
  336. ->method('acl_get')
  337. ->with($this->stringContains('_'),
  338. $this->anything())
  339. ->will($this->returnValueMap($acl_get_map));
  340. $auth->expects($this->any())
  341. ->method('acl_gets')
  342. ->with($this->stringContains('_'),
  343. $this->anything())
  344. ->will($this->returnValueMap($acl_gets_map));
  345. $user = new phpbb_mock_user;
  346. $user->optionset('viewcensors', false);
  347. // Test sprintf() of the data into the action
  348. $user->lang = array(
  349. 'LOG_INSTALL_INSTALLED' => 'installed: %s',
  350. 'LOG_USER' => 'User<br /> %s',
  351. 'LOG_MOD2' => 'Mod2',
  352. 'LOG_MOD3' => 'Mod3: %1$s, %2$s',
  353. 'LOG_SINGULAR_PLURAL' => array(
  354. 1 => 'singular',
  355. 2 => 'plural (%d)',
  356. ),
  357. );
  358. $user->session_id = false;
  359. $user->data['user_id'] = 10;
  360. $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
  361. $log = array();
  362. $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords));
  363. $this->assertEquals($expected, $log);
  364. }
  365. }