2018-07-03 21:25:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CodeMirror\Tests;
|
|
|
|
|
2020-10-08 08:18:20 +00:00
|
|
|
use CodeMirrorHooks;
|
2018-07-03 21:25:01 +00:00
|
|
|
use MediaWikiTestCase;
|
|
|
|
use RequestContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group CodeMirror
|
|
|
|
*/
|
|
|
|
class HookTest extends MediaWikiTestCase {
|
2020-10-08 08:18:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \CodeMirrorHooks::isCodeMirrorOnPage
|
|
|
|
* @covers \CodeMirrorHooks::onBeforePageDisplay
|
|
|
|
*/
|
|
|
|
public function testOnBeforePageDisplay() {
|
|
|
|
$wikiPage = new \WikiPage( \Title::makeTitle( NS_MAIN, __FUNCTION__ ) );
|
|
|
|
$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 );
|
|
|
|
$user->method( 'getOption' )->willReturn( true );
|
|
|
|
|
|
|
|
$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__ ) );
|
|
|
|
$kinds = $user->getOptionKinds( RequestContext::getMain(), [ 'usecodemirror' => 1 ] );
|
|
|
|
self::assertEquals( 'registered', $kinds['usecodemirror'] );
|
|
|
|
}
|
|
|
|
}
|