wiki.techinc.nl/tests/phpunit/unit/includes/user/TempUser/RealTempUserConfigTest.php
Dreamy Jazz 4fcf7c46ba Add wfDeprecated call to RealTempUserConfig::getMatchPattern
Why:
* The TempUserConfig::getMatchPattern method was deprecated in
  7f588780a0 with a replacement of
  TempUserConfig::getMatchPatterns.
* All existing usages on WMF deployed extensions have been replaced
  so a call to wfDeprecated can be added.

What:
* Add a wfDeprecated call in RealTempUserConfig::getMatchPattern.
  The other implementation of this method calls this method, so
  this is the only call needed.
* Update the tests to expect the deprecation of ::getMatchPattern.

Depends-On: I122f001ab24e879a573b19468d642b8f579d1024
Bug: T354619
Change-Id: I74ea85429d083737c325c978e1cad04beb6a9325
2024-01-18 20:25:17 +00:00

55 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\User\TempUser;
use BadMethodCallException;
use MediaWiki\User\TempUser\RealTempUserConfig;
use MediaWikiUnitTestCase;
use Wikimedia\TestingAccessWrapper;
/**
* @covers \MediaWiki\User\TempUser\RealTempUserConfig
*/
class RealTempUserConfigTest extends MediaWikiUnitTestCase {
/** @dataProvider provideMethodsThatThrowWhenTempUsersAreDisabled */
public function testMethodsThatThrowWhenTempUsersAreDisabled( $methodName ) {
$this->expectException( BadMethodCallException::class );
$objectUnderTest = $this->getMockBuilder( RealTempUserConfig::class )
->onlyMethods( [ 'isEnabled' ] )
->disableOriginalConstructor()
->getMock();
// Simulate that the AutoCreateTempUser config has 'enabled' as false.
$objectUnderTest->method( 'isEnabled' )
->willReturn( false );
$objectUnderTest->$methodName();
}
public static function provideMethodsThatThrowWhenTempUsersAreDisabled() {
return [
'getPlaceholderName' => [ 'getPlaceholderName' ],
'getMatchPatterns' => [ 'getMatchPatterns' ],
'getGeneratorPattern' => [ 'getGeneratorPattern' ],
];
}
/** @dataProvider provideIsEnabled */
public function testIsEnabled( $enabledValue ) {
// Get the object under test with the constructor disabled.
$objectUnderTest = $this->getMockBuilder( RealTempUserConfig::class )
->onlyMethods( [] )
->disableOriginalConstructor()
->getMock();
// Set $objectUnderTest->enabled to $enabledValue
$objectUnderTest = TestingAccessWrapper::newFromObject( $objectUnderTest );
$objectUnderTest->enabled = $enabledValue;
$this->assertSame( $enabledValue, $objectUnderTest->isEnabled() );
}
public static function provideIsEnabled() {
return [
'Auto creation is enabled' => [ true ],
'Auto creation is disabled' => [ false ],
];
}
}