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