ProtectLogFormatterTest.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. /**
  3. * @covers ProtectLogFormatter
  4. */
  5. class ProtectLogFormatterTest 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 provideProtectLogDatabaseRows() {
  12. return [
  13. // Current format
  14. [
  15. [
  16. 'type' => 'protect',
  17. 'action' => 'protect',
  18. 'comment' => 'protect comment',
  19. 'namespace' => NS_MAIN,
  20. 'title' => 'ProtectPage',
  21. 'params' => [
  22. '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  23. '5:bool:cascade' => false,
  24. 'details' => [
  25. [
  26. 'type' => 'edit',
  27. 'level' => 'sysop',
  28. 'expiry' => 'infinity',
  29. 'cascade' => false,
  30. ],
  31. [
  32. 'type' => 'move',
  33. 'level' => 'sysop',
  34. 'expiry' => 'infinity',
  35. 'cascade' => false,
  36. ],
  37. ],
  38. ],
  39. ],
  40. [
  41. 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
  42. '(indefinite) [Move=Allow only administrators] (indefinite)',
  43. 'api' => [
  44. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  45. 'cascade' => false,
  46. 'details' => [
  47. [
  48. 'type' => 'edit',
  49. 'level' => 'sysop',
  50. 'expiry' => 'infinite',
  51. 'cascade' => false,
  52. ],
  53. [
  54. 'type' => 'move',
  55. 'level' => 'sysop',
  56. 'expiry' => 'infinite',
  57. 'cascade' => false,
  58. ],
  59. ],
  60. ],
  61. ],
  62. ],
  63. // Current format with cascade
  64. [
  65. [
  66. 'type' => 'protect',
  67. 'action' => 'protect',
  68. 'comment' => 'protect comment',
  69. 'namespace' => NS_MAIN,
  70. 'title' => 'ProtectPage',
  71. 'params' => [
  72. '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  73. '5:bool:cascade' => true,
  74. 'details' => [
  75. [
  76. 'type' => 'edit',
  77. 'level' => 'sysop',
  78. 'expiry' => 'infinity',
  79. 'cascade' => true,
  80. ],
  81. [
  82. 'type' => 'move',
  83. 'level' => 'sysop',
  84. 'expiry' => 'infinity',
  85. 'cascade' => false,
  86. ],
  87. ],
  88. ],
  89. ],
  90. [
  91. 'text' => 'User protected ProtectPage [Edit=Allow only administrators] ' .
  92. '(indefinite) [Move=Allow only administrators] (indefinite) [cascading]',
  93. 'api' => [
  94. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  95. 'cascade' => true,
  96. 'details' => [
  97. [
  98. 'type' => 'edit',
  99. 'level' => 'sysop',
  100. 'expiry' => 'infinite',
  101. 'cascade' => true,
  102. ],
  103. [
  104. 'type' => 'move',
  105. 'level' => 'sysop',
  106. 'expiry' => 'infinite',
  107. 'cascade' => false,
  108. ],
  109. ],
  110. ],
  111. ],
  112. ],
  113. // Legacy format
  114. [
  115. [
  116. 'type' => 'protect',
  117. 'action' => 'protect',
  118. 'comment' => 'protect comment',
  119. 'namespace' => NS_MAIN,
  120. 'title' => 'ProtectPage',
  121. 'params' => [
  122. '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  123. '',
  124. ],
  125. ],
  126. [
  127. 'legacy' => true,
  128. 'text' => 'User protected ProtectPage [edit=sysop] (indefinite)[move=sysop] (indefinite)',
  129. 'api' => [
  130. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  131. 'cascade' => false,
  132. ],
  133. ],
  134. ],
  135. // Legacy format with cascade
  136. [
  137. [
  138. 'type' => 'protect',
  139. 'action' => 'protect',
  140. 'comment' => 'protect comment',
  141. 'namespace' => NS_MAIN,
  142. 'title' => 'ProtectPage',
  143. 'params' => [
  144. '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  145. 'cascade',
  146. ],
  147. ],
  148. [
  149. 'legacy' => true,
  150. 'text' => 'User protected ProtectPage [edit=sysop] ' .
  151. '(indefinite)[move=sysop] (indefinite) [cascading]',
  152. 'api' => [
  153. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  154. 'cascade' => true,
  155. ],
  156. ],
  157. ],
  158. ];
  159. }
  160. /**
  161. * @dataProvider provideProtectLogDatabaseRows
  162. */
  163. public function testProtectLogDatabaseRows( $row, $extra ) {
  164. $this->doTestLogFormatter( $row, $extra );
  165. }
  166. /**
  167. * Provide different rows from the logging table to test
  168. * for backward compatibility.
  169. * Do not change the existing data, just add a new database row
  170. */
  171. public static function provideModifyLogDatabaseRows() {
  172. return [
  173. // Current format
  174. [
  175. [
  176. 'type' => 'protect',
  177. 'action' => 'modify',
  178. 'comment' => 'protect comment',
  179. 'namespace' => NS_MAIN,
  180. 'title' => 'ProtectPage',
  181. 'params' => [
  182. '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  183. '5:bool:cascade' => false,
  184. 'details' => [
  185. [
  186. 'type' => 'edit',
  187. 'level' => 'sysop',
  188. 'expiry' => 'infinity',
  189. 'cascade' => false,
  190. ],
  191. [
  192. 'type' => 'move',
  193. 'level' => 'sysop',
  194. 'expiry' => 'infinity',
  195. 'cascade' => false,
  196. ],
  197. ],
  198. ],
  199. ],
  200. [
  201. 'text' => 'User changed protection level for ProtectPage ' .
  202. '[Edit=Allow only administrators] ' .
  203. '(indefinite) [Move=Allow only administrators] (indefinite)',
  204. 'api' => [
  205. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  206. 'cascade' => false,
  207. 'details' => [
  208. [
  209. 'type' => 'edit',
  210. 'level' => 'sysop',
  211. 'expiry' => 'infinite',
  212. 'cascade' => false,
  213. ],
  214. [
  215. 'type' => 'move',
  216. 'level' => 'sysop',
  217. 'expiry' => 'infinite',
  218. 'cascade' => false,
  219. ],
  220. ],
  221. ],
  222. ],
  223. ],
  224. // Current format with cascade
  225. [
  226. [
  227. 'type' => 'protect',
  228. 'action' => 'modify',
  229. 'comment' => 'protect comment',
  230. 'namespace' => NS_MAIN,
  231. 'title' => 'ProtectPage',
  232. 'params' => [
  233. '4::description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  234. '5:bool:cascade' => true,
  235. 'details' => [
  236. [
  237. 'type' => 'edit',
  238. 'level' => 'sysop',
  239. 'expiry' => 'infinity',
  240. 'cascade' => true,
  241. ],
  242. [
  243. 'type' => 'move',
  244. 'level' => 'sysop',
  245. 'expiry' => 'infinity',
  246. 'cascade' => false,
  247. ],
  248. ],
  249. ],
  250. ],
  251. [
  252. 'text' => 'User changed protection level for ProtectPage ' .
  253. '[Edit=Allow only administrators] (indefinite) ' .
  254. '[Move=Allow only administrators] (indefinite) [cascading]',
  255. 'api' => [
  256. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  257. 'cascade' => true,
  258. 'details' => [
  259. [
  260. 'type' => 'edit',
  261. 'level' => 'sysop',
  262. 'expiry' => 'infinite',
  263. 'cascade' => true,
  264. ],
  265. [
  266. 'type' => 'move',
  267. 'level' => 'sysop',
  268. 'expiry' => 'infinite',
  269. 'cascade' => false,
  270. ],
  271. ],
  272. ],
  273. ],
  274. ],
  275. // Legacy format
  276. [
  277. [
  278. 'type' => 'protect',
  279. 'action' => 'modify',
  280. 'comment' => 'protect comment',
  281. 'namespace' => NS_MAIN,
  282. 'title' => 'ProtectPage',
  283. 'params' => [
  284. '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  285. '',
  286. ],
  287. ],
  288. [
  289. 'legacy' => true,
  290. 'text' => 'User changed protection level for ProtectPage ' .
  291. '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  292. 'api' => [
  293. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  294. 'cascade' => false,
  295. ],
  296. ],
  297. ],
  298. // Legacy format with cascade
  299. [
  300. [
  301. 'type' => 'protect',
  302. 'action' => 'modify',
  303. 'comment' => 'protect comment',
  304. 'namespace' => NS_MAIN,
  305. 'title' => 'ProtectPage',
  306. 'params' => [
  307. '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  308. 'cascade',
  309. ],
  310. ],
  311. [
  312. 'legacy' => true,
  313. 'text' => 'User changed protection level for ProtectPage ' .
  314. '[edit=sysop] (indefinite)[move=sysop] (indefinite) [cascading]',
  315. 'api' => [
  316. 'description' => '[edit=sysop] (indefinite)[move=sysop] (indefinite)',
  317. 'cascade' => true,
  318. ],
  319. ],
  320. ],
  321. ];
  322. }
  323. /**
  324. * @dataProvider provideModifyLogDatabaseRows
  325. */
  326. public function testModifyLogDatabaseRows( $row, $extra ) {
  327. $this->doTestLogFormatter( $row, $extra );
  328. }
  329. /**
  330. * Provide different rows from the logging table to test
  331. * for backward compatibility.
  332. * Do not change the existing data, just add a new database row
  333. */
  334. public static function provideUnprotectLogDatabaseRows() {
  335. return [
  336. // Current format
  337. [
  338. [
  339. 'type' => 'protect',
  340. 'action' => 'unprotect',
  341. 'comment' => 'unprotect comment',
  342. 'namespace' => NS_MAIN,
  343. 'title' => 'ProtectPage',
  344. 'params' => [],
  345. ],
  346. [
  347. 'text' => 'User removed protection from ProtectPage',
  348. 'api' => [],
  349. ],
  350. ],
  351. ];
  352. }
  353. /**
  354. * @dataProvider provideUnprotectLogDatabaseRows
  355. */
  356. public function testUnprotectLogDatabaseRows( $row, $extra ) {
  357. $this->doTestLogFormatter( $row, $extra );
  358. }
  359. /**
  360. * Provide different rows from the logging table to test
  361. * for backward compatibility.
  362. * Do not change the existing data, just add a new database row
  363. */
  364. public static function provideMoveProtLogDatabaseRows() {
  365. return [
  366. // Current format
  367. [
  368. [
  369. 'type' => 'protect',
  370. 'action' => 'move_prot',
  371. 'comment' => 'Move comment',
  372. 'namespace' => NS_MAIN,
  373. 'title' => 'NewPage',
  374. 'params' => [
  375. '4::oldtitle' => 'OldPage',
  376. ],
  377. ],
  378. [
  379. 'text' => 'User moved protection settings from OldPage to NewPage',
  380. 'api' => [
  381. 'oldtitle_ns' => 0,
  382. 'oldtitle_title' => 'OldPage',
  383. ],
  384. ],
  385. ],
  386. // Legacy format
  387. [
  388. [
  389. 'type' => 'protect',
  390. 'action' => 'move_prot',
  391. 'comment' => 'Move comment',
  392. 'namespace' => NS_MAIN,
  393. 'title' => 'NewPage',
  394. 'params' => [
  395. 'OldPage',
  396. ],
  397. ],
  398. [
  399. 'legacy' => true,
  400. 'text' => 'User moved protection settings from OldPage to NewPage',
  401. 'api' => [
  402. 'oldtitle_ns' => 0,
  403. 'oldtitle_title' => 'OldPage',
  404. ],
  405. ],
  406. ],
  407. ];
  408. }
  409. /**
  410. * @dataProvider provideMoveProtLogDatabaseRows
  411. */
  412. public function testMoveProtLogDatabaseRows( $row, $extra ) {
  413. $this->doTestLogFormatter( $row, $extra );
  414. }
  415. }