mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-30 10:25:00 +00:00
Merge "Avoid using TestUser in non-Database tests"
This commit is contained in:
commit
0c1fc73908
|
@ -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 ) )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use Popups\PopupsGadgetsIntegration;
|
|||
* @group Popups
|
||||
* @coversDefaultClass \Popups\PopupsGadgetsIntegration
|
||||
*/
|
||||
class PopupsGadgetsIntegrationTest extends MediaWikiUnitTestCase {
|
||||
class PopupsGadgetsIntegrationTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
/**
|
||||
* Gadget name for testing
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue