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