summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/logging/BlockLogFormatterTest.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /tests/phpunit/includes/logging/BlockLogFormatterTest.php
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'tests/phpunit/includes/logging/BlockLogFormatterTest.php')
-rw-r--r--tests/phpunit/includes/logging/BlockLogFormatterTest.php372
1 files changed, 372 insertions, 0 deletions
diff --git a/tests/phpunit/includes/logging/BlockLogFormatterTest.php b/tests/phpunit/includes/logging/BlockLogFormatterTest.php
new file mode 100644
index 00000000..c7dc641d
--- /dev/null
+++ b/tests/phpunit/includes/logging/BlockLogFormatterTest.php
@@ -0,0 +1,372 @@
+<?php
+
+class BlockLogFormatterTest extends LogFormatterTestCase {
+
+ /**
+ * Provide different rows from the logging table to test
+ * for backward compatibility.
+ * Do not change the existing data, just add a new database row
+ */
+ public static function provideBlockLogDatabaseRows() {
+ return array(
+ // Current log format
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ '5::duration' => 'infinite',
+ '6::flags' => 'anononly',
+ ),
+ ),
+ array(
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // Old legacy log
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ 'anononly',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // Old legacy log without flag
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+
+ // Very old legacy log without duration
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideBlockLogDatabaseRows
+ */
+ public function testBlockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * Provide different rows from the logging table to test
+ * for backward compatibility.
+ * Do not change the existing data, just add a new database row
+ */
+ public static function provideReblockLogDatabaseRows() {
+ return array(
+ // Current log format
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'reblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ '5::duration' => 'infinite',
+ '6::flags' => 'anononly',
+ ),
+ ),
+ array(
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // Old log
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'reblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ 'anononly',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // Older log without flag
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'reblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ )
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of indefinite',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array(),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideReblockLogDatabaseRows
+ */
+ public function testReblockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * Provide different rows from the logging table to test
+ * for backward compatibility.
+ * Do not change the existing data, just add a new database row
+ */
+ public static function provideUnblockLogDatabaseRows() {
+ return array(
+ // Current log format
+ array(
+ array(
+ 'type' => 'block',
+ 'action' => 'unblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(),
+ ),
+ array(
+ 'text' => 'Sysop unblocked Logtestuser',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideUnblockLogDatabaseRows
+ */
+ public function testUnblockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * Provide different rows from the logging table to test
+ * for backward compatibility.
+ * Do not change the existing data, just add a new database row
+ */
+ public static function provideSuppressBlockLogDatabaseRows() {
+ return array(
+ // Current log format
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ '5::duration' => 'infinite',
+ '6::flags' => 'anononly',
+ ),
+ ),
+ array(
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // legacy log
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'block',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ 'anononly',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop blocked Logtestuser with an expiry time of indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideSuppressBlockLogDatabaseRows
+ */
+ public function testSuppressBlockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * Provide different rows from the logging table to test
+ * for backward compatibility.
+ * Do not change the existing data, just add a new database row
+ */
+ public static function provideSuppressReblockLogDatabaseRows() {
+ return array(
+ // Current log format
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'reblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ '5::duration' => 'infinite',
+ '6::flags' => 'anononly',
+ ),
+ ),
+ array(
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'suppress',
+ 'action' => 'reblock',
+ 'comment' => 'Block comment',
+ 'user' => 0,
+ 'user_text' => 'Sysop',
+ 'namespace' => NS_USER,
+ 'title' => 'Logtestuser',
+ 'params' => array(
+ 'infinite',
+ 'anononly',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'Sysop changed block settings for Logtestuser with an expiry time of'
+ . ' indefinite (anonymous users only)',
+ 'api' => array(
+ 'duration' => 'infinite',
+ 'flags' => array( 'anononly' ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider provideSuppressReblockLogDatabaseRows
+ */
+ public function testSuppressReblockLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+}