Merge "Add missing PHPUnit tests for better coverage"

This commit is contained in:
jenkins-bot 2020-10-28 10:04:49 +00:00 committed by Gerrit Code Review
commit 024b890554
2 changed files with 58 additions and 1 deletions

View file

@ -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();

View 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 );
}
}