Debian Codegraph @

tests/phpunit/includes/page/WikiCategoryPageTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Page\PageProps;
4 use MediaWiki\Title\Title;
5
6 class WikiCategoryPageTest extends MediaWikiLangTestCase {
7
8 /**
9 * @covers \WikiCategoryPage::isHidden
10 */
11 public function testHiddenCategory_PropertyNotSet() {
12 $title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
13 $title->resetArticleID( 42 );
14 $categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
15
16 $pageProps = $this->createMock( PageProps::class );
17 $pageProps->expects( $this->once() )
18 ->method( 'getProperties' )
19 ->with( $title, 'hiddencat' )
20 ->willReturn( [] );
21
22 $this->setService( 'PageProps', $pageProps );
23
24 $this->assertFalse( $categoryPage->isHidden() );
25 }
26
27 public static function provideCategoryContent() {
28 return [
29 [ true ],
30 [ false ],
31 ];
32 }
33
34 /**
35 * @dataProvider provideCategoryContent
36 * @covers \WikiCategoryPage::isHidden
37 */
38 public function testHiddenCategory_PropertyIsSet( $isHidden ) {
39 $categoryPageID = 42;
40 $categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
41 $categoryTitle->resetArticleID( $categoryPageID );
42 $categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
43
44 $pageProps = $this->createMock( PageProps::class );
45 $pageProps->expects( $this->once() )
46 ->method( 'getProperties' )
47 ->with( $categoryTitle, 'hiddencat' )
48 ->willReturn( $isHidden ? [ $categoryPageID => '' ] : [] );
49
50 $this->setService( 'PageProps', $pageProps );
51
52 $this->assertEquals( $isHidden, $categoryPage->isHidden() );
53 }
54
55 /**
56 * @covers \WikiCategoryPage::isExpectedUnusedCategory
57 */
58 public function testExpectUnusedCategory_PropertyNotSet() {
59 $title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
60 $title->resetArticleID( 42 );
61 $categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
62
63 $pageProps = $this->createMock( PageProps::class );
64 $pageProps->expects( $this->once() )
65 ->method( 'getProperties' )
66 ->with( $title, 'expectunusedcategory' )
67 ->willReturn( [] );
68
69 $this->setService( 'PageProps', $pageProps );
70
71 $this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
72 }
73
74 /**
75 * @dataProvider provideCategoryContent
76 * @covers \WikiCategoryPage::isExpectedUnusedCategory
77 */
78 public function testExpectUnusedCategory_PropertyIsSet( $isExpectedUnusedCategory ) {
79 $categoryPageID = 42;
80 $categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
81 $categoryTitle->resetArticleID( $categoryPageID );
82 $categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
83 $returnValue = $isExpectedUnusedCategory ? [ $categoryPageID => '' ] : [];
84
85 $pageProps = $this->createMock( PageProps::class );
86 $pageProps->expects( $this->once() )
87 ->method( 'getProperties' )
88 ->with( $categoryTitle, 'expectunusedcategory' )
89 ->willReturn( $returnValue );
90
91 $this->setService( 'PageProps', $pageProps );
92
93 $this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
94 }
95 }