Debian Codegraph @

tests/phpunit/unit/maintenance/PopulateUserIsTempTest.php

raw symbols SCIP
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 * @covers \PopulateUserIsTemp
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 // Create a mock TempUserConfig object that will return false for isEnabled and not
25 // expect any calls to getMatchPatterns.
26 $mockTempUserConfig = $this->createMock( TempUserConfig::class );
27 $mockTempUserConfig->method( 'isEnabled' )
28 ->willReturn( false );
29 $mockTempUserConfig->expects( $this->never() )
30 ->method( 'getMatchCondition' );
31 // Get the object under test and set the tempUserConfig property to the mock object.
32 $objectUnderTest = $this->getMockBuilder( PopulateUserIsTemp::class )
33 ->onlyMethods( [ 'initServices' ] )
34 ->getMock();
35 $objectUnderTest = TestingAccessWrapper::newFromObject( $objectUnderTest );
36 $objectUnderTest->tempUserConfig = $mockTempUserConfig;
37 // Call the doDBUpdates method and assert that it returns true.
38 $this->assertTrue(
39 $objectUnderTest->doDBUpdates(),
40 'The doDBUpdates method did not return true as expected.'
41 );
42 }
43 }