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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<?php
use MediaWiki\Page\PageProps;
use MediaWiki\Title\Title;
class WikiCategoryPageTest extends MediaWikiLangTestCase {
/**
* @covers \WikiCategoryPage::isHidden
*/
public function testHiddenCategory_PropertyNotSet() {
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$title->resetArticleID( 42 );
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
$pageProps = $this->createMock( PageProps::class );
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $title, 'hiddencat' )
->willReturn( [] );
$this->setService( 'PageProps', $pageProps );
$this->assertFalse( $categoryPage->isHidden() );
}
public static function provideCategoryContent() {
return [
[ true ],
[ false ],
];
}
/**
* @dataProvider provideCategoryContent
* @covers \WikiCategoryPage::isHidden
*/
public function testHiddenCategory_PropertyIsSet( $isHidden ) {
$categoryPageID = 42;
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$categoryTitle->resetArticleID( $categoryPageID );
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
$pageProps = $this->createMock( PageProps::class );
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $categoryTitle, 'hiddencat' )
->willReturn( $isHidden ? [ $categoryPageID => '' ] : [] );
$this->setService( 'PageProps', $pageProps );
$this->assertEquals( $isHidden, $categoryPage->isHidden() );
}
/**
* @covers \WikiCategoryPage::isExpectedUnusedCategory
*/
public function testExpectUnusedCategory_PropertyNotSet() {
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$title->resetArticleID( 42 );
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
$pageProps = $this->createMock( PageProps::class );
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $title, 'expectunusedcategory' )
->willReturn( [] );
$this->setService( 'PageProps', $pageProps );
$this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
}
/**
* @dataProvider provideCategoryContent
* @covers \WikiCategoryPage::isExpectedUnusedCategory
*/
public function testExpectUnusedCategory_PropertyIsSet( $isExpectedUnusedCategory ) {
$categoryPageID = 42;
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$categoryTitle->resetArticleID( $categoryPageID );
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
$returnValue = $isExpectedUnusedCategory ? [ $categoryPageID => '' ] : [];
$pageProps = $this->createMock( PageProps::class );
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $categoryTitle, 'expectunusedcategory' )
->willReturn( $returnValue );
$this->setService( 'PageProps', $pageProps );
$this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
}
}
|