wiki.techinc.nl/tests/phpunit/includes/page/WikiCategoryPageTest.php
Agabi10 4985ce5134 Add a way to exclude categories from Special:UnusedCategories
Added __EXPECT_UNUSED_CATEGORY__ as a behavioral switch. Adding
this switch to category pages prevents them from appearing in
Special:UnusedCategories.

Bug: T96041
Change-Id: I055e59f5311347155e0f801dd5ec9a6d4a68c9cc
2018-11-16 13:32:27 +00:00

105 lines
3.1 KiB
PHP

<?php
use Wikimedia\ScopedCallback;
class WikiCategoryPageTest extends MediaWikiLangTestCase {
/**
* @return PHPUnit_Framework_MockObject_MockObject|PageProps
*/
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' )
->will( $this->returnValue( [] ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertFalse( $categoryPage->isHidden() );
ScopedCallback::consume( $scopedOverride );
}
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' )
->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertEquals( $isHidden, $categoryPage->isHidden() );
ScopedCallback::consume( $scopedOverride );
}
/**
* @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' )
->will( $this->returnValue( [] ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
ScopedCallback::consume( $scopedOverride );
}
/**
* @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' )
->will( $this->returnValue( $returnValue ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
ScopedCallback::consume( $scopedOverride );
}
}