mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-15 02:04:02 +00:00
Add missing PHPUnit tests for better coverage
Change-Id: I242aa52a24a11de3db106e5e2c73bd6f2a95d80c
This commit is contained in:
parent
effb782d7e
commit
ff1c26e877
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace CodeMirror\Tests;
|
||||
|
||||
use CodeMirrorHooks;
|
||||
use MediaWikiTestCase;
|
||||
use RequestContext;
|
||||
|
||||
|
@ -9,8 +10,33 @@ use RequestContext;
|
|||
* @group CodeMirror
|
||||
*/
|
||||
class HookTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers CodeMirrorHooks::onGetPreferences()
|
||||
* @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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \CodeMirrorHooks::onGetPreferences
|
||||
*/
|
||||
public function testPreferenceRegistered() {
|
||||
$user = self::getTestUser()->getUser();
|
||||
|
|
31
tests/phpunit/ResourceLoaderCodeMirrorModuleTest.php
Normal file
31
tests/phpunit/ResourceLoaderCodeMirrorModuleTest.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace CodeMirror\Tests;
|
||||
|
||||
use ResourceLoaderCodeMirrorModule;
|
||||
use ResourceLoaderContext;
|
||||
|
||||
/**
|
||||
* @covers \ResourceLoaderCodeMirrorModule
|
||||
*/
|
||||
class ResourceLoaderCodeMirrorModuleTest extends \MediaWikiIntegrationTestCase {
|
||||
|
||||
public function testResourceLoaderModule() {
|
||||
$context = $this->createMock( ResourceLoaderContext::class );
|
||||
$module = new ResourceLoaderCodeMirrorModule();
|
||||
|
||||
$this->assertFalse( $module->supportsURLLoading() );
|
||||
$this->assertTrue( $module->enableModuleContentVersion() );
|
||||
|
||||
$script = $module->getScript( $context );
|
||||
$this->assertStringContainsString( '"extCodeMirrorConfig":', $script );
|
||||
$this->assertStringContainsString( '"pluginModules":', $script );
|
||||
$this->assertStringContainsString( '"tagModes":', $script );
|
||||
$this->assertStringContainsString( '"tags":', $script );
|
||||
$this->assertStringContainsString( '"doubleUnderscore":', $script );
|
||||
$this->assertStringContainsString( '"functionSynonyms":', $script );
|
||||
$this->assertStringContainsString( '"urlProtocols":', $script );
|
||||
$this->assertStringContainsString( '"linkTrailCharacters":', $script );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue