X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/page/WikiCategoryPageTest.php diff --git a/tests/phpunit/includes/page/WikiCategoryPageTest.php b/tests/phpunit/includes/page/WikiCategoryPageTest.php new file mode 100644 index 00000000..5f1bf0ca --- /dev/null +++ b/tests/phpunit/includes/page/WikiCategoryPageTest.php @@ -0,0 +1,63 @@ +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 ); + } +}