| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\User\TempUser\TempUserConfig; |
| 6 |
use MediaWikiUnitTestCase; |
| 7 |
use PopulateUserIsTemp; |
| 8 |
use Wikimedia\TestingAccessWrapper; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class PopulateUserIsTempTest extends MediaWikiUnitTestCase { |
| 14 |
public function testUpdateKey() { |
| 15 |
$objectUnderTest = TestingAccessWrapper::newFromObject( new PopulateUserIsTemp() ); |
| 16 |
$this->assertSame( |
| 17 |
PopulateUserIsTemp::class, |
| 18 |
$objectUnderTest->getUpdateKey(), |
| 19 |
'The update key for the PopulateUserTemp class was not as expected.' |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
public function testDoDBUpdatesWhenTempAccountsDisabled() { |
| 24 |
|
| 25 |
|
| 26 |
$mockTempUserConfig = $this->createMock( TempUserConfig::class ); |
| 27 |
$mockTempUserConfig->method( 'isEnabled' ) |
| 28 |
->willReturn( false ); |
| 29 |
$mockTempUserConfig->expects( $this->never() ) |
| 30 |
->method( 'getMatchCondition' ); |
| 31 |
|
| 32 |
$objectUnderTest = $this->getMockBuilder( PopulateUserIsTemp::class ) |
| 33 |
->onlyMethods( [ 'initServices' ] ) |
| 34 |
->getMock(); |
| 35 |
$objectUnderTest = TestingAccessWrapper::newFromObject( $objectUnderTest ); |
| 36 |
$objectUnderTest->tempUserConfig = $mockTempUserConfig; |
| 37 |
|
| 38 |
$this->assertTrue( |
| 39 |
$objectUnderTest->doDBUpdates(), |
| 40 |
'The doDBUpdates method did not return true as expected.' |
| 41 |
); |
| 42 |
} |
| 43 |
} |