Merge "Remove group validator from UnitTestCase"
[lhc/web/wiklou.git] / tests / phpunit / includes / OutputPageTest.php
index 32ce08c..243a90d 100644 (file)
@@ -298,33 +298,6 @@ class OutputPageTest extends MediaWikiTestCase {
                );
        }
 
-       /**
-        * Test that addScriptFile() throws due to deprecation.
-        *
-        * @covers OutputPage::addScriptFile
-        */
-       public function testAddDeprecatedScriptFileWarning() {
-               $this->setExpectedException( PHPUnit_Framework_Error_Deprecated::class,
-                       'Use of OutputPage::addScriptFile was deprecated in MediaWiki 1.24.' );
-
-               $op = $this->newInstance();
-               $op->addScriptFile( 'ignored-script.js' );
-       }
-
-       /**
-        * Test the actual behavior of the method (in the case where it doesn't throw, e.g., in
-        * production).
-        *
-        * @covers OutputPage::addScriptFile
-        */
-       public function testAddDeprecatedScriptFileNoOp() {
-               $this->hideDeprecated( 'OutputPage::addScriptFile' );
-               $op = $this->newInstance();
-               $op->addScriptFile( 'ignored-script.js' );
-
-               $this->assertNotContains( 'ignored-script.js', '' . $op->getBottomScripts() );
-       }
-
        /**
         * @covers OutputPage::addInlineScript
         */
@@ -2246,14 +2219,12 @@ class OutputPageTest extends MediaWikiTestCase {
         *
         * @covers OutputPage::addVaryHeader
         * @covers OutputPage::getVaryHeader
-        * @covers OutputPage::getKeyHeader
         *
         * @param array[] $calls For each array, call addVaryHeader() with those arguments
         * @param string[] $cookies Array of cookie names to vary on
         * @param string $vary Text of expected Vary header (including the 'Vary: ')
-        * @param string $key Text of expected Key header (including the 'Key: ')
         */
-       public function testVaryHeaders( array $calls, array $cookies, $vary, $key ) {
+       public function testVaryHeaders( array $calls, array $cookies, $vary ) {
                // Get rid of default Vary fields
                $op = $this->getMockBuilder( OutputPage::class )
                        ->setConstructorArgs( [ new RequestContext() ] )
@@ -2264,22 +2235,19 @@ class OutputPageTest extends MediaWikiTestCase {
                        ->will( $this->returnValue( $cookies ) );
                TestingAccessWrapper::newFromObject( $op )->mVaryHeader = [];
 
-               $this->hideDeprecated( '$wgUseKeyHeader' );
+               $this->hideDeprecated( 'addVaryHeader $option is ignored' );
                foreach ( $calls as $call ) {
                        $op->addVaryHeader( ...$call );
                }
                $this->assertEquals( $vary, $op->getVaryHeader(), 'Vary:' );
-               $this->assertEquals( $key, $op->getKeyHeader(), 'Key:' );
        }
 
        public function provideVaryHeaders() {
-               // note: getKeyHeader() automatically adds Vary: Cookie
                return [
                        'No header' => [
                                [],
                                [],
                                'Vary: ',
-                               'Key: Cookie',
                        ],
                        'Single header' => [
                                [
@@ -2287,7 +2255,6 @@ class OutputPageTest extends MediaWikiTestCase {
                                ],
                                [],
                                'Vary: Cookie',
-                               'Key: Cookie',
                        ],
                        'Non-unique headers' => [
                                [
@@ -2297,26 +2264,26 @@ class OutputPageTest extends MediaWikiTestCase {
                                ],
                                [],
                                'Vary: Cookie, Accept-Language',
-                               'Key: Cookie,Accept-Language',
                        ],
                        'Two headers with single options' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=phpsessid' ] ],
                                        [ 'Accept-Language', [ 'substr=en' ] ],
                                ],
                                [],
                                'Vary: Cookie, Accept-Language',
-                               'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
                        ],
                        'One header with multiple options' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=phpsessid', 'param=userId' ] ],
                                ],
                                [],
                                'Vary: Cookie',
-                               'Key: Cookie;param=phpsessid;param=userId',
                        ],
                        'Duplicate option' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=phpsessid' ] ],
                                        [ 'Cookie', [ 'param=phpsessid' ] ],
@@ -2324,30 +2291,28 @@ class OutputPageTest extends MediaWikiTestCase {
                                ],
                                [],
                                'Vary: Cookie, Accept-Language',
-                               'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
                        ],
                        'Same header, different options' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=phpsessid' ] ],
                                        [ 'Cookie', [ 'param=userId' ] ],
                                ],
                                [],
                                'Vary: Cookie',
-                               'Key: Cookie;param=phpsessid;param=userId',
                        ],
                        'No header, vary cookies' => [
                                [],
                                [ 'cookie1', 'cookie2' ],
                                'Vary: Cookie',
-                               'Key: Cookie;param=cookie1;param=cookie2',
                        ],
                        'Cookie header with option plus vary cookies' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=cookie1' ] ],
                                ],
                                [ 'cookie2', 'cookie3' ],
                                'Vary: Cookie',
