Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / RequestContextTest.php
blobf595d2dc649340ba372c171b476f6d389a1fe9b8
1 <?php
3 /**
4 * @group Database
5 */
6 class RequestContextTest extends MediaWikiTestCase {
8 /**
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 );
28 $this->assertTrue(
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."
35 /**
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();
48 $sinfo = array(
49 'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
50 'userId' => $user->getId(),
51 'ip' => '192.0.2.0',
52 'headers' => array(
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." );
63 $this->assertEquals(
64 $sinfo['ip'],
65 $context->getRequest()->getIP(),
66 "Correct context IP address."
68 $this->assertEquals(
69 $sinfo['headers'],
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." );
76 $this->assertEquals(
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." );