mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-30 17:04:14 +00:00
60b14d1aa0
Replace User::getOption() with UserOptionsLookup::getOption() since this method will be hard-deprecated. Bug: T296083 Change-Id: I405251092fd94fa70a33319d313c5140c8cebc21
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace CodeMirror\Tests;
|
|
|
|
use CodeMirrorHooks;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
use MediaWikiIntegrationTestCase;
|
|
use RequestContext;
|
|
|
|
/**
|
|
* @group CodeMirror
|
|
*/
|
|
class HookTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @covers \CodeMirrorHooks::isCodeMirrorOnPage
|
|
* @covers \CodeMirrorHooks::onBeforePageDisplay
|
|
*/
|
|
public function testOnBeforePageDisplay() {
|
|
$wikiPage = new \WikiPage( \Title::makeTitle( NS_MAIN, __METHOD__ ) );
|
|
$context = $this->createMock( \IContextSource::class );
|
|
$context->method( 'getRequest' )->willReturn( new \FauxRequest( [ 'action' => 'edit' ] ) );
|
|
$context->method( 'canUseWikiPage' )->willReturn( true );
|
|
$context->method( 'getWikiPage' )->willReturn( $wikiPage );
|
|
$context->method( 'getTitle' )->willReturn( $wikiPage->getTitle() );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
$userOptionsLookup->method( 'getOption' )->willReturn( true );
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
|
|
|
$out = $this->createMock( \OutputPage::class );
|
|
$out->method( 'getModules' )->willReturn( [] );
|
|
$out->method( 'getContext' )->willReturn( $context );
|
|
$out->method( 'getUser' )->willReturn( $user );
|
|
$out->expects( $this->exactly( 2 ) )->method( 'addModules' );
|
|
|
|
CodeMirrorHooks::onBeforePageDisplay( $out, $this->createMock( \Skin::class ) );
|
|
}
|
|
|
|
/**
|
|
* @covers \CodeMirrorHooks::onGetPreferences
|
|
*/
|
|
public function testPreferenceRegistered() {
|
|
$user = self::getTestUser()->getUser();
|
|
$this->setMwGlobals( 'wgTitle', \Title::newFromText( __METHOD__ ) );
|
|
$kinds = MediaWikiServices::getInstance()->getUserOptionsManager()
|
|
->getOptionKinds( $user, RequestContext::getMain(), [ 'usecodemirror' => 1 ] );
|
|
self::assertEquals( 'registered', $kinds['usecodemirror'] );
|
|
}
|
|
}
|