WikiCategoryPageTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use Wikimedia\ScopedCallback;
  3. class WikiCategoryPageTest extends MediaWikiLangTestCase {
  4. /**
  5. * @return PHPUnit_Framework_MockObject_MockObject|PageProps
  6. */
  7. private function getMockPageProps() {
  8. return $this->getMockBuilder( PageProps::class )
  9. ->disableOriginalConstructor()
  10. ->getMock();
  11. }
  12. /**
  13. * @covers WikiCategoryPage::isHidden
  14. */
  15. public function testHiddenCategory_PropertyNotSet() {
  16. $title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
  17. $categoryPage = WikiCategoryPage::factory( $title );
  18. $pageProps = $this->getMockPageProps();
  19. $pageProps->expects( $this->once() )
  20. ->method( 'getProperties' )
  21. ->with( $title, 'hiddencat' )
  22. ->will( $this->returnValue( [] ) );
  23. $scopedOverride = PageProps::overrideInstance( $pageProps );
  24. $this->assertFalse( $categoryPage->isHidden() );
  25. ScopedCallback::consume( $scopedOverride );
  26. }
  27. public function provideCategoryContent() {
  28. return [
  29. [ true ],
  30. [ false ],
  31. ];
  32. }
  33. /**
  34. * @dataProvider provideCategoryContent
  35. * @covers WikiCategoryPage::isHidden
  36. */
  37. public function testHiddenCategory_PropertyIsSet( $isHidden ) {
  38. $categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
  39. $categoryPage = WikiCategoryPage::factory( $categoryTitle );
  40. $pageProps = $this->getMockPageProps();
  41. $pageProps->expects( $this->once() )
  42. ->method( 'getProperties' )
  43. ->with( $categoryTitle, 'hiddencat' )
  44. ->will( $this->returnValue( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] ) );
  45. $scopedOverride = PageProps::overrideInstance( $pageProps );
  46. $this->assertEquals( $isHidden, $categoryPage->isHidden() );
  47. ScopedCallback::consume( $scopedOverride );
  48. }
  49. }