diff options
-rw-r--r-- | includes/context/RequestContext.php | 8 | ||||
-rw-r--r-- | tests/phpunit/includes/RequestContextTest.php | 28 |
2 files changed, 36 insertions, 0 deletions
diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index cd2bf556f83c..e4de030c749d 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -93,6 +93,8 @@ class RequestContext implements IContextSource { */ public function setTitle( Title $t ) { $this->title = $t; + // Erase the WikiPage so a new one with the new title gets created. + $this->wikipage = null; } /** @@ -138,6 +140,12 @@ class RequestContext implements IContextSource { * @param $p WikiPage object */ public function setWikiPage( WikiPage $p ) { + $contextTitle = $this->getTitle(); + $pageTitle = $p->getTitle(); + if ( !$contextTitle || !$pageTitle->equals( $contextTitle ) ) { + $this->setTitle( $pageTitle ); + } + // Defer this to the end since setTitle sets it to null. $this->wikipage = $p; } diff --git a/tests/phpunit/includes/RequestContextTest.php b/tests/phpunit/includes/RequestContextTest.php new file mode 100644 index 000000000000..48cf6dc65092 --- /dev/null +++ b/tests/phpunit/includes/RequestContextTest.php @@ -0,0 +1,28 @@ +<?php + +class RequestContextTest extends MediaWikiTestCase { + + /** + * Test the relationship between title and wikipage in RequestContext + */ + public function testWikiPageTitle() { + $context = new RequestContext(); + + $curTitle = Title::newFromText( "A" ); + $context->setTitle( $curTitle ); + $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ), + "When a title is first set WikiPage should be created on-demand for that title." ); + + $curTitle = Title::newFromText( "B" ); + $context->setWikiPage( WikiPage::factory( $curTitle ) ); + $this->assertTrue( $curTitle->equals( $context->getTitle() ), + "Title must be updated when a new WikiPage is provided." ); + + $curTitle = Title::newFromText( "C" ); + $context->setTitle( $curTitle ); + $this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ), + "When a title is updated the WikiPage should be purged and recreated on-demand with the new title." ); + + } + +} |