2016-04-13 15:52:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-10-06 04:54:59 +00:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-10-12 05:36:03 +00:00
|
|
|
|
2016-04-13 15:52:48 +00:00
|
|
|
class WikiCategoryPageTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-06 04:54:59 +00:00
|
|
|
* @return MockObject|PageProps
|
2016-04-13 15:52:48 +00:00
|
|
|
*/
|
|
|
|
|
private function getMockPageProps() {
|
|
|
|
|
return $this->getMockBuilder( PageProps::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiCategoryPage::isHidden
|
|
|
|
|
*/
|
|
|
|
|
public function testHiddenCategory_PropertyNotSet() {
|
|
|
|
|
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
|
|
|
$categoryPage = WikiCategoryPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$pageProps = $this->getMockPageProps();
|
|
|
|
|
$pageProps->expects( $this->once() )
|
|
|
|
|
->method( 'getProperties' )
|
|
|
|
|
->with( $title, 'hiddencat' )
|
2021-04-22 08:28:11 +00:00
|
|
|
->willReturn( [] );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
2020-05-21 03:47:11 +00:00
|
|
|
$this->setService( 'PageProps', $pageProps );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse( $categoryPage->isHidden() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideCategoryContent() {
|
|
|
|
|
return [
|
|
|
|
|
[ true ],
|
|
|
|
|
[ false ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCategoryContent
|
|
|
|
|
* @covers WikiCategoryPage::isHidden
|
|
|
|
|
*/
|
|
|
|
|
public function testHiddenCategory_PropertyIsSet( $isHidden ) {
|
|
|
|
|
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
|
|
|
$categoryPage = WikiCategoryPage::factory( $categoryTitle );
|
|
|
|
|
|
|
|
|
|
$pageProps = $this->getMockPageProps();
|
|
|
|
|
$pageProps->expects( $this->once() )
|
|
|
|
|
->method( 'getProperties' )
|
|
|
|
|
->with( $categoryTitle, 'hiddencat' )
|
2021-04-22 08:28:11 +00:00
|
|
|
->willReturn( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
2020-05-21 03:47:11 +00:00
|
|
|
$this->setService( 'PageProps', $pageProps );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $isHidden, $categoryPage->isHidden() );
|
|
|
|
|
}
|
2018-09-07 21:32:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiCategoryPage::isExpectedUnusedCategory
|
|
|
|
|
*/
|
|
|
|
|
public function testExpectUnusedCategory_PropertyNotSet() {
|
|
|
|
|
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
|
|
|
$categoryPage = WikiCategoryPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$pageProps = $this->getMockPageProps();
|
|
|
|
|
$pageProps->expects( $this->once() )
|
|
|
|
|
->method( 'getProperties' )
|
|
|
|
|
->with( $title, 'expectunusedcategory' )
|
2021-04-22 08:28:11 +00:00
|
|
|
->willReturn( [] );
|
2018-09-07 21:32:26 +00:00
|
|
|
|
2020-05-21 03:47:11 +00:00
|
|
|
$this->setService( 'PageProps', $pageProps );
|
2018-09-07 21:32:26 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCategoryContent
|
|
|
|
|
* @covers WikiCategoryPage::isExpectedUnusedCategory
|
|
|
|
|
*/
|
|
|
|
|
public function testExpectUnusedCategory_PropertyIsSet( $isExpectedUnusedCategory ) {
|
|
|
|
|
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
|
|
|
$categoryPage = WikiCategoryPage::factory( $categoryTitle );
|
|
|
|
|
$returnValue = $isExpectedUnusedCategory ? [ $categoryTitle->getArticleID() => '' ] : [];
|
|
|
|
|
|
|
|
|
|
$pageProps = $this->getMockPageProps();
|
|
|
|
|
$pageProps->expects( $this->once() )
|
|
|
|
|
->method( 'getProperties' )
|
|
|
|
|
->with( $categoryTitle, 'expectunusedcategory' )
|
2021-04-22 08:28:11 +00:00
|
|
|
->willReturn( $returnValue );
|
2018-09-07 21:32:26 +00:00
|
|
|
|
2020-05-21 03:47:11 +00:00
|
|
|
$this->setService( 'PageProps', $pageProps );
|
2018-09-07 21:32:26 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
|
|
|
|
|
}
|
2016-04-13 15:52:48 +00:00
|
|
|
}
|