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