config: Add new ConfigRepository
[lhc/web/wiklou.git] / tests / phpunit / includes / MediaWikiTest.php
index df92012..7d7e637 100644 (file)
@@ -34,7 +34,7 @@ class MediaWikiTest extends MediaWikiTestCase {
                                'url' => 'http://example.org/w/index.php?title=Foo_Bar',
                                'query' => [ 'title' => 'Foo_Bar' ],
                                'title' => 'Foo_Bar',
-                               'redirect' => 'http://example.org/wiki/Foo_Bar',
+                               'redirect' => false,
                        ],
                        [
                                // View: Script path with implicit title from page id
@@ -76,21 +76,21 @@ class MediaWikiTest extends MediaWikiTestCase {
                                'url' => 'http://example.org/w/?title=Foo_Bar',
                                'query' => [ 'title' => 'Foo_Bar' ],
                                'title' => 'Foo_Bar',
-                               'redirect' => 'http://example.org/wiki/Foo_Bar',
+                               'redirect' => false,
                        ],
                        [
                                // View: Root path with escaped title
                                'url' => 'http://example.org/?title=Foo_Bar',
                                'query' => [ 'title' => 'Foo_Bar' ],
                                'title' => 'Foo_Bar',
-                               'redirect' => 'http://example.org/wiki/Foo_Bar',
+                               'redirect' => false,
                        ],
                        [
                                // View: Canonical with redundant query
                                'url' => 'http://example.org/wiki/Foo_Bar?action=view',
                                'query' => [ 'action' => 'view' ],
                                'title' => 'Foo_Bar',
-                               'redirect' => 'http://example.org/wiki/Foo_Bar',
+                               'redirect' => false,
                        ],
                        [
                                // Edit: Canonical view url with action query
@@ -104,7 +104,7 @@ class MediaWikiTest extends MediaWikiTestCase {
                                'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=view',
                                'query' => [ 'title' => 'Foo_Bar', 'action' => 'view' ],
                                'title' => 'Foo_Bar',
-                               'redirect' => 'http://example.org/wiki/Foo_Bar',
+                               'redirect' => false,
                        ],
                        [
                                // Edit: Index with action query
@@ -154,4 +154,53 @@ class MediaWikiTest extends MediaWikiTestCase {
                        $context->getOutput()->getRedirect()
                );
        }
+
+       /**
+        * Test a post-send job can not set cookies (T191537).
+        */
+       public function testPostSendJobDoesNotSetCookie() {
+               // Prevent updates from running
+               $this->setMwGlobals( 'wgCommandLineMode', false );
+
+               $response = new WebResponse;
+
+               // A job that attempts to set a cookie
+               $jobHasRun = false;
+               DeferredUpdates::addCallableUpdate( function () use ( $response, &$jobHasRun ) {
+                       $jobHasRun = true;
+                       $response->setCookie( 'JobCookie', 'yes' );
+                       $response->header( 'Foo: baz' );
+               } );
+
+               $hookWasRun = false;
+               $this->setTemporaryHook( 'WebResponseSetCookie', function () use ( &$hookWasRun ) {
+                       $hookWasRun = true;
+                       return true;
+               } );
+
+               $logger = new TestLogger();
+               $logger->setCollect( true );
+               $this->setLogger( 'cookie', $logger );
+               $this->setLogger( 'header', $logger );
+
+               $mw = new MediaWiki();
+               $mw->doPostOutputShutdown();
+               // restInPeace() might have been registered to a callback of
+               // register_postsend_function() and thus can not be triggered from
+               // PHPUnit.
+               if ( $jobHasRun === false ) {
+                       $mw->restInPeace();
+               }
+
+               $this->assertTrue( $jobHasRun, 'post-send job has run' );
+               $this->assertFalse( $hookWasRun,
+                       'post-send job must not trigger WebResponseSetCookie hook' );
+               $this->assertEquals(
+                       [
+                               [ 'info', 'ignored post-send cookie {cookie}' ],
+                               [ 'info', 'ignored post-send header {header}' ],
+                       ],
+                       $logger->getBuffer()
+               );
+       }
 }