2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
2017-07-14 23:56:16 +00:00
|
|
|
|
|
|
|
namespace Tests\MediaWiki\Minerva;
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
use MediaWiki\Minerva\SkinUserPageHelper;
|
2017-07-14 23:56:16 +00:00
|
|
|
use MediaWikiTestCase;
|
|
|
|
use Title;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2018-11-01 13:28:20 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\SkinUserPageHelper
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
class SkinUserPageHelperTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::__construct
|
|
|
|
*/
|
|
|
|
public function testTitleNotInUserNamespace() {
|
2018-04-15 23:27:21 +00:00
|
|
|
$title = Title::newFromText( 'Test Page' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-04-15 23:27:21 +00:00
|
|
|
$helper = new SkinUserPageHelper( $title );
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->assertEquals( false, $helper->isUserPage() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
*/
|
|
|
|
public function testTitleisASubpage() {
|
2018-04-15 23:27:21 +00:00
|
|
|
$title = Title::newFromText( 'User:TestUser/subpage' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-04-15 23:27:21 +00:00
|
|
|
$helper = new SkinUserPageHelper( $title );
|
2017-07-12 15:12:40 +00:00
|
|
|
$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' );
|
|
|
|
|
2018-04-15 23:27:21 +00:00
|
|
|
$helper = new SkinUserPageHelper( $titleMock );
|
2017-07-12 15:12:40 +00:00
|
|
|
$helper->isUserPage();
|
|
|
|
$helper->isUserPage();
|
|
|
|
$helper->getPageUser();
|
|
|
|
$helper->getPageUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::getPageUser
|
|
|
|
* @covers ::isUserPage
|
|
|
|
*/
|
|
|
|
public function testGetPageUserWhenOnUserPage() {
|
|
|
|
$testUser = $this->getTestUser()->getUser();
|
|
|
|
$title = $testUser->getUserPage();
|
|
|
|
|
2018-04-15 23:27:21 +00:00
|
|
|
$helper = new SkinUserPageHelper( $title );
|
2017-07-12 15:12:40 +00:00
|
|
|
$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();
|
|
|
|
|
2018-04-15 23:27:21 +00:00
|
|
|
$helper = new SkinUserPageHelper( $secondTestUserTitle );
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->assertEquals( true, $helper->isUserPage() );
|
|
|
|
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
|
|
|
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|