"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/phpunit/includes/MediaWikiTest.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

MediaWikiTest.php  (mediawiki-1.31.1):MediaWikiTest.php  (mediawiki-1.32.0)
<?php <?php
class MediaWikiTest extends MediaWikiTestCase { class MediaWikiTest extends MediaWikiTestCase {
private $oldServer, $oldGet, $oldPost;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgServer' => 'http://example.org', 'wgServer' => 'http://example.org',
'wgScriptPath' => '/w', 'wgScriptPath' => '/w',
'wgScript' => '/w/index.php', 'wgScript' => '/w/index.php',
'wgArticlePath' => '/wiki/$1', 'wgArticlePath' => '/wiki/$1',
'wgActionPaths' => [], 'wgActionPaths' => [],
] ); ] );
// phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
$this->oldServer = $_SERVER;
$this->oldGet = $_GET;
$this->oldPost = $_POST;
}
protected function tearDown() {
parent::tearDown();
$_SERVER = $this->oldServer;
$_GET = $this->oldGet;
$_POST = $this->oldPost;
} }
public static function provideTryNormaliseRedirect() { public static function provideTryNormaliseRedirect() {
return [ return [
[ [
// View: Canonical // View: Canonical
'url' => 'http://example.org/wiki/Foo_Bar', 'url' => 'http://example.org/wiki/Foo_Bar',
'query' => [], 'query' => [],
'title' => 'Foo_Bar', 'title' => 'Foo_Bar',
'redirect' => false, 'redirect' => false,
skipping to change at line 116 skipping to change at line 130
'title' => 'Foo_Bar', 'title' => 'Foo_Bar',
'redirect' => false, 'redirect' => false,
], ],
[ [
// Edit: Index with action query // Edit: Index with action query
'url' => 'http://example.org/w/index.php?title=Fo o_Bar&action=edit', 'url' => 'http://example.org/w/index.php?title=Fo o_Bar&action=edit',
'query' => [ 'title' => 'Foo_Bar', 'action' => 'e dit' ], 'query' => [ 'title' => 'Foo_Bar', 'action' => 'e dit' ],
'title' => 'Foo_Bar', 'title' => 'Foo_Bar',
'redirect' => false, 'redirect' => false,
], ],
[
// Path with double slash prefix (T100782)
'url' => 'http://example.org//wiki/Double_slash',
'query' => [],
'title' => 'Double_slash',
'redirect' => false,
],
[
// View: Media namespace redirect (T203942)
'url' => 'http://example.org/w/index.php?title=Me
dia:Foo_Bar',
'query' => [ 'title' => 'Foo_Bar' ],
'title' => 'File:Foo_Bar',
'redirect' => 'http://example.org/wiki/File:Foo_B
ar',
],
]; ];
} }
/** /**
* @dataProvider provideTryNormaliseRedirect * @dataProvider provideTryNormaliseRedirect
* @covers MediaWiki::tryNormaliseRedirect * @covers MediaWiki::tryNormaliseRedirect
*/ */
public function testTryNormaliseRedirect( $url, $query, $title, $expected Redirect = false ) { public function testTryNormaliseRedirect( $url, $query, $title, $expected Redirect = false ) {
// Set SERVER because interpolateTitle() doesn't use getRequestUR L(), // Set SERVER because interpolateTitle() doesn't use getRequestUR L(),
// whereas tryNormaliseRedirect does(). // whereas tryNormaliseRedirect does(). Also, using WebRequest al
lows
// us to test some quirks in that class.
$_SERVER['REQUEST_URI'] = $url; $_SERVER['REQUEST_URI'] = $url;
$_POST = [];
$_GET = $query;
$req = new WebRequest;
$req = new FauxRequest( $query );
$req->setRequestURL( $url );
// This adds a virtual 'title' query parameter. Normally called f rom Setup.php // This adds a virtual 'title' query parameter. Normally called f rom Setup.php
$req->interpolateTitle(); $req->interpolateTitle();
$titleObj = Title::newFromText( $title ); $titleObj = Title::newFromText( $title );
// Set global context since some involved code paths don't yet ha ve context // Set global context since some involved code paths don't yet ha ve context
$context = RequestContext::getMain(); $context = RequestContext::getMain();
$context->setRequest( $req ); $context->setRequest( $req );
$context->setTitle( $titleObj ); $context->setTitle( $titleObj );
skipping to change at line 157 skipping to change at line 187
$expectedRedirect !== false, $expectedRedirect !== false,
$ret, $ret,
'Return true only when redirecting' 'Return true only when redirecting'
); );
$this->assertEquals( $this->assertEquals(
$expectedRedirect ?: '', $expectedRedirect ?: '',
$context->getOutput()->getRedirect() $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 fro
m
// 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()
);
}
} }
 End of changes. 7 change blocks. 
3 lines changed or deleted 89 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)