MediaWiki
REL1_24
|
00001 <?php 00002 00007 class RequestContextTest extends MediaWikiTestCase { 00008 00014 public function testWikiPageTitle() { 00015 $context = new RequestContext(); 00016 00017 $curTitle = Title::newFromText( "A" ); 00018 $context->setTitle( $curTitle ); 00019 $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ), 00020 "When a title is first set WikiPage should be created on-demand for that title." ); 00021 00022 $curTitle = Title::newFromText( "B" ); 00023 $context->setWikiPage( WikiPage::factory( $curTitle ) ); 00024 $this->assertTrue( $curTitle->equals( $context->getTitle() ), 00025 "Title must be updated when a new WikiPage is provided." ); 00026 00027 $curTitle = Title::newFromText( "C" ); 00028 $context->setTitle( $curTitle ); 00029 $this->assertTrue( 00030 $curTitle->equals( $context->getWikiPage()->getTitle() ), 00031 "When a title is updated the WikiPage should be purged " 00032 . "and recreated on-demand with the new title." 00033 ); 00034 } 00035 00039 public function testImportScopedSession() { 00040 $context = RequestContext::getMain(); 00041 00042 $oInfo = $context->exportSession(); 00043 $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." ); 00044 $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." ); 00045 00046 $user = User::newFromName( 'UnitTestContextUser' ); 00047 $user->addToDatabase(); 00048 00049 $sinfo = array( 00050 'sessionId' => 'd612ee607c87e749ef14da4983a702cd', 00051 'userId' => $user->getId(), 00052 'ip' => '192.0.2.0', 00053 'headers' => array( 00054 'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0' 00055 ) 00056 ); 00057 // importScopedSession() sets these variables 00058 $this->setMwGlobals( array( 00059 'wgUser' => new User, 00060 'wgRequest' => new FauxRequest, 00061 ) ); 00062 $sc = RequestContext::importScopedSession( $sinfo ); // load new context 00063 00064 $info = $context->exportSession(); 00065 $this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." ); 00066 $this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." ); 00067 $this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." ); 00068 $this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." ); 00069 $this->assertEquals( 00070 $sinfo['ip'], 00071 $context->getRequest()->getIP(), 00072 "Correct context IP address." 00073 ); 00074 $this->assertEquals( 00075 $sinfo['headers'], 00076 $context->getRequest()->getAllHeaders(), 00077 "Correct context headers." 00078 ); 00079 $this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." ); 00080 $this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." ); 00081 $this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." ); 00082 $this->assertEquals( 00083 'UnitTestContextUser', 00084 $context->getUser()->getName(), 00085 "Correct context user name." 00086 ); 00087 00088 unset( $sc ); // restore previous context 00089 00090 $info = $context->exportSession(); 00091 $this->assertEquals( $oInfo['ip'], $info['ip'], "Correct initial IP address." ); 00092 $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct initial headers." ); 00093 $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct initial session ID." ); 00094 $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct initial user ID." ); 00095 } 00096 }