LocalisationCache: try harder to use LCStoreCDB
[lhc/web/wiklou.git] / tests / phpunit / includes / OutputPageTest.php
index f0d905e..5f21e07 100644 (file)
@@ -137,6 +137,7 @@ class OutputPageTest extends MediaWikiTestCase {
        }
 
        public static function provideMakeResourceLoaderLink() {
+               // @codingStandardsIgnoreStart Generic.Files.LineLength
                return array(
                        // Load module script only
                        array(
@@ -193,6 +194,7 @@ class OutputPageTest extends MediaWikiTestCase {
                                        . "\n} );</script>"
                        ),
                );
+               // @codingStandardsIgnoreEnd
        }
 
        /**
@@ -264,9 +266,9 @@ class OutputPageTest extends MediaWikiTestCase {
         * @dataProvider provideVaryHeaders
         * @covers OutputPage::addVaryHeader
         * @covers OutputPage::getVaryHeader
-        * @covers OutputPage::getXVO
+        * @covers OutputPage::getKeyHeader
         */
-       public function testVaryHeaders( $calls, $vary, $xvo ) {
+       public function testVaryHeaders( $calls, $vary, $key ) {
                // get rid of default Vary fields
                $outputPage = $this->getMockBuilder( 'OutputPage' )
                        ->setConstructorArgs( array( new RequestContext() ) )
@@ -281,18 +283,18 @@ class OutputPageTest extends MediaWikiTestCase {
                        call_user_func_array( array( $outputPage, 'addVaryHeader' ), $call );
                }
                $this->assertEquals( $vary, $outputPage->getVaryHeader(), 'Vary:' );
-               $this->assertEquals( $xvo, $outputPage->getXVO(), 'X-Vary-Options:' );
+               $this->assertEquals( $key, $outputPage->getKeyHeader(), 'Key:' );
        }
 
        public function provideVaryHeaders() {
-               // note: getXVO() automatically adds Vary: Cookie
+               // note: getKeyHeader() automatically adds Vary: Cookie
                return array(
                        array( // single header
                                array(
                                        array( 'Cookie' ),
                                ),
                                'Vary: Cookie',
-                               'X-Vary-Options: Cookie',
+                               'Key: Cookie',
                        ),
                        array( // non-unique headers
                                array(
@@ -301,44 +303,63 @@ class OutputPageTest extends MediaWikiTestCase {
                                        array( 'Cookie' ),
                                ),
                                'Vary: Cookie, Accept-Language',
-                               'X-Vary-Options: Cookie,Accept-Language',
+                               'Key: Cookie,Accept-Language',
                        ),
                        array( // two headers with single options
                                array(
-                                       array( 'Cookie', array( 'string-contains=phpsessid' ) ),
-                                       array( 'Accept-Language', array( 'string-contains=en' ) ),
+                                       array( 'Cookie', array( 'param=phpsessid' ) ),
+                                       array( 'Accept-Language', array( 'substr=en' ) ),
                                ),
                                'Vary: Cookie, Accept-Language',
-                               'X-Vary-Options: Cookie;string-contains=phpsessid,Accept-Language;string-contains=en',
+                               'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
                        ),
                        array( // one header with multiple options
                                array(
-                                       array( 'Cookie', array( 'string-contains=phpsessid', 'string-contains=userId' ) ),
+                                       array( 'Cookie', array( 'param=phpsessid', 'param=userId' ) ),
                                ),
                                'Vary: Cookie',
-                               'X-Vary-Options: Cookie;string-contains=phpsessid;string-contains=userId',
+                               'Key: Cookie;param=phpsessid;param=userId',
                        ),
                        array( // Duplicate option
                                array(
-                                       array( 'Cookie', array( 'string-contains=phpsessid' ) ),
-                                       array( 'Cookie', array( 'string-contains=phpsessid' ) ),
-                                       array( 'Accept-Language', array( 'string-contains=en', 'string-contains=en' ) ),
-
-
+                                       array( 'Cookie', array( 'param=phpsessid' ) ),
+                                       array( 'Cookie', array( 'param=phpsessid' ) ),
+                                       array( 'Accept-Language', array( 'substr=en', 'substr=en' ) ),
                                ),
                                'Vary: Cookie, Accept-Language',
-                               'X-Vary-Options: Cookie;string-contains=phpsessid,Accept-Language;string-contains=en',
+                               'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
                        ),
                        array( // Same header, different options
                                array(
-                                       array( 'Cookie', array( 'string-contains=phpsessid' ) ),
-                                       array( 'Cookie', array( 'string-contains=userId' ) ),
+                                       array( 'Cookie', array( 'param=phpsessid' ) ),
+                                       array( 'Cookie', array( 'param=userId' ) ),
                                ),
                                'Vary: Cookie',
-                               'X-Vary-Options: Cookie;string-contains=phpsessid;string-contains=userId',
+                               'Key: Cookie;param=phpsessid;param=userId',
                        ),
                );
        }
+
+       /**
+        * @covers OutputPage::haveCacheVaryCookies
+        */
+       function testHaveCacheVaryCookies() {
+               $request = new FauxRequest();
+               $context = new RequestContext();
+               $context->setRequest( $request );
+               $outputPage = new OutputPage( $context );
+
+               // No cookies are set.
+               $this->assertFalse( $outputPage->haveCacheVaryCookies() );
+
+               // 'Token' is present but empty, so it shouldn't count.
+               $request->setCookie( 'Token', '' );
+               $this->assertFalse( $outputPage->haveCacheVaryCookies() );
+
+               // 'Token' present and nonempty.
+               $request->setCookie( 'Token', '123' );
+               $this->assertTrue( $outputPage->haveCacheVaryCookies() );
+       }
 }
 
 /**
@@ -359,6 +380,7 @@ class NullMessageBlobStore extends MessageBlobStore {
 
        public function updateMessage( $key ) {
        }
+
        public function clear() {
        }
 }