mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-01 01:06:31 +00:00
047618c24d
In some edge cases the RequestContext::getTitle() can return null instead of Title object. Similar situations already happened in the past (see T179833). The RequestContext::getTitle() documentation says it can return null, therefore code should be resilient and support such situations, even if there are not common. Bug: T221792 Change-Id: I842f8c49f20e511fda3b081e59a06586810bc748
146 lines
3.6 KiB
PHP
146 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\MediaWiki\Minerva;
|
|
|
|
use MediaWiki\Minerva\SkinUserPageHelper;
|
|
use MediaWikiTestCase;
|
|
use Title;
|
|
|
|
/**
|
|
* @group MinervaNeue
|
|
* @coversDefaultClass \MediaWiki\Minerva\SkinUserPageHelper
|
|
*/
|
|
class SkinUserPageHelperTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers ::isUserPage
|
|
* @covers ::fetchData
|
|
* @covers ::__construct
|
|
*/
|
|
public function testTitleNotInUserNamespace() {
|
|
$title = Title::newFromText( 'Test Page' );
|
|
|
|
$helper = new SkinUserPageHelper( $title );
|
|
$this->assertEquals( false, $helper->isUserPage() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::isUserPage
|
|
* @covers ::fetchData
|
|
* @covers ::__construct
|
|
*/
|
|
public function testTitleIsNull() {
|
|
$title = null;
|
|
|
|
$helper = new SkinUserPageHelper( $title );
|
|
$this->assertEquals( null, $helper->getPageUser() );
|
|
$this->assertEquals( false, $helper->isUserPage() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::isUserPage
|
|
* @covers ::fetchData
|
|
*/
|
|
public function testTitleisASubpage() {
|
|
$title = Title::newFromText( 'User:TestUser/subpage' );
|
|
|
|
$helper = new SkinUserPageHelper( $title );
|
|
$this->assertEquals( false, $helper->isUserPage() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::isUserPage
|
|
* @covers ::fetchData
|
|
* @covers ::buildPageUserObject
|
|
*/
|
|
public function testTitleisAnIP() {
|
|
$title = Title::newFromText( 'User:127.0.0.1' );
|
|
|
|
$helper = new SkinUserPageHelper( $title );
|
|
$this->assertEquals( true, $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->assertEquals( false, $helper->isUserPage() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::isUserPage
|
|
* @covers ::fetchData
|
|
* @covers ::buildPageUserObject
|
|
*/
|
|
public function testTitleIsFakeUserPage() {
|
|
$title = Title::newFromText( 'User:Fake user' );
|
|
|
|
$helper = new SkinUserPageHelper( $title );
|
|
$this->assertEquals( false, $helper->isUserPage() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::fetchData
|
|
*/
|
|
public function testTitleProcessingIsCached() {
|
|
$titleMock = $this->getMockBuilder( Title::class )
|
|
->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->assertEquals( true, $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->assertEquals( true, $helper->isUserPage() );
|
|
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
|
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
|
|
}
|
|
|
|
}
|