Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?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' );
|
|
$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 ) {
|
|
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
|
|
|
|
$pageProps = $this->createMock( PageProps::class );
|
|
$pageProps->expects( $this->once() )
|
|
->method( 'getProperties' )
|
|
->with( $categoryTitle, 'hiddencat' )
|
|
->willReturn( $isHidden ? [ $categoryTitle->getArticleID() => '' ] : [] );
|
|
|
|
$this->setService( 'PageProps', $pageProps );
|
|
|
|
$this->assertEquals( $isHidden, $categoryPage->isHidden() );
|
|
}
|
|
|
|
/**
|
|
* @covers WikiCategoryPage::isExpectedUnusedCategory
|
|
*/
|
|
public function testExpectUnusedCategory_PropertyNotSet() {
|
|
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
$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 ) {
|
|
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
|
|
$categoryPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $categoryTitle );
|
|
$returnValue = $isExpectedUnusedCategory ? [ $categoryTitle->getArticleID() => '' ] : [];
|
|
|
|
$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() );
|
|
}
|
|
}
|