2018-07-03 21:25:01 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-06 15:13:05 +00:00
|
|
|
namespace MediaWiki\Extension\CodeMirror\Tests;
|
2018-07-03 21:25:01 +00:00
|
|
|
|
2022-02-06 15:13:05 +00:00
|
|
|
use MediaWiki\Extension\CodeMirror\Hooks;
|
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
|
|
|
|
|
|
|
/**
|
2022-02-06 15:13:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\CodeMirror\Hooks::isCodeMirrorOnPage
|
|
|
|
* @covers \MediaWiki\Extension\CodeMirror\Hooks::onBeforePageDisplay
|
2020-10-08 08:18:20 +00:00
|
|
|
*/
|
|
|
|
public function testOnBeforePageDisplay() {
|
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( [] );
|
2022-04-15 20:46:08 +00:00
|
|
|
$out->method( 'getUser' )->willReturn( $this->createMock( \User::class ) );
|
|
|
|
$out->method( 'getActionName' )->willReturn( 'edit' );
|
|
|
|
$out->method( 'getTitle' )->willReturn( \Title::makeTitle( NS_MAIN, __METHOD__ ) );
|
2020-10-08 08:18:20 +00:00
|
|
|
$out->expects( $this->exactly( 2 ) )->method( 'addModules' );
|
|
|
|
|
2022-02-06 15:13:05 +00:00
|
|
|
Hooks::onBeforePageDisplay( $out, $this->createMock( \Skin::class ) );
|
2020-10-08 08:18:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 21:25:01 +00:00
|
|
|
/**
|
2022-02-06 15:13:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\CodeMirror\Hooks::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'] );
|
|
|
|
}
|
|
|
|
}
|