-                               'Key: Cookie;param=cookie1;param=cookie2;param=cookie3',
                        ],
                        'Non-cookie header plus vary cookies' => [
                                [
@@ -2355,16 +2320,15 @@ class OutputPageTest extends MediaWikiTestCase {
                                ],
                                [ 'cookie' ],
                                'Vary: Accept-Language, Cookie',
-                               'Key: Accept-Language,Cookie;param=cookie',
                        ],
                        'Cookie and non-cookie headers plus vary cookies' => [
+                               // Options are deprecated since 1.34
                                [
                                        [ 'Cookie', [ 'param=cookie1' ] ],
                                        [ 'Accept-Language' ],
                                ],
                                [ 'cookie2' ],
                                'Vary: Cookie, Accept-Language',
-                               'Key: Cookie;param=cookie1;param=cookie2,Accept-Language',
                        ],
                ];
        }
@@ -2417,10 +2381,9 @@ class OutputPageTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideAddAcceptLanguage
         * @covers OutputPage::addAcceptLanguage
-        * @covers OutputPage::getKeyHeader
         */
        public function testAddAcceptLanguage(
-               $code, array $variants, array $expected, array $options = []
+               $code, array $variants, $expected, array $options = []
        ) {
                $req = new FauxRequest( in_array( 'varianturl', $options ) ? [ 'variant' => 'x' ] : [] );
                $op = $this->newInstance( [], $req, in_array( 'notitle', $options ) ? 'notitle' : null );
@@ -2444,41 +2407,38 @@ class OutputPageTest extends MediaWikiTestCase {
 
                // This will run addAcceptLanguage()
                $op->sendCacheControl();
-
-               $this->hideDeprecated( '$wgUseKeyHeader' );
-               $keyHeader = $op->getKeyHeader();
-
-               if ( !$expected ) {
-                       $this->assertFalse( strpos( 'Accept-Language', $keyHeader ) );
-                       return;
-               }
-
-               $keyHeader = explode( ' ', $keyHeader, 2 )[1];
-               $keyHeader = explode( ',', $keyHeader );
-
-               $acceptLanguage = null;
-               foreach ( $keyHeader as $item ) {
-                       if ( strpos( $item, 'Accept-Language;' ) === 0 ) {
-                               $acceptLanguage = $item;
-                               break;
-                       }
-               }
-
-               $expectedString = 'Accept-Language;substr=' . implode( ';substr=', $expected );
-               $this->assertSame( $expectedString, $acceptLanguage );
+               $this->assertSame( "Vary: $expected", $op->getVaryHeader() );
        }
 
        public function provideAddAcceptLanguage() {
                return [
-                       'No variants' => [ 'en', [ 'en' ], [] ],
-                       'One simple variant' => [ 'en', [ 'en', 'en-x-piglatin' ], [ 'en-x-piglatin' ] ],
+                       'No variants' => [
+                               'en',
+                               [ 'en' ],
+                               'Accept-Encoding, Cookie',
+                       ],
+                       'One simple variant' => [
+                               'en',
+                               [ 'en', 'en-x-piglatin' ],
+                               'Accept-Encoding, Cookie, Accept-Language',
+                       ],
                        'Multiple variants with BCP47 alternatives' => [
                                'zh',
                                [ 'zh', 'zh-hans', 'zh-cn', 'zh-tw' ],
-                               [ 'zh-hans', 'zh-Hans', 'zh-cn', 'zh-Hans-CN', 'zh-tw', 'zh-Hant-TW' ],
+                               'Accept-Encoding, Cookie, Accept-Language',
+                       ],
+                       'No title' => [
+                               'en',
+                               [ 'en', 'en-x-piglatin' ],
+                               'Accept-Encoding, Cookie',
+                               [ 'notitle' ]
+                       ],
+                       'Variant in URL' => [
+                               'en',
+                               [ 'en', 'en-x-piglatin' ],
+                               'Accept-Encoding, Cookie',
+                               [ 'varianturl' ]
                        ],
-                       'No title' => [ 'en', [ 'en', 'en-x-piglatin' ], [], [ 'notitle' ] ],
-                       'Variant in URL' => [ 'en', [ 'en', 'en-x-piglatin' ], [], [ 'varianturl' ] ],
                ];
        }