mediawiki-skins-MinervaNeue/tests/phpunit/skins/SkinUserPageHelperTest.php
Jdlrobson 74838b2fa2 Revert "ServiceWiring: Avoid usage of deprecated Title::getSubjectPage()"
This reverts commit ae8e3ad58b.

Reason for revert: This led to T260155 as the internal class uses
isSubPage which is not available on LinkTarget

Bug: T260155
Change-Id: I783f41e70cf1cf3b91737bce9cbf9ac729a778df
2020-08-11 15:50:44 +00:00

147 lines
3.5 KiB
PHP

<?php
namespace Tests\MediaWiki\Minerva;
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
use MediaWikiTestCase;
use Title;
/**
* @group MinervaNeue
* @coversDefaultClass \MediaWiki\Minerva\Skins\SkinUserPageHelper
*/
class SkinUserPageHelperTest extends MediaWikiTestCase {
/**
* @covers ::isUserPage
* @covers ::fetchData
* @covers ::__construct
*/
public function testTitleNotInUserNamespace() {
$title = Title::newFromText( 'Test Page' );
$helper = new SkinUserPageHelper( $title );
$this->assertFalse( $helper->isUserPage() );
}
/**
* @covers ::isUserPage
* @covers ::fetchData
* @covers ::__construct
*/
public function testTitleIsNull() {
$title = null;
$helper = new SkinUserPageHelper( $title );
$this->assertNull( $helper->getPageUser() );
$this->assertFalse( $helper->isUserPage() );
}
/**
* @covers ::isUserPage
* @covers ::fetchData
*/
public function testTitleisASubpage() {
$title = Title::newFromText( 'User:TestUser/subpage' );
$helper = new SkinUserPageHelper( $title );
$this->assertFalse( $helper->isUserPage() );
}
/**
* @covers ::isUserPage
* @covers ::fetchData
* @covers ::buildPageUserObject
*/
public function testTitleisAnIP() {
$title = Title::newFromText( 'User:127.0.0.1' );
$helper = new SkinUserPageHelper( $title );
$this->assertTrue( $helper->isUserPage() );
}
/**
* @covers ::isUserPage
* @covers ::fetchData
* @covers ::buildPageUserObject
*/
public function testTitleIsIPRange() {
$title = Title::newFromText( 'User:127.0.0.1/24' );
$helper = new SkinUserPageHelper( $title );
$this->assertFalse( $helper->isUserPage() );
}
/**
* @covers ::isUserPage
* @covers ::fetchData
* @covers ::buildPageUserObject
*/
public function testTitleIsFakeUserPage() {
$title = Title::newFromText( 'User:Fake user' );
$helper = new SkinUserPageHelper( $title );
$this->assertFalse( $helper->isUserPage() );
}
/**
* @covers ::fetchData
*/
public function testTitleProcessingIsCached() {
$titleMock = $this->getMockBuilder( Title::class )
->disableOriginalConstructor()
->getMock();
$titleMock->expects( $this->once() )
->method( 'inNamespace' )
->with( NS_USER )
->willReturn( true );
$titleMock->expects( $this->once() )
->method( 'isSubpage' )
->willReturn( false );
$titleMock->expects( $this->once() )
->method( 'getText' )
->willReturn( 'Test' );
$helper = new SkinUserPageHelper( $titleMock );
$helper->isUserPage();
$helper->isUserPage();
$helper->getPageUser();
$helper->getPageUser();
}
/**
* @covers ::fetchData
* @covers ::getPageUser
* @covers ::isUserPage
*/
public function testGetPageUserWhenOnUserPage() {
$testUser = $this->getTestUser()->getUser();
$title = $testUser->getUserPage();
$helper = new SkinUserPageHelper( $title );
$this->assertTrue( $helper->isUserPage() );
$this->assertEquals( $testUser->getId(), $helper->getPageUser()->getId() );
}
/**
* @covers ::fetchData
* @covers ::getPageUser
* @covers ::isUserPage
*/
public function testGetPageUserWhenOnUserPageReturnsCorrectUser() {
$testUser = $this->getTestUser()->getUser();
$testUserTitle = $testUser->getUserPage();
$secondTestUser = $this->getTestSysop()->getUser();
$secondTestUserTitle = $secondTestUser->getUserPage();
$helper = new SkinUserPageHelper( $secondTestUserTitle );
$this->assertTrue( $helper->isUserPage() );
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
}
}