wiki.techinc.nl/tests/phpunit/includes/page/WikiCategoryPageTest.php
DannyS712 e4db469262 Convert PageProps to a service
Bug: T253188
Change-Id: Ic358946099a3424a3d1c2615feb14e74b6336a0e
2020-08-12 21:21:53 +00:00

97 lines
2.8 KiB
PHP

<?php
use PHPUnit\Framework\MockObject\MockObject;
class WikiCategoryPageTest extends MediaWikiLangTestCase {
/**
* @return 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( [] ) );
$this->setService( 'PageProps', $pageProps );
$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' )
->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
$this->setService( 'PageProps', $pageProps );
$this->assertEquals( $isHidden, $categoryPage->isHidden() );
}
/**
* @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( [] ) );
$this->setService( 'PageProps', $pageProps );
$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' )
->will( $this->returnValue( $returnValue ) );
$this->setService( 'PageProps', $pageProps );
$this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
}
}