MediaWiki  1.23.13
RequestContextTest.php
Go to the documentation of this file.
1 <?php
2 
7 
13  public function testWikiPageTitle() {
14  $context = new RequestContext();
15 
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." );
20 
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." );
25 
26  $curTitle = Title::newFromText( "C" );
27  $context->setTitle( $curTitle );
28  $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
29  "When a title is updated the WikiPage should be purged and recreated on-demand with the new title." );
30  }
31 
35  public function testImportScopedSession() {
36  $context = RequestContext::getMain();
37 
38  $oInfo = $context->exportSession();
39  $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
40  $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
41 
42  $user = User::newFromName( 'UnitTestContextUser' );
43  $user->addToDatabase();
44 
45  $sinfo = array(
46  'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
47  'userId' => $user->getId(),
48  'ip' => '192.0.2.0',
49  'headers' => array( 'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0' )
50  );
51  $sc = RequestContext::importScopedSession( $sinfo ); // load new context
52 
53  $info = $context->exportSession();
54  $this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
55  $this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
56  $this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
57  $this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
58  $this->assertEquals( $sinfo['ip'], $context->getRequest()->getIP(), "Correct context IP address." );
59  $this->assertEquals( $sinfo['headers'], $context->getRequest()->getAllHeaders(), "Correct context headers." );
60  $this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
61  $this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
62  $this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
63  $this->assertEquals( 'UnitTestContextUser', $context->getUser()->getName(), "Correct context user name." );
64 
65  unset( $sc ); // restore previous context
66 
67  $info = $context->exportSession();
68  $this->assertEquals( $oInfo['ip'], $info['ip'], "Correct initial IP address." );
69  $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct initial headers." );
70  $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct initial session ID." );
71  $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct initial user ID." );
72  }
73 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
RequestContextTest\testImportScopedSession
testImportScopedSession()
@covers RequestContext::importScopedSession
Definition: RequestContextTest.php:35
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:420
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
RequestContext\importScopedSession
static importScopedSession(array $params)
Import the resolved user IP, HTTP headers, user ID, and session ID.
Definition: RequestContext.php:461
RequestContextTest\testWikiPageTitle
testWikiPageTitle()
Test the relationship between title and wikipage in RequestContext @covers RequestContext::getWikiPag...
Definition: RequestContextTest.php:13
RequestContextTest
@group Database
Definition: RequestContextTest.php:6