3 use Wikimedia\ScopedCallback
;
5 class WikiCategoryPageTest
extends MediaWikiLangTestCase
{
8 * @return PHPUnit_Framework_MockObject_MockObject|PageProps
10 private function getMockPageProps() {
11 return $this->getMockBuilder( PageProps
::class )
12 ->disableOriginalConstructor()
17 * @covers WikiCategoryPage::isHidden
19 public function testHiddenCategory_PropertyNotSet() {
20 $title = Title
::makeTitle( NS_CATEGORY
, 'CategoryPage' );
21 $categoryPage = WikiCategoryPage
::factory( $title );
23 $pageProps = $this->getMockPageProps();
24 $pageProps->expects( $this->once() )
25 ->method( 'getProperties' )
26 ->with( $title, 'hiddencat' )
27 ->will( $this->returnValue( [] ) );
29 $scopedOverride = PageProps
::overrideInstance( $pageProps );
31 $this->assertFalse( $categoryPage->isHidden() );
33 ScopedCallback
::consume( $scopedOverride );
36 public function provideCategoryContent() {
44 * @dataProvider provideCategoryContent
45 * @covers WikiCategoryPage::isHidden
47 public function testHiddenCategory_PropertyIsSet( $isHidden ) {
48 $categoryTitle = Title
::makeTitle( NS_CATEGORY
, 'CategoryPage' );
49 $categoryPage = WikiCategoryPage
::factory( $categoryTitle );
51 $pageProps = $this->getMockPageProps();
52 $pageProps->expects( $this->once() )
53 ->method( 'getProperties' )
54 ->with( $categoryTitle, 'hiddencat' )
55 ->will( $this->returnValue( $isHidden ?
[ $categoryTitle->getArticleID() => '' ] : [] ) );
57 $scopedOverride = PageProps
::overrideInstance( $pageProps );
59 $this->assertEquals( $isHidden, $categoryPage->isHidden() );
61 ScopedCallback
::consume( $scopedOverride );
65 * @covers WikiCategoryPage::isExpectedUnusedCategory
67 public function testExpectUnusedCategory_PropertyNotSet() {
68 $title = Title
::makeTitle( NS_CATEGORY
, 'CategoryPage' );
69 $categoryPage = WikiCategoryPage
::factory( $title );
71 $pageProps = $this->getMockPageProps();
72 $pageProps->expects( $this->once() )
73 ->method( 'getProperties' )
74 ->with( $title, 'expectunusedcategory' )
75 ->will( $this->returnValue( [] ) );
77 $scopedOverride = PageProps
::overrideInstance( $pageProps );
79 $this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
81 ScopedCallback
::consume( $scopedOverride );
85 * @dataProvider provideCategoryContent
86 * @covers WikiCategoryPage::isExpectedUnusedCategory
88 public function testExpectUnusedCategory_PropertyIsSet( $isExpectedUnusedCategory ) {
89 $categoryTitle = Title
::makeTitle( NS_CATEGORY
, 'CategoryPage' );
90 $categoryPage = WikiCategoryPage
::factory( $categoryTitle );
91 $returnValue = $isExpectedUnusedCategory ?
[ $categoryTitle->getArticleID() => '' ] : [];
93 $pageProps = $this->getMockPageProps();
94 $pageProps->expects( $this->once() )
95 ->method( 'getProperties' )
96 ->with( $categoryTitle, 'expectunusedcategory' )
97 ->will( $this->returnValue( $returnValue ) );
99 $scopedOverride = PageProps
::overrideInstance( $pageProps );
101 $this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
103 ScopedCallback
::consume( $scopedOverride );