From 0ed6cafb3b0b609add2bbc451d5f4b884ecff838 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 1 Oct 2024 09:01:52 +0200 Subject: [PATCH] Use more narrow UserIdentity interface where possible Change-Id: I766eaa904a9eaeb7ac2a32a98289a364b1c25355 --- src/ReferencePreviews/ReferencePreviewsContext.php | 4 ++-- .../ReferencePreviewsGadgetsIntegration.php | 5 ++--- .../ReferencePreviewsGadgetsIntegrationTest.php | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ReferencePreviews/ReferencePreviewsContext.php b/src/ReferencePreviews/ReferencePreviewsContext.php index ef9134739..ac98bd5cb 100644 --- a/src/ReferencePreviews/ReferencePreviewsContext.php +++ b/src/ReferencePreviews/ReferencePreviewsContext.php @@ -52,7 +52,7 @@ class ReferencePreviewsContext { // Anonymous users can (de)activate the feature via a cookie at runtime, hence it must load return !$user->isNamed() || $this->userOptionsLookup->getBoolOption( - $user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME - ); + $user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME + ); } } diff --git a/src/ReferencePreviews/ReferencePreviewsGadgetsIntegration.php b/src/ReferencePreviews/ReferencePreviewsGadgetsIntegration.php index befa6fb9b..1fcc065d2 100644 --- a/src/ReferencePreviews/ReferencePreviewsGadgetsIntegration.php +++ b/src/ReferencePreviews/ReferencePreviewsGadgetsIntegration.php @@ -5,7 +5,6 @@ namespace Cite\ReferencePreviews; use InvalidArgumentException; use MediaWiki\Config\Config; use MediaWiki\Extension\Gadgets\GadgetRepo; -use MediaWiki\User\User; use MediaWiki\User\UserIdentity; /** @@ -50,11 +49,11 @@ class ReferencePreviewsGadgetsIntegration { return false; } - public function isNavPopupsGadgetEnabled( User $user ): bool { + public function isNavPopupsGadgetEnabled( UserIdentity $user ): bool { return $this->isGadgetEnabled( $user, $this->navPopupsGadgetName ); } - public function isRefTooltipsGadgetEnabled( User $user ): bool { + public function isRefTooltipsGadgetEnabled( UserIdentity $user ): bool { return $this->isGadgetEnabled( $user, $this->refTooltipsGadgetName ); } diff --git a/tests/phpunit/integration/ReferencePreviews/ReferencePreviewsGadgetsIntegrationTest.php b/tests/phpunit/integration/ReferencePreviews/ReferencePreviewsGadgetsIntegrationTest.php index 68cffaeaa..cf80bd05f 100644 --- a/tests/phpunit/integration/ReferencePreviews/ReferencePreviewsGadgetsIntegrationTest.php +++ b/tests/phpunit/integration/ReferencePreviews/ReferencePreviewsGadgetsIntegrationTest.php @@ -8,7 +8,7 @@ use MediaWiki\Config\Config; use MediaWiki\Config\HashConfig; use MediaWiki\Extension\Gadgets\Gadget; use MediaWiki\Extension\Gadgets\GadgetRepo; -use MediaWiki\User\User; +use MediaWiki\User\UserIdentity; use MediaWikiIntegrationTestCase; /** @@ -44,7 +44,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa $this->getConfig(), null ) ) - ->isNavPopupsGadgetEnabled( $this->createNoOpMock( User::class ) ), + ->isNavPopupsGadgetEnabled( $this->createNoOpMock( UserIdentity::class ) ), 'No conflict is identified.' ); } @@ -58,7 +58,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa ->willReturn( [] ); $this->executeIsNavPopupsGadgetEnabled( - $this->createNoOpMock( User::class ), + $this->createNoOpMock( UserIdentity::class ), $this->getConfig(), $gadgetRepoMock, self::GADGET_DISABLED @@ -68,7 +68,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa public function testConflictsWithNavPopupsGadgetIfGadgetExists() { $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); - $user = $this->createMock( User::class ); + $user = $this->createMock( UserIdentity::class ); $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) @@ -109,7 +109,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa ->willThrowException( new InvalidArgumentException() ); $this->executeIsNavPopupsGadgetEnabled( - $this->createNoOpMock( User::class ), + $this->createNoOpMock( UserIdentity::class ), $this->getConfig(), $gadgetRepoMock, self::GADGET_DISABLED @@ -137,7 +137,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa ->willReturn( $gadgetMock ); $this->executeIsNavPopupsGadgetEnabled( - $this->createNoOpMock( User::class ), + $this->createNoOpMock( UserIdentity::class ), $this->getConfig( $gadgetName ), $gadgetRepoMock, self::GADGET_ENABLED @@ -151,7 +151,7 @@ class ReferencePreviewsGadgetsIntegrationTest extends MediaWikiIntegrationTestCa } private function executeIsNavPopupsGadgetEnabled( - User $user, + UserIdentity $user, Config $config, GadgetRepo $repoMock, bool $expected