2016-04-13 15:52:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-12-09 12:17:40 +00:00
|
|
|
use MediaWiki\Page\PageProps;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-12-09 12:17:40 +00:00
|
|
|
|
2016-04-13 15:52:48 +00:00
|
|
|
class WikiCategoryPageTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiCategoryPage::isHidden
|
|
|
|
|
*/
|
|
|
|
|
public function testHiddenCategory_PropertyNotSet() {
|
|
|
|
|
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
2022-10-23 20:42:56 +00:00
|
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
2022-08-05 10:47:38 +00:00
|
|
|
$pageProps = $this->createMock( PageProps::class );
|
2016-04-13 15:52:48 +00:00
|
|
|
$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() );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideCategoryContent() {
|
2016-04-13 15:52:48 +00:00
|
|
|
return [
|
|
|
|
|
[ true ],
|
|
|
|
|
[ false ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCategoryContent
|
|
|
|
|
* @covers WikiCategoryPage::isHidden
|
|
|
|
|
*/
|
|
|
|
|
public function testHiddenCategory_PropertyIsSet( $isHidden ) {
|
|
|
|
|
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
2022-10-23 20:42:56 +00:00
|
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
|
2016-04-13 15:52:48 +00:00
|
|
|
|
2022-08-05 10:47:38 +00:00
|
|
|
$pageProps = $this->createMock( PageProps::class );
|
2016-04-13 15:52:48 +00:00
|
|
|
$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' );
|
2022-10-23 20:42:56 +00:00
|
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2018-09-07 21:32:26 +00:00
|
|
|
|
2022-08-05 10:47:38 +00:00
|
|
|
$pageProps = $this->createMock( PageProps::class );
|
2018-09-07 21:32:26 +00:00
|
|
|
$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' );
|
2022-10-23 20:42:56 +00:00
|
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
|
2018-09-07 21:32:26 +00:00
|
|
|
$returnValue = $isExpectedUnusedCategory ? [ $categoryTitle->getArticleID() => '' ] : [];
|
|
|
|
|
|
2022-08-05 10:47:38 +00:00
|
|
|
$pageProps = $this->createMock( PageProps::class );
|
2018-09-07 21:32:26 +00:00
|
|
|
$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
|
|
|
}
|