diff --git a/RELEASE-NOTES-1.41 b/RELEASE-NOTES-1.41 index d6e4253de55..9ed41b85e64 100644 --- a/RELEASE-NOTES-1.41 +++ b/RELEASE-NOTES-1.41 @@ -107,6 +107,21 @@ because of Phabricator reports. - ::wasConnectionLoss() * PrevNextNavigationRenderer class, deprecated in 1.39, has been removed. +* The following methods in the Title class, deprecated since 1.37, have been + removed: + - ::areCascadeProtectionSourcesLoaded() + - ::areRestrictionsCascading() + - ::areRestrictionsLoaded() + - ::getAllRestrictions() + - ::getCascadeProtectionSources() + - ::getFilteredRestrictionTypes() + - ::getRestrictionExpiry() + - ::getRestrictionTypes() + - ::getRestrictions() + - ::isCascadeProtected() + - ::isProtected() + - ::isSemiProtected() + - ::loadRestrictionsFromRows() * LinkBatch::__construct() now requires that all parameters be passed. The fallback to MediaWikiServices emitted deprecation notices since 1.35. * The methods IndexPager::getPagingLinks(), IndexPager::getLimitLinks() and diff --git a/docs/config-schema.yaml b/docs/config-schema.yaml index 8b909454357..1d55715f953 100644 --- a/docs/config-schema.yaml +++ b/docs/config-schema.yaml @@ -4965,7 +4965,7 @@ config-schema: Set of available actions that can be restricted via action=protect You probably shouldn't change this. Translated through restriction-* messages. - Title::getRestrictionTypes() will remove restrictions that are not + RestrictionStore::listApplicableRestrictionTypes() will remove restrictions that are not applicable to a specific title (create and upload) RestrictionLevels: default: diff --git a/includes/MainConfigSchema.php b/includes/MainConfigSchema.php index 9a2b2b41ea3..3e78061dca5 100644 --- a/includes/MainConfigSchema.php +++ b/includes/MainConfigSchema.php @@ -7881,7 +7881,7 @@ class MainConfigSchema { * You probably shouldn't change this. * * Translated through restriction-* messages. - * Title::getRestrictionTypes() will remove restrictions that are not + * RestrictionStore::listApplicableRestrictionTypes() will remove restrictions that are not * applicable to a specific title (create and upload) */ public const RestrictionTypes = [ diff --git a/includes/Permissions/RestrictionStore.php b/includes/Permissions/RestrictionStore.php index 48cd0a8415e..f5cfb1e2e84 100644 --- a/includes/Permissions/RestrictionStore.php +++ b/includes/Permissions/RestrictionStore.php @@ -150,8 +150,7 @@ class RestrictionStore { * @param PageIdentity $page Must be local * @param string $action * @return ?string 14-char timestamp, or 'infinity' if the page is protected forever or not - * protected at all, or null if the action is not recognized. NOTE: This returns null for - * unrecognized actions, unlike Title::getRestrictionExpiry which returns false. + * protected at all, or null if the action is not recognized. */ public function getRestrictionExpiry( PageIdentity $page, string $action ): ?string { $page->assertWiki( PageIdentity::LOCAL ); @@ -545,9 +544,7 @@ class RestrictionStore { * @param PageIdentity $page Must be local * @return array[] Two elements: First is an array of PageIdentity objects of the pages from * which cascading restrictions have come, which may be empty. Second is an array like that - * returned by getAllRestrictions(). NOTE: The first element of the return is always an - * array, unlike Title::getCascadeProtectionSources where the first element is false if there - * are no sources. + * returned by getAllRestrictions(). */ public function getCascadeProtectionSources( PageIdentity $page ): array { $page->assertWiki( PageIdentity::LOCAL ); diff --git a/includes/title/Title.php b/includes/title/Title.php index ad32d719d35..a965af24148 100644 --- a/includes/title/Title.php +++ b/includes/title/Title.php @@ -2465,42 +2465,11 @@ class Title implements LinkTarget, PageIdentity, IDBAccessObject { return $s; } - /** - * Get a filtered list of all restriction types supported by this wiki. - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::listAllRestrictionTypes instead - * - * @param bool $exists True to get all restriction types that apply to - * titles that do exist, False for all restriction types that apply to - * titles that do not exist - * @return array - */ - public static function getFilteredRestrictionTypes( $exists = true ) { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance() - ->getRestrictionStore() - ->listAllRestrictionTypes( $exists ); - } - - /** - * Returns restriction types for the current Title - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::listApplicableRestrictionTypes instead - * - * @return array Applicable restriction types - */ - public function getRestrictionTypes() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance() - ->getRestrictionStore() - ->listApplicableRestrictionTypes( $this ); - } - /** * Is this title subject to title protection? * Title protection is the one applied against creation of such title. * - * @deprecated since 1.37, use RestrictionStore::getRestrictions() instead + * @deprecated since 1.37, use RestrictionStore::getCreateProtection() instead * * @return array|bool An associative array representing any existent title * protection, or false if there's none. @@ -2519,184 +2488,6 @@ class Title implements LinkTarget, PageIdentity, IDBAccessObject { MediaWikiServices::getInstance()->getRestrictionStore()->deleteCreateProtection( $this ); } - /** - * Is this page "semi-protected" - the *only* protection levels are listed - * in $wgSemiprotectedRestrictionLevels? - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isSemiProtected instead - * - * @param string $action Action to check (default: edit) - * @return bool - */ - public function isSemiProtected( $action = 'edit' ) { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->isSemiProtected( - $this, $action - ); - } - - /** - * Does the title correspond to a protected article? - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isProtected instead - * - * @param string $action The action the page is protected from, - * by default checks all actions. - * @return bool - */ - public function isProtected( $action = '' ) { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->isProtected( - $this, $action - ); - } - - /** - * Cascading protection: Return true if cascading restrictions apply to this page, false if not. - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isCascadeProtected instead - * - * @return bool If the page is subject to cascading restrictions. - */ - public function isCascadeProtected() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->isCascadeProtected( $this ); - } - - /** - * Determines whether cascading protection sources have already been loaded from - * the database. - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areCascadeProtectionSourcesLoaded instead - * - * @return bool - * @since 1.23 - */ - public function areCascadeProtectionSourcesLoaded() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore() - ->areCascadeProtectionSourcesLoaded( $this ); - } - - /** - * Cascading protection: Get the source of any cascading restrictions on this page. - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getCascadeProtectionSources instead - * - * @param bool $getPages Whether or not to retrieve the actual pages - * that the restrictions have come from and the actual restrictions - * themselves. - * @return array Two elements: First is an array of Title objects of the - * pages from which cascading restrictions have come if $getPages - * is true, or a bool indicating whether any cascading protection - * applies if $getPages was set to false. - * Second is an array like that returned by Title::getAllRestrictions(), - * or an empty array if $getPages is false. - */ - public function getCascadeProtectionSources( $getPages = true ) { - wfDeprecated( __METHOD__, '1.37' ); - $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore(); - if ( !$getPages ) { - return [ $restrictionStore->isCascadeProtected( $this ), [] ]; - } - - $ret = $restrictionStore->getCascadeProtectionSources( $this ); - $ret[0] = array_map( '\MediaWiki\Title\Title::castFromPageIdentity', $ret[0] ); - return $ret; - } - - /** - * Accessor for mRestrictionsLoaded - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areRestrictionsLoaded instead - * - * @return bool Whether or not the page's restrictions have already been - * loaded from the database - * @since 1.23 - */ - public function areRestrictionsLoaded() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance() - ->getRestrictionStore() - ->areRestrictionsLoaded( $this ); - } - - /** - * Accessor/initialisation for mRestrictions - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getRestrictions instead - * - * @param string $action Action that permission needs to be checked for - * @return array Restriction levels needed to take the action. All levels are - * required. Note that restriction levels are normally user rights, but 'sysop' - * and 'autoconfirmed' are also allowed for backwards compatibility. These should - * be mapped to 'editprotected' and 'editsemiprotected' respectively. - */ - public function getRestrictions( $action ) { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictions( $this, $action ); - } - - /** - * Accessor/initialisation for mRestrictions - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getAllRestrictions instead - * - * @return array Keys are actions, values are arrays as returned by - * Title::getRestrictions() - * @since 1.23 - */ - public function getAllRestrictions() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->getAllRestrictions( $this ); - } - - /** - * Get the expiry time for the restriction against a given action - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getRestrictionExpiry instead - * - * @param string $action - * @return string|bool 14-char timestamp, or 'infinity' if the page is protected forever - * or not protected at all, or false if the action is not recognised. - */ - public function getRestrictionExpiry( $action ) { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictionExpiry( - $this, $action - ) ?? false; - } - - /** - * Returns cascading restrictions for the current article - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areRestrictionsCascading instead - * - * @return bool - */ - public function areRestrictionsCascading() { - wfDeprecated( __METHOD__, '1.37' ); - return MediaWikiServices::getInstance() - ->getRestrictionStore() - ->areRestrictionsCascading( $this ); - } - - /** - * Compiles list of active page restrictions from both page table (pre 1.10) - * and page_restrictions table for this existing page. - * Public for usage by LiquidThreads. - * - * @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::loadRestrictionsFromRows instead - * - * @param stdClass[] $rows Array of db result objects - */ - public function loadRestrictionsFromRows( $rows ) { - wfDeprecated( __METHOD__, '1.37' ); - MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictionsFromRows( - $this, $rows - ); - } - /** * Load restrictions from the page_restrictions table * diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 270982c6fe8..a3b7280e015 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -1,16 +1,13 @@ hideDeprecated( Title::class . '::areRestrictionsLoaded' ); - $this->hideDeprecated( Title::class . '::getRestrictionExpiry' ); - $title = Title::newFromText( 'UTPage1' ); - $title->loadRestrictions(); - $this->assertTrue( $title->areRestrictionsLoaded() ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $title->loadRestrictions(); - $this->assertTrue( $title->areRestrictionsLoaded() ); - $this->assertFalse( $title->getRestrictionExpiry( 'create' ), - "Existing page can't have create protection" ); - $this->assertSame( 'infinity', $title->getRestrictionExpiry( 'edit' ) ); - $page = $this->getNonexistingTestPage( 'UTest1' ); - $title = $page->getTitle(); - $protectExpiry = wfTimestamp( TS_MW, time() + 10000 ); - $cascade = 0; - $page->doUpdateRestrictions( - [ 'create' => 'sysop' ], - [ 'create' => $protectExpiry ], - $cascade, - 'test', - $this->getTestSysop()->getUser() - ); - $title->flushRestrictions(); - $title->loadRestrictions(); - $this->assertSame( - $protectExpiry, - $title->getRestrictionExpiry( 'create' ) - ); - } - - public static function provideRestrictionsRows() { - yield [ [ (object)[ - 'pr_id' => 1, - 'pr_page' => 1, - 'pr_type' => 'edit', - 'pr_level' => 'sysop', - 'pr_cascade' => 0, - 'pr_expiry' => 'infinity' - ] ] ]; - yield [ [ (object)[ - 'pr_id' => 1, - 'pr_page' => 1, - 'pr_type' => 'edit', - 'pr_level' => 'sysop', - 'pr_cascade' => 0, - 'pr_expiry' => 'infinity' - ] ] ]; - yield [ [ (object)[ - 'pr_id' => 1, - 'pr_page' => 1, - 'pr_type' => 'move', - 'pr_level' => 'sysop', - 'pr_cascade' => 0, - 'pr_expiry' => wfTimestamp( TS_MW, time() + 10000 ) - ] ] ]; - } - - /** - * @covers Title::loadRestrictionsFromRows - * @dataProvider provideRestrictionsRows - */ - public function testloadRestrictionsFromRows( $rows ) { - $this->hideDeprecated( Title::class . '::loadRestrictionsFromRows' ); - $this->hideDeprecated( Title::class . '::getRestrictions' ); - $this->hideDeprecated( Title::class . '::getRestrictionExpiry' ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $title->loadRestrictionsFromRows( $rows ); - $this->assertSame( - $rows[0]->pr_level, - $title->getRestrictions( $rows[0]->pr_type )[0] - ); - $this->assertSame( - $rows[0]->pr_expiry, - $title->getRestrictionExpiry( $rows[0]->pr_type ) - ); - } - - /** - * @dataProvider provideRestrictionStoreForwarding - * @covers Title::getFilteredRestrictionTypes - * @covers Title::getRestrictionTypes - * @covers Title::getTitleProtection - * @covers Title::deleteTitleProtection - * @covers Title::isSemiProtected - * @covers Title::isProtected - * @covers Title::isCascadeProtected - * @covers Title::areCascadeProtectionSourcesLoaded - * @covers Title::getCascadeProtectionSources - * @covers Title::areRestrictionsLoaded - * @covers Title::getRestrictions - * @covers Title::getAllRestrictions - * @covers Title::getRestrictionExpiry - * @covers Title::areRestrictionsCascading - * @covers Title::loadRestrictionsFromRows - * @covers Title::loadRestrictions - * @covers Title::flushRestrictions - */ - public function testRestrictionStoreForwarding( - string $method, array $params, $return, array $options = [] - ) { - $this->hideDeprecated( Title::class . '::' . $method ); - $expectedParams = $options['expectedParams'] ?? $params; - - if ( isset( $options['static'] ) ) { - $callee = 'Title'; - } else { - $callee = $this->getExistingTestPage()->getTitle(); - $expectedParams = array_merge( [ $callee ], $expectedParams ); - } - - $expectedMethod = $options['expectedMethod'] ?? $method; - $mockRestrictionStore = $this->createNoOpMock( RestrictionStore::class, [ $expectedMethod ] ); - - $expectedCall = $mockRestrictionStore->expects( $this->once() ) - ->method( $expectedMethod ) - ->with( ...$expectedParams ); - if ( !isset( $options['void'] ) ) { - $expectedCall->willReturn( $return ); - } - - $this->setService( 'RestrictionStore', $mockRestrictionStore ); - - $options['expectedReturn'] ??= $return; - - $comparisonMethod = isset( $options['weakCompareReturn'] ) ? 'assertEquals' : 'assertSame'; - - $this->$comparisonMethod( $options['expectedReturn'], [ $callee, $method ]( ...$params ) ); - } - - public static function provideRestrictionStoreForwarding() { - $pageIdentity = PageIdentityValue::localIdentity( 144, NS_MAIN, 'Sample' ); - $title = Title::newFromPageIdentity( $pageIdentity ); - return [ - [ 'getFilteredRestrictionTypes', [ true ], [ 'abc' ], - [ 'static' => true, 'expectedMethod' => 'listAllRestrictionTypes' ] ], - [ 'getFilteredRestrictionTypes', [ false ], [ 'def' ], - [ 'static' => true, 'expectedMethod' => 'listAllRestrictionTypes' ] ], - [ 'getRestrictionTypes', [], [ 'ghi' ], - [ 'expectedMethod' => 'listApplicableRestrictionTypes' ] ], - [ 'getTitleProtection', [], [ 'jkl' ], [ 'expectedMethod' => 'getCreateProtection' ] ], - [ 'getTitleProtection', [], null, - [ 'expectedMethod' => 'getCreateProtection', 'expectedReturn' => false ] ], - [ 'deleteTitleProtection', [], null, - [ 'expectedMethod' => 'deleteCreateProtection', 'void' => true ] ], - [ 'isSemiProtected', [ 'phlebotomize' ], true ], - [ 'isSemiProtected', [ 'splecotomize' ], false ], - [ 'isProtected', [ 'strezotomize' ], true ], - [ 'isProtected', [ 'chrelotomize' ], false ], - [ 'isCascadeProtected', [], true ], - [ 'isCascadeProtected', [], false ], - [ 'areCascadeProtectionSourcesLoaded', [ true ], true, [ 'expectedParams' => [] ] ], - [ 'areCascadeProtectionSourcesLoaded', [ true ], false, [ 'expectedParams' => [] ] ], - [ 'areCascadeProtectionSourcesLoaded', [ false ], true, [ 'expectedParams' => [] ] ], - [ 'areCascadeProtectionSourcesLoaded', [ false ], false, [ 'expectedParams' => [] ] ], - [ 'getCascadeProtectionSources', [], [ [ $pageIdentity ], [ 'mno' ] ], - [ 'expectedReturn' => [ [ $title ], [ 'mno' ] ], 'weakCompareReturn' => true ] ], - [ 'getCascadeProtectionSources', [], [ [], [] ], - [ 'expectedReturn' => [ [], [] ] ] ], - [ 'getCascadeProtectionSources', [ true ], [ [ $pageIdentity ], [ 'mno' ] ], - [ 'expectedParams' => [], 'expectedReturn' => [ [ $title ], [ 'mno' ] ], - 'weakCompareReturn' => true ] ], - [ 'getCascadeProtectionSources', [ true ], [ [], [] ], - [ 'expectedParams' => [], 'expectedReturn' => [ [], [] ] ] ], - [ 'getCascadeProtectionSources', [ false ], false, - [ 'expectedMethod' => 'isCascadeProtected', 'expectedParams' => [], - 'expectedReturn' => [ false, [] ] ] ], - [ 'getCascadeProtectionSources', [ false ], true, - [ 'expectedMethod' => 'isCascadeProtected', 'expectedParams' => [], - 'expectedReturn' => [ true, [] ] ] ], - [ 'areRestrictionsLoaded', [], true ], - [ 'areRestrictionsLoaded', [], false ], - [ 'getRestrictions', [ 'stu' ], [ 'vwx' ] ], - [ 'getAllRestrictions', [], [ 'yza' ] ], - [ 'getRestrictionExpiry', [ 'bcd' ], 'efg' ], - [ 'getRestrictionExpiry', [ 'hij' ], null, [ 'expectedReturn' => false ] ], - [ 'areRestrictionsCascading', [], true ], - [ 'areRestrictionsCascading', [], false ], - [ 'loadRestrictionsFromRows', [ [ 'hij' ] ], null, [ 'void' => true ] ], - [ 'loadRestrictions', [ 123 ], null, - [ 'void' => true, 'expectedParams' => [ 123 ] ] ], - [ 'flushRestrictions', [], null, [ 'void' => true ] ], - ]; - } - - /** - * @covers Title::getRestrictions - */ - public function testGetRestrictions() { - $this->hideDeprecated( Title::class . '::getRestrictions' ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => [ - 'a' => [ 'sysop' ], - 'b' => [ 'sysop' ], - 'c' => [ 'sysop' ] - ], - ] ]; - $this->assertArrayEquals( [ 'sysop' ], $title->getRestrictions( 'a' ) ); - $this->assertArrayEquals( [], $title->getRestrictions( 'error' ) ); - // TODO: maybe test if loadRestrictionsFromRows() is called? - } - - /** - * @covers Title::getAllRestrictions - */ - public function testGetAllRestrictions() { - $this->hideDeprecated( Title::class . '::getAllRestrictions' ); - $restrictions = [ - 'a' => [ 'sysop' ], - 'b' => [ 'sysop' ], - 'c' => [ 'sysop' ], - ]; - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => $restrictions - ] ]; - $this->assertArrayEquals( - $restrictions, - $title->getAllRestrictions() - ); - } - - /** - * @covers Title::getRestrictionExpiry - */ - public function testGetRestrictionExpiry() { - $this->hideDeprecated( Title::class . '::getRestrictionExpiry' ); - $this->hideDeprecated( Title::class . '::getRestrictions' ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'expiry' => [ - 'a' => 'infinity', 'b' => 'infinity', 'c' => 'infinity' - ], - // XXX This is bogus, restrictions will never be empty when expiry is not - 'restrictions' => [], - ] ]; - $this->assertSame( 'infinity', $title->getRestrictionExpiry( 'a' ) ); - $this->assertArrayEquals( [], $title->getRestrictions( 'error' ) ); - } - /** * @covers Title::getTitleProtection */ @@ -2090,28 +1837,6 @@ class TitleTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $title->getTitleProtection() ); } - /** - * @covers Title::isSemiProtected - */ - public function testIsSemiProtected() { - $this->hideDeprecated( Title::class . '::isSemiProtected' ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $this->overrideConfigValues( [ - MainConfigNames::SemiprotectedRestrictionLevels => [ 'autoconfirmed' ], - MainConfigNames::RestrictionLevels => [ '', 'autoconfirmed', 'sysop' ] - ] ); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => [ 'edit' => [ 'sysop' ] ], - ] ]; - $this->assertFalse( $title->isSemiProtected( 'edit' ) ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => [ 'edit' => [ 'autoconfirmed' ] ], - ] ]; - $this->assertTrue( $title->isSemiProtected( 'edit' ) ); - } - /** * @covers Title::deleteTitleProtection */ @@ -2120,132 +1845,6 @@ class TitleTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $title->getTitleProtection() ); } - /** - * @covers Title::isProtected - */ - public function testIsProtected() { - $this->hideDeprecated( Title::class . '::isProtected' ); - $title = $this->getExistingTestPage( 'UTest1' )->getTitle(); - $this->overrideConfigValues( [ - MainConfigNames::RestrictionLevels => [ '', 'autoconfirmed', 'sysop' ], - MainConfigNames::RestrictionTypes => [ 'create', 'edit', 'move', 'upload' ] - ] ); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => [ 'edit' => [ 'sysop' ] ], - ] ]; - $this->assertTrue( $title->isProtected( 'edit' ) ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'restrictions' => [ 'edit' => [ 'test' ] ], - ] ]; - $this->assertFalse( $title->isProtected( 'edit' ) ); - } - - /** - * @covers Title::isCascadeProtected - */ - public function testIsCascadeProtected() { - $this->hideDeprecated( Title::class . '::isCascadeProtected' ); - $page = $this->getExistingTestPage( 'UTest1' ); - $title = $page->getTitle(); - $rs = $this->getServiceContainer()->getRestrictionStore(); - $wrapper = TestingAccessWrapper::newFromObject( $rs ); - $wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [ - 'has_cascading' => true, - ] ]; - $this->assertTrue( $title->isCascadeProtected() ); - $wrapper->cache = []; - $this->assertFalse( $title->isCascadeProtected() ); - $wrapper->cache = []; - $cascade = 1; - $anotherPage = $this->getExistingTestPage( 'UTest2' ); - $anotherPage->doUserEditContent( - new WikitextContent( '{{:UTest1}}' ), - $this->getTestSysop()->getUser(), - 'test' - ); - $anotherPage->doUpdateRestrictions( - [ 'edit' => 'sysop' ], - [], - $cascade, - 'test', - $this->getTestSysop()->getUser() - ); - $this->assertTrue( $title->isCascadeProtected() ); - } - - /** - * @covers Title::getCascadeProtectionSources - * @group Broken - */ - public function testGetCascadeProtectionSources() { - $this->hideDeprecated( Title::class . '::getCascadeProtectionSources' ); - $page = $this->getExistingTestPage( 'UTest1' ); - $title = $page->getTitle(); - - $title->mCascadeSources = []; - $this->assertArrayEquals( - [ [], [] ], - $title->getCascadeProtectionSources( true ) - ); - - $reflection = new ReflectionClass( $title ); - $reflection_property = $reflection->getProperty( 'mHasCascadingRestrictions' ); - $reflection_property->setAccessible( true ); - $reflection_property->setValue( $title, true ); - $this->assertArrayEquals( - [ true, [] ], - $title->getCascadeProtectionSources( false ) - ); - - $title->mCascadeSources = null; - $reflection_property->setValue( $title, null ); - $this->assertArrayEquals( - [ false, [] ], - $title->getCascadeProtectionSources( false ) - ); - - $title->mCascadeSources = null; - $reflection_property->setValue( $title, null ); - $this->assertArrayEquals( - [ [], [] ], - $title->getCascadeProtectionSources( true ) - ); - - // TODO: this might partially duplicate testIsCascadeProtected method above - - $cascade = 1; - $anotherPage = $this->getExistingTestPage( 'UTest2' ); - $anotherPage->doUserEditContent( - new WikitextContent( '{{:UTest1}}' ), - $this->getTestSysop()->getUser(), - 'test' - ); - $anotherPage->doUpdateRestrictions( - [ 'edit' => 'sysop' ], - [], - $cascade, - 'test', - $this->getTestSysop()->getUser() - ); - - $this->assertArrayEquals( - [ true, [] ], - $title->getCascadeProtectionSources( false ) - ); - - $title->mCascadeSources = null; - $result = $title->getCascadeProtectionSources( true ); - $this->assertArrayEquals( - [ 'edit' => [ 'sysop' ] ], - $result[1] - ); - $this->assertArrayHasKey( - $anotherPage->getTitle()->getArticleID(), $result[0] - ); - } - /** * @covers Title::getCdnUrls */ diff --git a/tests/phpunit/mocks/MockTitleTrait.php b/tests/phpunit/mocks/MockTitleTrait.php index 660153b324c..9b896aec72b 100644 --- a/tests/phpunit/mocks/MockTitleTrait.php +++ b/tests/phpunit/mocks/MockTitleTrait.php @@ -68,7 +68,6 @@ trait MockTitleTrait { $title->method( 'getPageLanguage' )->willReturn( $props['language'] ?? 'qqx' ); $title->method( 'getContentModel' ) ->willReturn( $props['contentModel'] ?? CONTENT_MODEL_WIKITEXT ); - $title->method( 'getRestrictions' )->willReturn( [] ); $title->method( 'getTitleProtection' )->willReturn( false ); $title->method( 'canExist' ) ->willReturn( $ns >= 0 && empty( $props['interwiki'] ) && $text !== '' );