2018-07-03 21:25:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CodeMirror\Tests;
|
|
|
|
|
2020-10-08 08:18:20 +00:00
|
|
|
use CodeMirrorHooks;
|
2021-05-03 10:43:35 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-11-29 18:49:29 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
2021-10-12 19:29:45 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2018-07-03 21:25:01 +00:00
|
|
|
use RequestContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group CodeMirror
|
|
|
|
*/
|
2021-10-12 19:29:45 +00:00
|
|
|
class HookTest extends MediaWikiIntegrationTestCase {
|
2020-10-08 08:18:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \CodeMirrorHooks::isCodeMirrorOnPage
|
|
|
|
* @covers \CodeMirrorHooks::onBeforePageDisplay
|
|
|
|
*/
|
|
|
|
public function testOnBeforePageDisplay() {
|
2021-01-27 07:41:27 +00:00
|
|
|
$wikiPage = new \WikiPage( \Title::makeTitle( NS_MAIN, __METHOD__ ) );
|
2020-10-08 08:18:20 +00:00
|
|
|
$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 );
|
2021-11-29 18:49:29 +00:00
|
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$userOptionsLookup->method( 'getOption' )->willReturn( true );
|
|
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
2020-10-08 08:18:20 +00:00
|
|
|
|
|
|
|
$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 ) );
|
|
|
|
}
|
|
|
|
|
2018-07-03 21:25:01 +00:00
|
|
|
/**
|
2020-10-08 08:18:20 +00:00
|
|
|
* @covers \CodeMirrorHooks::onGetPreferences
|
2018-07-03 21:25:01 +00:00
|
|
|
*/
|
|
|
|
public function testPreferenceRegistered() {
|
|
|
|
$user = self::getTestUser()->getUser();
|
|
|
|
$this->setMwGlobals( 'wgTitle', \Title::newFromText( __METHOD__ ) );
|
2021-05-03 10:43:35 +00:00
|
|
|
$kinds = MediaWikiServices::getInstance()->getUserOptionsManager()
|
|
|
|
->getOptionKinds( $user, RequestContext::getMain(), [ 'usecodemirror' => 1 ] );
|
2018-07-03 21:25:01 +00:00
|
|
|
self::assertEquals( 'registered', $kinds['usecodemirror'] );
|
|
|
|
}
|
|
|
|
}
|