Add tests for Sanitizer::escapeId
authorFomafix <fomafix@googlemail.com>
Fri, 30 Jun 2017 10:20:19 +0000 (12:20 +0200)
committerFomafix <fomafix@googlemail.com>
Tue, 25 Jul 2017 20:12:54 +0000 (22:12 +0200)
The tests are transfered from mediawiki.util.test.js.

Change-Id: I3fccfab3a2cdf5ad115fc426b3d45ce905e2e609

tests/phpunit/includes/SanitizerTest.php

index abcf1d4..6d093b0 100644 (file)
@@ -343,6 +343,41 @@ class SanitizerTest extends MediaWikiTestCase {
                ];
        }
 
+       /**
+        * Test Sanitizer::escapeId
+        *
+        * @dataProvider provideEscapeId
+        * @covers Sanitizer::escapeId
+        */
+       public function testEscapeId( $input, $output ) {
+               $this->assertEquals(
+                       $output,
+                       Sanitizer::escapeId( $input, [ 'noninitial', 'legacy' ] )
+               );
+       }
+
+       public static function provideEscapeId() {
+               return [
+                       [ '+', '.2B' ],
+                       [ '&', '.26' ],
+                       [ '=', '.3D' ],
+                       [ ':', ':' ],
+                       [ ';', '.3B' ],
+                       [ '@', '.40' ],
+                       [ '$', '.24' ],
+                       [ '-_.', '-_.' ],
+                       [ '!', '.21' ],
+                       [ '*', '.2A' ],
+                       [ '/', '.2F' ],
+                       [ '[]', '.5B.5D' ],
+                       [ '<>', '.3C.3E' ],
+                       [ '\'', '.27' ],
+                       [ 'ยง', '.C2.A7' ],
+                       [ 'Test:A & B/Here', 'Test:A_.26_B.2FHere' ],
+                       [ 'A&B&amp;C&amp;amp;D&amp;amp;amp;E', 'A.26B.26C.26amp.3BD.26amp.3Bamp.3BE' ],
+               ];
+       }
+
        /**
         * Test escapeIdReferenceList for consistency with escapeId
         *