From 4da5567bd9ac140301d83bb9f8019d76ca2ebf13 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 15 Apr 2018 16:27:21 -0700 Subject: [PATCH] Simplify SkinUserPageHelper constructor Instead of requiring a full IContextSource object and only using the Title, only ask for the Title in the first place. Change-Id: I33034193140ca53919f29f847a03caf26250ce54 --- includes/skins/SkinMinerva.php | 2 +- includes/skins/SkinUserPageHelper.php | 8 +++--- .../phpunit/skins/SkinUserPageHelperTest.php | 25 ++++++------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php index 963a10375..b4b095da9 100644 --- a/includes/skins/SkinMinerva.php +++ b/includes/skins/SkinMinerva.php @@ -328,7 +328,7 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin { */ public function getUserPageHelper() { if ( $this->userPageHelper === null ) { - $this->userPageHelper = new SkinUserPageHelper( $this->getContext() ); + $this->userPageHelper = new SkinUserPageHelper( $this->getContext()->getTitle() ); } return $this->userPageHelper; } diff --git a/includes/skins/SkinUserPageHelper.php b/includes/skins/SkinUserPageHelper.php index 0ac2a57c6..98a709e2b 100644 --- a/includes/skins/SkinUserPageHelper.php +++ b/includes/skins/SkinUserPageHelper.php @@ -20,7 +20,6 @@ namespace MediaWiki\Minerva; -use IContextSource; use Title; use User; @@ -40,11 +39,10 @@ class SkinUserPageHelper { private $pageUser; /** - * SkinMinervaUserPageHelper constructor. - * @param IContextSource $context + * @param Title $title */ - public function __construct( IContextSource $context ) { - $this->title = $context->getTitle(); + public function __construct( Title $title ) { + $this->title = $title; } /** diff --git a/tests/phpunit/skins/SkinUserPageHelperTest.php b/tests/phpunit/skins/SkinUserPageHelperTest.php index dd00235a8..428ac96fc 100644 --- a/tests/phpunit/skins/SkinUserPageHelperTest.php +++ b/tests/phpunit/skins/SkinUserPageHelperTest.php @@ -5,7 +5,6 @@ namespace Tests\MediaWiki\Minerva; use MediaWiki\Minerva\SkinUserPageHelper; use MediaWikiTestCase; use Title; -use IContextSource; /** * @group MinervaNeue @@ -13,25 +12,15 @@ use IContextSource; */ class SkinUserPageHelperTest extends MediaWikiTestCase { - private function getContextMock( Title $title ) { - $context = $this->getMock( IContextSource::class ); - - $context->expects( $this->once() ) - ->method( 'getTitle' ) - ->willReturn( $title ); - - return $context; - } - /** * @covers ::isUserPage * @covers ::fetchData * @covers ::__construct */ public function testTitleNotInUserNamespace() { - $title = Title::newFromText( 'Test Page', NS_MAIN ); + $title = Title::newFromText( 'Test Page' ); - $helper = new SkinUserPageHelper( $this->getContextMock( $title ) ); + $helper = new SkinUserPageHelper( $title ); $this->assertEquals( false, $helper->isUserPage() ); } @@ -40,9 +29,9 @@ class SkinUserPageHelperTest extends MediaWikiTestCase { * @covers ::fetchData */ public function testTitleisASubpage() { - $title = Title::newFromText( 'User:TestUser/subpage', NS_USER ); + $title = Title::newFromText( 'User:TestUser/subpage' ); - $helper = new SkinUserPageHelper( $this->getContextMock( $title ) ); + $helper = new SkinUserPageHelper( $title ); $this->assertEquals( false, $helper->isUserPage() ); } @@ -65,7 +54,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase { ->method( 'getText' ) ->willReturn( 'Test' ); - $helper = new SkinUserPageHelper( $this->getContextMock( $titleMock ) ); + $helper = new SkinUserPageHelper( $titleMock ); $helper->isUserPage(); $helper->isUserPage(); $helper->getPageUser(); @@ -81,7 +70,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase { $testUser = $this->getTestUser()->getUser(); $title = $testUser->getUserPage(); - $helper = new SkinUserPageHelper( $this->getContextMock( $title ) ); + $helper = new SkinUserPageHelper( $title ); $this->assertEquals( true, $helper->isUserPage() ); $this->assertEquals( $testUser->getId(), $helper->getPageUser()->getId() ); } @@ -98,7 +87,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase { $secondTestUser = $this->getTestSysop()->getUser(); $secondTestUserTitle = $secondTestUser->getUserPage(); - $helper = new SkinUserPageHelper( $this->getContextMock( $secondTestUserTitle ) ); + $helper = new SkinUserPageHelper( $secondTestUserTitle ); $this->assertEquals( true, $helper->isUserPage() ); $this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() ); $this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );