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
This commit is contained in:
Kunal Mehta 2018-04-15 16:27:21 -07:00
parent 04e61303c2
commit 4da5567bd9
3 changed files with 11 additions and 24 deletions

View file

@ -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;
}

View file

@ -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;
}
/**

View file

@ -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 );