diff --git a/tests/phpunit/PopupsContextTest.php b/tests/phpunit/PopupsContextTest.php index d3f0f18e4..c6fa0fd73 100644 --- a/tests/phpunit/PopupsContextTest.php +++ b/tests/phpunit/PopupsContextTest.php @@ -19,6 +19,7 @@ * @ingroup extensions */ +use MediaWiki\User\UserOptionsLookup; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls; use Popups\PopupsContext; use Popups\PopupsGadgetsIntegration; @@ -94,8 +95,8 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase { * @covers ::shouldSendModuleToUser */ public function testShouldSendToAnonUser() { - $user = $this->getMutableTestUser()->getUser(); - $user->setId( self::ANONYMOUS_USER ); + $user = $this->createMock( User::class ); + $user->method( 'getId' )->willReturn( self::ANONYMOUS_USER ); $context = $this->getContext(); $this->assertTrue( @@ -118,10 +119,15 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase { 'wgPopupsReferencePreviews' => false, ] ); + $user = $this->createMock( User::class ); + $user->method( 'isNamed' )->willReturn( true ); + $userOptLookup = $this->createMock( UserOptionsLookup::class ); + $userOptLookup->method( 'getBoolOption' ) + ->with( $user, PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ) + ->willReturn( $optIn ); + $this->setService( 'UserOptionsLookup', $userOptLookup ); + $context = $this->getContext(); - $user = $this->getMutableTestUser()->getUser(); - $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); - $userOptionsManager->setOption( $user, PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $optIn ); $this->assertSame( $expected, $context->shouldSendModuleToUser( $user ), ( $expected ? 'A' : 'No' ) . ' module is sent to the user.' ); @@ -252,7 +258,7 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase { public function testConflictsWithNavPopupsGadget() { $integrationMock = $this->createMock( PopupsGadgetsIntegration::class ); - $user = $this->getTestUser()->getUser(); + $user = $this->createMock( User::class ); $integrationMock->expects( $this->once() ) ->method( 'conflictsWithNavPopupsGadget' ) @@ -301,7 +307,7 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase { $this->assertSame( $expected, - $contextMock->getConfigBitmaskFromUser( $this->getTestUser()->getUser() ) + $contextMock->getConfigBitmaskFromUser( $this->createMock( User::class ) ) ); } diff --git a/tests/phpunit/unit/PopupsGadgetsIntegrationTest.php b/tests/phpunit/PopupsGadgetsIntegrationTest.php similarity index 98% rename from tests/phpunit/unit/PopupsGadgetsIntegrationTest.php rename to tests/phpunit/PopupsGadgetsIntegrationTest.php index 771945734..9d6522689 100644 --- a/tests/phpunit/unit/PopupsGadgetsIntegrationTest.php +++ b/tests/phpunit/PopupsGadgetsIntegrationTest.php @@ -27,7 +27,7 @@ use Popups\PopupsGadgetsIntegration; * @group Popups * @coversDefaultClass \Popups\PopupsGadgetsIntegration */ -class PopupsGadgetsIntegrationTest extends MediaWikiUnitTestCase { +class PopupsGadgetsIntegrationTest extends MediaWikiIntegrationTestCase { /** * Gadget name for testing diff --git a/tests/phpunit/PopupsHooksTest.php b/tests/phpunit/PopupsHooksTest.php index affcc3aba..bd0adde44 100644 --- a/tests/phpunit/PopupsHooksTest.php +++ b/tests/phpunit/PopupsHooksTest.php @@ -46,7 +46,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); ( new PopupsHooks( $userOptionsManager ) ) - ->onGetPreferences( $this->getTestUser()->getUser(), $prefs ); + ->onGetPreferences( $this->createMock( User::class ), $prefs ); $this->assertCount( 1, $prefs, 'No preferences are retrieved.' ); $this->assertSame( 'notEmpty', $prefs[ 'someNotEmptyValue'], @@ -57,7 +57,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { * @covers ::onGetPreferences */ public function testOnGetPreferencesNavPopupGadgetIsOn() { - $userMock = $this->getTestUser()->getUser(); + $userMock = $this->createMock( User::class ); $contextMock = $this->createMock( PopupsContext::class ); $contextMock->expects( $this->once() ) @@ -73,7 +73,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); ( new PopupsHooks( $userOptionsManager ) ) - ->onGetPreferences( $this->getTestUser()->getUser(), $prefs ); + ->onGetPreferences( $userMock, $prefs ); $this->assertArrayHasKey( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $prefs, 'The opt-in preference is retrieved.' ); @@ -108,7 +108,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); ( new PopupsHooks( $userOptionsManager ) ) - ->onGetPreferences( $this->getTestUser()->getUser(), $prefs ); + ->onGetPreferences( $this->createMock( User::class ), $prefs ); $this->assertGreaterThan( 3, count( $prefs ), 'A preference is retrieved.' ); $this->assertSame( 'notEmpty', $prefs[ 'someNotEmptyValue'], @@ -142,7 +142,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); ( new PopupsHooks( $userOptionsManager ) ) - ->onGetPreferences( $this->getTestUser()->getUser(), $prefs ); + ->onGetPreferences( $this->createMock( User::class ), $prefs ); $this->assertGreaterThan( 2, count( $prefs ), 'A preference is retrieved.' ); $this->assertArrayHasKey( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $prefs,