6 class RequestContextTest
extends MediaWikiTestCase
{
9 * Test the relationship between title and wikipage in RequestContext
10 * @covers RequestContext::getWikiPage
11 * @covers RequestContext::getTitle
13 public function testWikiPageTitle() {
14 $context = new RequestContext();
16 $curTitle = Title
::newFromText( "A" );
17 $context->setTitle( $curTitle );
18 $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
19 "When a title is first set WikiPage should be created on-demand for that title." );
21 $curTitle = Title
::newFromText( "B" );
22 $context->setWikiPage( WikiPage
::factory( $curTitle ) );
23 $this->assertTrue( $curTitle->equals( $context->getTitle() ),
24 "Title must be updated when a new WikiPage is provided." );
26 $curTitle = Title
::newFromText( "C" );
27 $context->setTitle( $curTitle );
29 $curTitle->equals( $context->getWikiPage()->getTitle() ),
30 "When a title is updated the WikiPage should be purged "
31 . "and recreated on-demand with the new title."
36 * @covers RequestContext::importScopedSession
38 public function testImportScopedSession() {
39 $context = RequestContext
::getMain();
41 $oInfo = $context->exportSession();
42 $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
43 $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
45 $user = User
::newFromName( 'UnitTestContextUser' );
46 $user->addToDatabase();
49 'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
50 'userId' => $user->getId(),
53 'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0'
56 $sc = RequestContext
::importScopedSession( $sinfo ); // load new context
58 $info = $context->exportSession();
59 $this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
60 $this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
61 $this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
62 $this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
65 $context->getRequest()->getIP(),
66 "Correct context IP address."
70 $context->getRequest()->getAllHeaders(),
71 "Correct context headers."
73 $this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
74 $this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
75 $this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
77 'UnitTestContextUser',
78 $context->getUser()->getName(),
79 "Correct context user name."
82 unset( $sc ); // restore previous context
84 $info = $context->exportSession();
85 $this->assertEquals( $oInfo['ip'], $info['ip'], "Correct initial IP address." );
86 $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct initial headers." );
87 $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct initial session ID." );
88 $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct initial user ID." );