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