BlockLogFormatterTest.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. /**
  3. * @covers BlockLogFormatter
  4. */
  5. class BlockLogFormatterTest extends LogFormatterTestCase {
  6. /**
  7. * Provide different rows from the logging table to test
  8. * for backward compatibility.
  9. * Do not change the existing data, just add a new database row
  10. */
  11. public static function provideBlockLogDatabaseRows() {
  12. return [
  13. // Current log format
  14. [
  15. [
  16. 'type' => 'block',
  17. 'action' => 'block',
  18. 'comment' => 'Block comment',
  19. 'user' => 0,
  20. 'user_text' => 'Sysop',
  21. 'namespace' => NS_USER,
  22. 'title' => 'Logtestuser',
  23. 'params' => [
  24. '5::duration' => 'infinite',
  25. '6::flags' => 'anononly',
  26. ],
  27. ],
  28. [
  29. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
  30. . ' (anonymous users only)',
  31. 'api' => [
  32. 'duration' => 'infinite',
  33. 'flags' => [ 'anononly' ],
  34. ],
  35. ],
  36. ],
  37. // Old legacy log
  38. [
  39. [
  40. 'type' => 'block',
  41. 'action' => 'block',
  42. 'comment' => 'Block comment',
  43. 'user' => 0,
  44. 'user_text' => 'Sysop',
  45. 'namespace' => NS_USER,
  46. 'title' => 'Logtestuser',
  47. 'params' => [
  48. 'infinite',
  49. 'anononly',
  50. ],
  51. ],
  52. [
  53. 'legacy' => true,
  54. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
  55. . ' (anonymous users only)',
  56. 'api' => [
  57. 'duration' => 'infinite',
  58. 'flags' => [ 'anononly' ],
  59. ],
  60. ],
  61. ],
  62. // Old legacy log without flag
  63. [
  64. [
  65. 'type' => 'block',
  66. 'action' => 'block',
  67. 'comment' => 'Block comment',
  68. 'user' => 0,
  69. 'user_text' => 'Sysop',
  70. 'namespace' => NS_USER,
  71. 'title' => 'Logtestuser',
  72. 'params' => [
  73. 'infinite',
  74. ],
  75. ],
  76. [
  77. 'legacy' => true,
  78. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
  79. 'api' => [
  80. 'duration' => 'infinite',
  81. 'flags' => [],
  82. ],
  83. ],
  84. ],
  85. // Very old legacy log without duration
  86. [
  87. [
  88. 'type' => 'block',
  89. 'action' => 'block',
  90. 'comment' => 'Block comment',
  91. 'user' => 0,
  92. 'user_text' => 'Sysop',
  93. 'namespace' => NS_USER,
  94. 'title' => 'Logtestuser',
  95. 'params' => [],
  96. ],
  97. [
  98. 'legacy' => true,
  99. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite',
  100. 'api' => [
  101. 'duration' => 'infinite',
  102. 'flags' => [],
  103. ],
  104. ],
  105. ],
  106. ];
  107. }
  108. /**
  109. * @dataProvider provideBlockLogDatabaseRows
  110. */
  111. public function testBlockLogDatabaseRows( $row, $extra ) {
  112. $this->doTestLogFormatter( $row, $extra );
  113. }
  114. /**
  115. * Provide different rows from the logging table to test
  116. * for backward compatibility.
  117. * Do not change the existing data, just add a new database row
  118. */
  119. public static function provideReblockLogDatabaseRows() {
  120. return [
  121. // Current log format
  122. [
  123. [
  124. 'type' => 'block',
  125. 'action' => 'reblock',
  126. 'comment' => 'Block comment',
  127. 'user' => 0,
  128. 'user_text' => 'Sysop',
  129. 'namespace' => NS_USER,
  130. 'title' => 'Logtestuser',
  131. 'params' => [
  132. '5::duration' => 'infinite',
  133. '6::flags' => 'anononly',
  134. ],
  135. ],
  136. [
  137. 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
  138. . ' indefinite (anonymous users only)',
  139. 'api' => [
  140. 'duration' => 'infinite',
  141. 'flags' => [ 'anononly' ],
  142. ],
  143. ],
  144. ],
  145. // Old log
  146. [
  147. [
  148. 'type' => 'block',
  149. 'action' => 'reblock',
  150. 'comment' => 'Block comment',
  151. 'user' => 0,
  152. 'user_text' => 'Sysop',
  153. 'namespace' => NS_USER,
  154. 'title' => 'Logtestuser',
  155. 'params' => [
  156. 'infinite',
  157. 'anononly',
  158. ],
  159. ],
  160. [
  161. 'legacy' => true,
  162. 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
  163. . ' indefinite (anonymous users only)',
  164. 'api' => [
  165. 'duration' => 'infinite',
  166. 'flags' => [ 'anononly' ],
  167. ],
  168. ],
  169. ],
  170. // Older log without flag
  171. [
  172. [
  173. 'type' => 'block',
  174. 'action' => 'reblock',
  175. 'comment' => 'Block comment',
  176. 'user' => 0,
  177. 'user_text' => 'Sysop',
  178. 'namespace' => NS_USER,
  179. 'title' => 'Logtestuser',
  180. 'params' => [
  181. 'infinite',
  182. ]
  183. ],
  184. [
  185. 'legacy' => true,
  186. 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of indefinite',
  187. 'api' => [
  188. 'duration' => 'infinite',
  189. 'flags' => [],
  190. ],
  191. ],
  192. ],
  193. ];
  194. }
  195. /**
  196. * @dataProvider provideReblockLogDatabaseRows
  197. */
  198. public function testReblockLogDatabaseRows( $row, $extra ) {
  199. $this->doTestLogFormatter( $row, $extra );
  200. }
  201. /**
  202. * Provide different rows from the logging table to test
  203. * for backward compatibility.
  204. * Do not change the existing data, just add a new database row
  205. */
  206. public static function provideUnblockLogDatabaseRows() {
  207. return [
  208. // Current log format
  209. [
  210. [
  211. 'type' => 'block',
  212. 'action' => 'unblock',
  213. 'comment' => 'Block comment',
  214. 'user' => 0,
  215. 'user_text' => 'Sysop',
  216. 'namespace' => NS_USER,
  217. 'title' => 'Logtestuser',
  218. 'params' => [],
  219. ],
  220. [
  221. 'text' => 'Sysop unblocked Logtestuser',
  222. 'api' => [],
  223. ],
  224. ],
  225. ];
  226. }
  227. /**
  228. * @dataProvider provideUnblockLogDatabaseRows
  229. */
  230. public function testUnblockLogDatabaseRows( $row, $extra ) {
  231. $this->doTestLogFormatter( $row, $extra );
  232. }
  233. /**
  234. * Provide different rows from the logging table to test
  235. * for backward compatibility.
  236. * Do not change the existing data, just add a new database row
  237. */
  238. public static function provideSuppressBlockLogDatabaseRows() {
  239. return [
  240. // Current log format
  241. [
  242. [
  243. 'type' => 'suppress',
  244. 'action' => 'block',
  245. 'comment' => 'Block comment',
  246. 'user' => 0,
  247. 'user_text' => 'Sysop',
  248. 'namespace' => NS_USER,
  249. 'title' => 'Logtestuser',
  250. 'params' => [
  251. '5::duration' => 'infinite',
  252. '6::flags' => 'anononly',
  253. ],
  254. ],
  255. [
  256. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
  257. . ' (anonymous users only)',
  258. 'api' => [
  259. 'duration' => 'infinite',
  260. 'flags' => [ 'anononly' ],
  261. ],
  262. ],
  263. ],
  264. // legacy log
  265. [
  266. [
  267. 'type' => 'suppress',
  268. 'action' => 'block',
  269. 'comment' => 'Block comment',
  270. 'user' => 0,
  271. 'user_text' => 'Sysop',
  272. 'namespace' => NS_USER,
  273. 'title' => 'Logtestuser',
  274. 'params' => [
  275. 'infinite',
  276. 'anononly',
  277. ],
  278. ],
  279. [
  280. 'legacy' => true,
  281. 'text' => 'Sysop blocked Logtestuser with an expiration time of indefinite'
  282. . ' (anonymous users only)',
  283. 'api' => [
  284. 'duration' => 'infinite',
  285. 'flags' => [ 'anononly' ],
  286. ],
  287. ],
  288. ],
  289. ];
  290. }
  291. /**
  292. * @dataProvider provideSuppressBlockLogDatabaseRows
  293. */
  294. public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
  295. $this->doTestLogFormatter( $row, $extra );
  296. }
  297. /**
  298. * Provide different rows from the logging table to test
  299. * for backward compatibility.
  300. * Do not change the existing data, just add a new database row
  301. */
  302. public static function provideSuppressReblockLogDatabaseRows() {
  303. return [
  304. // Current log format
  305. [
  306. [
  307. 'type' => 'suppress',
  308. 'action' => 'reblock',
  309. 'comment' => 'Block comment',
  310. 'user' => 0,
  311. 'user_text' => 'Sysop',
  312. 'namespace' => NS_USER,
  313. 'title' => 'Logtestuser',
  314. 'params' => [
  315. '5::duration' => 'infinite',
  316. '6::flags' => 'anononly',
  317. ],
  318. ],
  319. [
  320. 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
  321. . ' indefinite (anonymous users only)',
  322. 'api' => [
  323. 'duration' => 'infinite',
  324. 'flags' => [ 'anononly' ],
  325. ],
  326. ],
  327. ],
  328. // Legacy format
  329. [
  330. [
  331. 'type' => 'suppress',
  332. 'action' => 'reblock',
  333. 'comment' => 'Block comment',
  334. 'user' => 0,
  335. 'user_text' => 'Sysop',
  336. 'namespace' => NS_USER,
  337. 'title' => 'Logtestuser',
  338. 'params' => [
  339. 'infinite',
  340. 'anononly',
  341. ],
  342. ],
  343. [
  344. 'legacy' => true,
  345. 'text' => 'Sysop changed block settings for Logtestuser with an expiration time of'
  346. . ' indefinite (anonymous users only)',
  347. 'api' => [
  348. 'duration' => 'infinite',
  349. 'flags' => [ 'anononly' ],
  350. ],
  351. ],
  352. ],
  353. ];
  354. }
  355. /**
  356. * @dataProvider provideSuppressReblockLogDatabaseRows
  357. */
  358. public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
  359. $this->doTestLogFormatter( $row, $extra );
  360. }
  361. }