diff --git a/tests/phpunit/HookTest.php b/tests/phpunit/HookTest.php index 13ec3c4a..2c2bbca7 100644 --- a/tests/phpunit/HookTest.php +++ b/tests/phpunit/HookTest.php @@ -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(); diff --git a/tests/phpunit/ResourceLoaderCodeMirrorModuleTest.php b/tests/phpunit/ResourceLoaderCodeMirrorModuleTest.php new file mode 100644 index 00000000..80effbba --- /dev/null +++ b/tests/phpunit/ResourceLoaderCodeMirrorModuleTest.php @@ -0,0 +1,31 @@ +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 ); + } + +}