mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-22 11:32:38 +00:00
179d402344
PHP classes and test are somewhat copies from the Popups codebase. Some refactoring was applied. More could be done. Not to sure if this should happen more in follow ups though. Could also reduce the complexity of checks on the JS side. Most of these things can only change on page load. The only dynamic part left is the anon user setting managed by the Popups extension. Note, that I needed to add a new PHP config for here although the other still exists and is needed in the Popups extension. This will change, when the user settings code also moves. I guess it's okay for now though. Both settings default to true and are not overridden in the config repos. Also needed to add the Gadget extension as phan dependency. Bug: T362771 Depends-On: Ia028c41f8aaa1c522dfc7c372e1ce51e40933a5e Change-Id: Ie6e8bc706235724494036c7f0d873f5c996c46e6
93 lines
3 KiB
PHP
93 lines
3 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Integration\ReferencePreviews;
|
|
|
|
use Cite\ReferencePreviews\ReferencePreviewsContext;
|
|
use MediaWiki\Config\HashConfig;
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
|
use MediaWiki\User\User;
|
|
use MediaWikiIntegrationTestCase;
|
|
use Skin;
|
|
|
|
/**
|
|
* @group Popups
|
|
* @coversDefaultClass \Cite\ReferencePreviews\ReferencePreviewsContext
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class ReferencePreviewsContextTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* Tests #shouldSendModuleToUser when the user is logged in and the reference previews feature
|
|
* is disabled.
|
|
*
|
|
* @covers ::isReferencePreviewsEnabled
|
|
* @dataProvider provideIsReferencePreviewsEnabled_requirements
|
|
*/
|
|
public function testIsReferencePreviewsEnabled_requirements( bool $setting, string $skinName, bool $expected ) {
|
|
$config = new HashConfig( [
|
|
'CiteReferencePreviews' => $setting,
|
|
'CiteReferencePreviewsConflictingNavPopupsGadgetName' => '',
|
|
'CiteReferencePreviewsConflictingRefTooltipsGadgetName' => '',
|
|
] );
|
|
$userOptLookup = $this->createNoOpMock( UserOptionsLookup::class );
|
|
|
|
$context = new ReferencePreviewsContext( $config, $userOptLookup );
|
|
|
|
$user = $this->createMock( User::class );
|
|
$user->method( 'isNamed' )->willReturn( false );
|
|
|
|
$skin = $this->createMock( Skin::class );
|
|
$skin->method( 'getSkinName' )->willReturn( $skinName );
|
|
|
|
$this->assertSame( $expected,
|
|
$context->isReferencePreviewsEnabled( $user, $skin ),
|
|
( $expected ? 'A' : 'No' ) . ' module is sent to the user.' );
|
|
}
|
|
|
|
public static function provideIsReferencePreviewsEnabled_requirements() {
|
|
yield [ true, 'minerva', false ];
|
|
yield [ false, 'minerva', false ];
|
|
yield [ true, 'vector', true ];
|
|
yield [ false, 'vector', false ];
|
|
}
|
|
|
|
/**
|
|
* Tests #shouldSendModuleToUser when the user is logged in and the reference previews feature
|
|
* is disabled.
|
|
*
|
|
* @covers ::isReferencePreviewsEnabled
|
|
* @dataProvider provideIsReferencePreviewsEnabled_userOptions
|
|
*/
|
|
public function testIsReferencePreviewsEnabled_userOptions( bool $isNamed, bool $option, bool $expected ) {
|
|
$user = $this->createMock( User::class );
|
|
$user->method( 'isNamed' )->willReturn( $isNamed );
|
|
|
|
$userOptLookup = $this->createMock( UserOptionsLookup::class );
|
|
$userOptLookup->method( 'getBoolOption' )
|
|
->with( $user, ReferencePreviewsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME )
|
|
->willReturn( $option );
|
|
|
|
$config = new HashConfig( [
|
|
'CiteReferencePreviews' => true,
|
|
'CiteReferencePreviewsConflictingNavPopupsGadgetName' => '',
|
|
'CiteReferencePreviewsConflictingRefTooltipsGadgetName' => '',
|
|
] );
|
|
|
|
$context = new ReferencePreviewsContext( $config, $userOptLookup );
|
|
|
|
$skin = $this->createMock( Skin::class );
|
|
|
|
$this->assertSame( $expected,
|
|
$context->isReferencePreviewsEnabled( $user, $skin ),
|
|
( $expected ? 'A' : 'No' ) . ' module is sent to the user.' );
|
|
}
|
|
|
|
public static function provideIsReferencePreviewsEnabled_userOptions() {
|
|
yield [ true, true, true ];
|
|
yield [ true, false, false ];
|
|
yield [ false, false, true ];
|
|
yield [ false, true, true ];
|
|
}
|
|
|
|
}
|