Replace Title::newFromText by Title::makeTitle

* Prefer Title::makeTitle in unit tests where the title is known,
  this avoids title parsing and can improve the test performance.
* Use Title::makeTitle for the user page like done in User::getUserPage

Change-Id: I3901a6ed208a5ff90b216d01d3c4962cdcb48db1
This commit is contained in:
Umherirrender 2022-03-10 22:39:37 +01:00
parent 1a2960a3c0
commit 4831549b14
4 changed files with 16 additions and 16 deletions

View file

@ -86,7 +86,7 @@ final class ProfileMenuEntry implements IProfileMenuEntry {
return [ [
'icon' => 'wikimedia-userAvatar-base20',
'text' => $this->customProfileLabel ?? $username,
'href' => $this->customProfileURL ?? Title::newFromText( $username, NS_USER )->getLocalURL(),
'href' => $this->customProfileURL ?? Title::makeTitle( NS_USER, $username )->getLocalURL(),
'class' => 'menu__item--user',
'data-event-name' => 'menu.' . (
$this->profileTrackingCode ?? self::DEFAULT_PROFILE_TRACKING_CODE )

View file

@ -108,7 +108,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testInvalidPageActionsArentAllowed() {
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ), [] );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ), [] );
$this->assertFalse( $perms->isAllowed( 'blah' ) );
$this->assertFalse( $perms->isAllowed( 'wah' ) );
@ -118,7 +118,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testValidPageActionsAreAllowed() {
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ) );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ) );
$this->assertTrue( $perms->isAllowed( IMinervaPagePermissions::TALK ) );
$this->assertTrue( $perms->isAllowed( IMinervaPagePermissions::WATCH ) );
}
@ -152,7 +152,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
$contentHandler->method( 'supportsDirectApiEditing' )
->willReturn( $supportsDirectApiEditing );
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ), null, [],
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ), null, [],
$contentHandler );
$this->assertEquals( $expected, $perms->isAllowed( IMinervaPagePermissions::CONTENT_EDIT ) );
@ -162,7 +162,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testPageActionsWhenOnUserPage() {
$perms = $this->buildPermissionsObject( Title::newFromText( 'User:Admin' ) );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_USER, 'Admin' ) );
$this->assertTrue( $perms->isAllowed( IMinervaPagePermissions::TALK ) );
}
@ -170,7 +170,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testPageActionsWhenOnAnonUserPage() {
$perms = $this->buildPermissionsObject( Title::newFromText( 'User:1.1.1.1' ) );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_USER, '1.1.1.1' ) );
$this->assertTrue( $perms->isAllowed( IMinervaPagePermissions::TALK ) );
}
@ -200,7 +200,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
*/
public function testGlobalHideLanguageLinksTakesPrecedence() {
$this->setMwGlobals( [ 'wgHideInterlanguageLinks' => true ] );
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ) );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ) );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) );
}
@ -246,7 +246,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testWatchIsAllowedOnlyWhenWatchlistPermissionsAreGranted() {
$title = Title::newFromText( 'test_watchstar_permissions' );
$title = Title::makeTitle( NS_MAIN, 'Test_watchstar_permissions' );
$userMock = $this->getMockBuilder( User::class )
->disableOriginalConstructor()
@ -289,7 +289,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testMoveAndDeleteAndProtectNotAllowedByDefault() {
$perms = $this->buildPermissionsObject( Title::newFromText( 'test' ), null );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ), null );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::MOVE ) );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::DELETE ) );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::PROTECT ) );

View file

@ -37,7 +37,7 @@ class SkinMinervaTest extends MediaWikiIntegrationTestCase {
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
$context = new RequestContext();
$context->setTitle( Title::newFromText( 'Test' ) );
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
$context->setOutput( $outputPage );
$skin = new SkinMinerva();
@ -65,7 +65,7 @@ class SkinMinervaTest extends MediaWikiIntegrationTestCase {
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
$context = new RequestContext();
$context->setTitle( Title::newFromText( 'Test' ) );
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
$context->setOutput( $outputPage );
$skin = new SkinMinerva();

View file

@ -18,7 +18,7 @@ class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
* @covers ::__construct
*/
public function testTitleNotInUserNamespace() {
$title = Title::newFromText( 'Test Page' );
$title = Title::makeTitle( NS_MAIN, 'Test_Page' );
$helper = new SkinUserPageHelper( $this->getServiceContainer()->getUserNameUtils(), $title );
$this->assertFalse( $helper->isUserPage() );
@ -42,7 +42,7 @@ class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
* @covers ::fetchData
*/
public function testTitleisASubpage() {
$title = Title::newFromText( 'User:TestUser/subpage' );
$title = Title::makeTitle( NS_USER, 'TestUser/subpage' );
$helper = new SkinUserPageHelper( $this->getServiceContainer()->getUserNameUtils(), $title );
$this->assertFalse( $helper->isUserPage() );
@ -54,7 +54,7 @@ class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
* @covers ::buildPageUserObject
*/
public function testTitleisAnIP() {
$title = Title::newFromText( 'User:127.0.0.1' );
$title = Title::makeTitle( NS_USER, '127.0.0.1' );
$helper = new SkinUserPageHelper( $this->getServiceContainer()->getUserNameUtils(), $title );
$this->assertTrue( $helper->isUserPage() );
@ -66,7 +66,7 @@ class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
* @covers ::buildPageUserObject
*/
public function testTitleIsIPRange() {
$title = Title::newFromText( 'User:127.0.0.1/24' );
$title = Title::makeTitle( NS_USER, '127.0.0.1/24' );
$helper = new SkinUserPageHelper( $this->getServiceContainer()->getUserNameUtils(), $title );
$this->assertFalse( $helper->isUserPage() );
@ -78,7 +78,7 @@ class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
* @covers ::buildPageUserObject
*/
public function testTitleIsFakeUserPage() {
$title = Title::newFromText( 'User:Fake user' );
$title = Title::makeTitle( NS_USER, 'Fake_user' );
$helper = new SkinUserPageHelper( $this->getServiceContainer()->getUserNameUtils(), $title );
$this->assertFalse( $helper->isUserPage() );