mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-27 23:50:30 +00:00
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:
parent
04e61303c2
commit
4da5567bd9
|
@ -328,7 +328,7 @@ class SkinMinerva extends SkinTemplate implements ICustomizableSkin {
|
||||||
*/
|
*/
|
||||||
public function getUserPageHelper() {
|
public function getUserPageHelper() {
|
||||||
if ( $this->userPageHelper === null ) {
|
if ( $this->userPageHelper === null ) {
|
||||||
$this->userPageHelper = new SkinUserPageHelper( $this->getContext() );
|
$this->userPageHelper = new SkinUserPageHelper( $this->getContext()->getTitle() );
|
||||||
}
|
}
|
||||||
return $this->userPageHelper;
|
return $this->userPageHelper;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
namespace MediaWiki\Minerva;
|
namespace MediaWiki\Minerva;
|
||||||
|
|
||||||
use IContextSource;
|
|
||||||
use Title;
|
use Title;
|
||||||
use User;
|
use User;
|
||||||
|
|
||||||
|
@ -40,11 +39,10 @@ class SkinUserPageHelper {
|
||||||
private $pageUser;
|
private $pageUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SkinMinervaUserPageHelper constructor.
|
* @param Title $title
|
||||||
* @param IContextSource $context
|
|
||||||
*/
|
*/
|
||||||
public function __construct( IContextSource $context ) {
|
public function __construct( Title $title ) {
|
||||||
$this->title = $context->getTitle();
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace Tests\MediaWiki\Minerva;
|
||||||
use MediaWiki\Minerva\SkinUserPageHelper;
|
use MediaWiki\Minerva\SkinUserPageHelper;
|
||||||
use MediaWikiTestCase;
|
use MediaWikiTestCase;
|
||||||
use Title;
|
use Title;
|
||||||
use IContextSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group MinervaNeue
|
* @group MinervaNeue
|
||||||
|
@ -13,25 +12,15 @@ use IContextSource;
|
||||||
*/
|
*/
|
||||||
class SkinUserPageHelperTest extends MediaWikiTestCase {
|
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 ::isUserPage
|
||||||
* @covers ::fetchData
|
* @covers ::fetchData
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
*/
|
*/
|
||||||
public function testTitleNotInUserNamespace() {
|
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() );
|
$this->assertEquals( false, $helper->isUserPage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +29,9 @@ class SkinUserPageHelperTest extends MediaWikiTestCase {
|
||||||
* @covers ::fetchData
|
* @covers ::fetchData
|
||||||
*/
|
*/
|
||||||
public function testTitleisASubpage() {
|
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() );
|
$this->assertEquals( false, $helper->isUserPage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +54,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase {
|
||||||
->method( 'getText' )
|
->method( 'getText' )
|
||||||
->willReturn( 'Test' );
|
->willReturn( 'Test' );
|
||||||
|
|
||||||
$helper = new SkinUserPageHelper( $this->getContextMock( $titleMock ) );
|
$helper = new SkinUserPageHelper( $titleMock );
|
||||||
$helper->isUserPage();
|
$helper->isUserPage();
|
||||||
$helper->isUserPage();
|
$helper->isUserPage();
|
||||||
$helper->getPageUser();
|
$helper->getPageUser();
|
||||||
|
@ -81,7 +70,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase {
|
||||||
$testUser = $this->getTestUser()->getUser();
|
$testUser = $this->getTestUser()->getUser();
|
||||||
$title = $testUser->getUserPage();
|
$title = $testUser->getUserPage();
|
||||||
|
|
||||||
$helper = new SkinUserPageHelper( $this->getContextMock( $title ) );
|
$helper = new SkinUserPageHelper( $title );
|
||||||
$this->assertEquals( true, $helper->isUserPage() );
|
$this->assertEquals( true, $helper->isUserPage() );
|
||||||
$this->assertEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
$this->assertEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
||||||
}
|
}
|
||||||
|
@ -98,7 +87,7 @@ class SkinUserPageHelperTest extends MediaWikiTestCase {
|
||||||
$secondTestUser = $this->getTestSysop()->getUser();
|
$secondTestUser = $this->getTestSysop()->getUser();
|
||||||
$secondTestUserTitle = $secondTestUser->getUserPage();
|
$secondTestUserTitle = $secondTestUser->getUserPage();
|
||||||
|
|
||||||
$helper = new SkinUserPageHelper( $this->getContextMock( $secondTestUserTitle ) );
|
$helper = new SkinUserPageHelper( $secondTestUserTitle );
|
||||||
$this->assertEquals( true, $helper->isUserPage() );
|
$this->assertEquals( true, $helper->isUserPage() );
|
||||||
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
||||||
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
|
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
|
||||||
|
|
Loading…
Reference in a new issue