2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
2017-07-14 23:56:16 +00:00
|
|
|
|
2022-05-03 18:11:54 +00:00
|
|
|
namespace MediaWiki\Minerva;
|
2017-07-14 23:56:16 +00:00
|
|
|
|
2020-05-01 01:16:53 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
|
2021-10-11 22:53:10 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2017-07-14 23:56:16 +00:00
|
|
|
use Title;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2020-05-01 01:16:53 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\Skins\SkinUserPageHelper
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-10-11 22:53:10 +00:00
|
|
|
class SkinUserPageHelperTest extends MediaWikiIntegrationTestCase {
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::__construct
|
|
|
|
*/
|
|
|
|
public function testTitleNotInUserNamespace() {
|
2022-03-10 21:39:37 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Test_Page' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertFalse( $helper->isUserPage() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 23:42:00 +00:00
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::__construct
|
|
|
|
*/
|
|
|
|
public function testTitleIsNull() {
|
|
|
|
$title = null;
|
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertNull( $helper->getPageUser() );
|
|
|
|
$this->assertFalse( $helper->isUserPage() );
|
2019-05-24 23:42:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
*/
|
|
|
|
public function testTitleisASubpage() {
|
2022-03-10 21:39:37 +00:00
|
|
|
$title = Title::makeTitle( NS_USER, 'TestUser/subpage' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertFalse( $helper->isUserPage() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 09:55:21 +00:00
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::buildPageUserObject
|
|
|
|
*/
|
|
|
|
public function testTitleisAnIP() {
|
2022-03-10 21:39:37 +00:00
|
|
|
$title = Title::makeTitle( NS_USER, '127.0.0.1' );
|
2019-05-23 09:55:21 +00:00
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertTrue( $helper->isUserPage() );
|
2019-05-23 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::buildPageUserObject
|
|
|
|
*/
|
|
|
|
public function testTitleIsIPRange() {
|
2022-03-10 21:39:37 +00:00
|
|
|
$title = Title::makeTitle( NS_USER, '127.0.0.1/24' );
|
2019-05-23 09:55:21 +00:00
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertFalse( $helper->isUserPage() );
|
2019-05-23 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isUserPage
|
|
|
|
* @covers ::fetchData
|
|
|
|
* @covers ::buildPageUserObject
|
|
|
|
*/
|
|
|
|
public function testTitleIsFakeUserPage() {
|
2022-03-10 21:39:37 +00:00
|
|
|
$title = Title::makeTitle( NS_USER, 'Fake_user' );
|
2019-05-23 09:55:21 +00:00
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertFalse( $helper->isUserPage() );
|
2019-05-23 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* @covers ::fetchData
|
|
|
|
*/
|
|
|
|
public function testTitleProcessingIsCached() {
|
|
|
|
$titleMock = $this->getMockBuilder( Title::class )
|
2020-03-13 14:00:40 +00:00
|
|
|
->disableOriginalConstructor()
|
2017-07-12 15:12:40 +00:00
|
|
|
->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' );
|
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$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();
|
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$title
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertTrue( $helper->isUserPage() );
|
2017-07-12 15:12:40 +00:00
|
|
|
$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();
|
|
|
|
|
2022-12-21 18:57:45 +00:00
|
|
|
$helper = new SkinUserPageHelper(
|
|
|
|
$this->getServiceContainer()->getUserNameUtils(),
|
|
|
|
$this->getServiceContainer()->getUserFactory(),
|
|
|
|
$secondTestUserTitle
|
|
|
|
);
|
2020-01-26 19:26:31 +00:00
|
|
|
$this->assertTrue( $helper->isUserPage() );
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->assertNotEquals( $testUser->getId(), $helper->getPageUser()->getId() );
|
|
|
|
$this->assertNotEquals( $helper->getPageUser()->getUserPage(), $testUserTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|