wiki.techinc.nl/tests/phpunit/includes/context/RequestContextTest.php

97 lines
3.4 KiB
PHP
Raw Normal View History

<?php
/**
* @group Database
* @group RequestContext
*/
class RequestContextTest extends MediaWikiTestCase {
/**
* Test the relationship between title and wikipage in RequestContext
* @covers RequestContext::getWikiPage
* @covers RequestContext::getTitle
*/
public function testWikiPageTitle() {
$context = new RequestContext();
$curTitle = Title::newFromText( "A" );
$context->setTitle( $curTitle );
$this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
"When a title is first set WikiPage should be created on-demand for that title." );
$curTitle = Title::newFromText( "B" );
$context->setWikiPage( WikiPage::factory( $curTitle ) );
$this->assertTrue( $curTitle->equals( $context->getTitle() ),
"Title must be updated when a new WikiPage is provided." );
$curTitle = Title::newFromText( "C" );
$context->setTitle( $curTitle );
$this->assertTrue(
$curTitle->equals( $context->getWikiPage()->getTitle() ),
"When a title is updated the WikiPage should be purged "
. "and recreated on-demand with the new title."
);
}
/**
* @covers RequestContext::importScopedSession
*/
public function testImportScopedSession() {
$context = RequestContext::getMain();
$oInfo = $context->exportSession();
$this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
$this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
$user = User::newFromName( 'UnitTestContextUser' );
$user->addToDatabase();
$sinfo = array(
'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
'userId' => $user->getId(),
'ip' => '192.0.2.0',
'headers' => array(
'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0'
)
);
// importScopedSession() sets these variables
$this->setMwGlobals( array(
'wgUser' => new User,
'wgRequest' => new FauxRequest,
) );
$sc = RequestContext::importScopedSession( $sinfo ); // load new context
$info = $context->exportSession();
$this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
$this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
$this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
$this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
$this->assertEquals(
$sinfo['ip'],
$context->getRequest()->getIP(),
"Correct context IP address."
);
$this->assertEquals(
$sinfo['headers'],
$context->getRequest()->getAllHeaders(),
"Correct context headers."
);
Remove SessionManager, temporarily The plan here is to take it out of 1.27.0-wmf.12 and put it back in 1.27.0-wmf.13. Since BotPasswords depends on SessionManager, that's getting temporarily removed too. This reverts the following commits: * 6acd424e0dbc322e8b9a141bd2625453c1b9b6f1 SessionManager: Notify AuthPlugin before calling hooks * 4d1ad32d8acbd443346253d2f6a95024c833295c Close a loophole in CookieSessionProvider * fcdd643a46d87b677f6cdcc3ba9440e1472d8df7 SessionManager: Don't save non-persisted sessions to backend storage * 058aec4c76129b7ee8541692a8a48f8046e15bb6 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php * b5c0c03bb708f8dad6e404969df8addc123984db SessionManager: Save user name to metadata even if the user doesn't exist locally * 13f2f09a193215aa7a061d10a1955e172d06fa0a SECURITY: Fix User::setToken() call on User::newSystemUser * 305bc75b27903237a9683ec1f329bcbec0ecd266 SessionManager: Don't generate user tokens when checking the tokens * 7c4bd85d2152fd9fa975ea0fb5ffb1a0b804f99b RequestContext::exportSession() should only export persisted session IDs * 296ccfd4a9a6ad3ae412db7e2408c923aaa61f64 SessionManager: Save 'persisted' flag in session metadata * 94ba53f67731b0553a6178841d9506e384f74496 Move CSRF token handling into MediaWiki\Session\Session * 46a565d6b00174e631d2022b47677e1a78e73897 Avoid false "added in both Session and $_SESSION" when value is null * c00d0b5d94c946b8883dd7062bf7160a199aa5c2 Log backtrace for "User::loadFromSession called before the end of Setup.php" * 4eeff5b559e2ae7b8fa1f45572968ba28573a421 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure' * 7491b52f700e220814a8190781fd794b4dd88a20 Call session_cache_limiter() before starting a session * 2c34aeea72471f9a598e67bdbf34bc5f9fb3f0c5 SessionManager: Abstract forceHTTPS cookie setting * 9aa53627a53aabec0273cecf45a86e77927ef406 Ignore auth cookies with value 'deleted' * 43f904b51a746d7f71ea2ab9951c5c98d269765b SessionManager: Kill getPersistedSessionId() * 50c52563528ba3d765c3762211f98d6f3c0e39fd SessionManager: Add SessionBackend::setProviderMetadata() * f640d403154bc0a2b4f6d399582797a9e3bc6fcb SessionManager: Notify AuthPlugin when auto-creating accounts * 70b05d1ac1e859bac2185b246e9b93ec9051e4d8 Add checks of $wgEnableBotPasswords in more places * bfed32eb78b6c720b16bc7ed60153fd2fe257a9e Do not raise a PHP warning when session write fails * 722a7331ad8d98228511f8da38adc7a3c64dd617 Only check LoggedOut timestamp on the user loaded from session * 4f5057b84b36eccd16627a6b29831dfdb4483b02 SessionManager: Change behavior of getSessionById() * 66e82e614e157e39b03d813e71ddf23f53cf640b Fix typo in [[MediaWiki:Botpasswords-editexisting/en]] * f9fd9516d922d36291037baca7205a2b0ac9f15f Add "bot passwords" * d7716f1df0b692902571bf415a0984071e3e9a60 Add missing argument for wfDebugLog * a73c5b7395a07d490f7052fd3b2491ebd656b190 Add SessionManager Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 17:28:29 +00:00
$this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
$this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
$this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
$this->assertEquals(
'UnitTestContextUser',
$context->getUser()->getName(),
"Correct context user name."
);
unset( $sc ); // restore previous context
$info = $context->exportSession();
$this->assertEquals( $oInfo['ip'], $info['ip'], "Correct restored IP address." );
$this->assertEquals( $oInfo['headers'], $info['headers'], "Correct restored headers." );
$this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct restored session ID." );
$this->assertEquals( $oInfo['userId'], $info['userId'], "Correct restored user ID." );
}
}