Merge "HTML escape parameter 'text' of hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / CSSMinTest.php
index c711291..4c93789 100644 (file)
@@ -19,6 +19,30 @@ class CSSMinTest extends MediaWikiTestCase {
                ] );
        }
 
+       /**
+        * @dataProvider providesReferencedFiles
+        * @covers CSSMin::getLocalFileReferences
+        */
+       public function testGetLocalFileReferences( $input, $expected ) {
+               $output = CSSMin::getLocalFileReferences( $input, '/' );
+               $this->assertEquals(
+                       $expected,
+                       $output,
+                       'getLocalFileReferences() must find the local file properly'
+               );
+       }
+
+       public static function providesReferencedFiles() {
+               // input, array of expected local file names
+               return [
+                       [ 'url("//example.org")', [] ],
+                       [ 'url("https://example.org")', [] ],
+                       [ 'url("#default#")', [] ],
+                       [ 'url("WikiFont-Glyphs.svg#wikiglyph")', [ '/WikiFont-Glyphs.svg' ] ],
+                       [ 'url("#some-anchor")', [] ],
+               ];
+       }
+
        /**
         * @dataProvider provideSerializeStringValue
         * @covers CSSMin::serializeStringValue
@@ -61,9 +85,9 @@ class CSSMinTest extends MediaWikiTestCase {
         * @covers CSSMin::getMimeType
         */
        public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
-               $fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.'
-                       . $fileExtension;
-               $this->addTmpFiles( $fileName );
+               // Automatically removed when it falls out of scope (including if the test fails)
+               $file = TempFSFile::factory( 'PHPUnit_CSSMinTest_', $fileExtension, wfTempDir() );
+               $fileName = $file->getPath();
                file_put_contents( $fileName, $fileContents );
                $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
        }
@@ -292,6 +316,16 @@ class CSSMinTest extends MediaWikiTestCase {
                                [ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
                                'foo { behavior: url("#default#bar"); }',
                        ],
+                       [
+                               'Keeps anchors',
+                               [ 'url(#other)', false, '/', false ],
+                               'url("#other")'
+                       ],
+                       [
+                               'Keeps anchors after a path',
+                               [ 'url(images/file.svg#id)', false, '/', false ],
+                               'url("/images/file.svg#id")'
+                       ],
                ];
        }
 
@@ -633,7 +667,7 @@ class CSSMinTest extends MediaWikiTestCase {
        }
 
        /**
-        * Seperated because they are currently broken (T37492)
+        * Separated because they are currently broken (T37492)
         *
         * @group Broken
         * @dataProvider provideStringCases