summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/page/WikiCategoryPageTest.php
blob: 5f1bf0ca794ae34bf35085ae7a4441fda9173edb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

use Wikimedia\ScopedCallback;

class WikiCategoryPageTest extends MediaWikiLangTestCase {

	/**
	 * @return PHPUnit_Framework_MockObject_MockObject|PageProps
	 */
	private function getMockPageProps() {
		return $this->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 );
	}
}