Merge "Add SPARQL client to core"
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / SwiftFileBackendTest.php
index 6acc943..35eca28 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
  * @group FileRepo
  * @group FileBackend
@@ -20,7 +22,7 @@ class SwiftFileBackendTest extends MediaWikiTestCase {
                $this->backend = TestingAccessWrapper::newFromObject(
                        new SwiftFileBackend( [
                                'name'             => 'local-swift-testing',
-                               'class'            => 'SwiftFileBackend',
+                               'class'            => SwiftFileBackend::class,
                                'wikiId'           => 'unit-testing',
                                'lockManager'      => LockManagerGroup::singleton()->get( 'fsLockManager' ),
                                'swiftAuthUrl'     => 'http://127.0.0.1:8080/auth', // unused
@@ -31,6 +33,68 @@ class SwiftFileBackendTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @dataProvider provider_testSanitizeHdrsStrict
+        */
+       public function testSanitizeHdrsStrict( $raw, $sanitized ) {
+               $hdrs = $this->backend->sanitizeHdrsStrict( [ 'headers' => $raw ] );
+
+               $this->assertEquals( $hdrs, $sanitized, 'sanitizeHdrsStrict() has expected result' );
+       }
+
+       public static function provider_testSanitizeHdrsStrict() {
+               return [
+                       [
+                               [
+                                       'content-length' => 345,
+                                       'content-type'   => 'image+bitmap/jpeg',
+                                       'content-disposition' => 'inline',
+                                       'content-duration' => 35.6363,
+                                       'content-Custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ],
+                               [
+                                       'content-disposition' => 'inline',
+                                       'content-duration' => 35.6363,
+                                       'content-custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ]
+                       ],
+                       [
+                               [
+                                       'content-length' => 345,
+                                       'content-type'   => 'image+bitmap/jpeg',
+                                       'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
+                                       'content-duration' => 35.6363,
+                                       'content-custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ],
+                               [
+                                       'content-disposition' => 'inline;filename=xxx',
+                                       'content-duration' => 35.6363,
+                                       'content-custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ]
+                       ],
+                       [
+                               [
+                                       'content-length' => 345,
+                                       'content-type'   => 'image+bitmap/jpeg',
+                                       'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
+                                       'content-duration' => 35.6363,
+                                       'content-custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ],
+                               [
+                                       'content-disposition' => '',
+                                       'content-duration' => 35.6363,
+                                       'content-custom' => 'hello',
+                                       'x-content-custom' => 'hello'
+                               ]
+                       ]
+               ];
+       }
+
        /**
         * @dataProvider provider_testSanitizeHdrs
         */
@@ -52,6 +116,7 @@ class SwiftFileBackendTest extends MediaWikiTestCase {
                                        'x-content-custom' => 'hello'
                                ],
                                [
+                                       'content-type'   => 'image+bitmap/jpeg',
                                        'content-disposition' => 'inline',
                                        'content-duration' => 35.6363,
                                        'content-custom' => 'hello',
@@ -68,6 +133,7 @@ class SwiftFileBackendTest extends MediaWikiTestCase {
                                        'x-content-custom' => 'hello'
                                ],
                                [
+                                       'content-type'   => 'image+bitmap/jpeg',
                                        'content-disposition' => 'inline;filename=xxx',
                                        'content-duration' => 35.6363,
                                        'content-custom' => 'hello',
@@ -84,6 +150,7 @@ class SwiftFileBackendTest extends MediaWikiTestCase {
                                        'x-content-custom' => 'hello'
                                ],
                                [
+                                       'content-type'   => 'image+bitmap/jpeg',
                                        'content-disposition' => '',
                                        'content-duration' => 35.6363,
                                        'content-custom' => 'hello',