mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-12 14:35:28 +00:00
d78af2c0e9
This is more a proof of concept. The PHP code in this codebase is rather small, but not trivial, and worth being covered by tests. Change-Id: I20c713c3c3be5d289947a343cd4fbf5256234a4a
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\VisualEditor\Tests;
|
|
|
|
use MediaWiki\Extension\VisualEditor\VisualEditorHookRunner;
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
use MediaWiki\Page\PageIdentityValue;
|
|
use MediaWiki\User\UserIdentityValue;
|
|
use MediaWikiUnitTestCase;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\VisualEditor\VisualEditorHookRunner
|
|
*/
|
|
class VisualEditorHookRunnerTest extends MediaWikiUnitTestCase {
|
|
|
|
public function testPreSaveHook() {
|
|
$container = $this->createNoOpMock( HookContainer::class, [ 'run' ] );
|
|
$container->expects( $this->once() )
|
|
->method( 'run' )
|
|
->with(
|
|
'VisualEditorApiVisualEditorEditPreSave',
|
|
$this->isType( 'array' ),
|
|
[ 'abortable' => true ]
|
|
)
|
|
->willReturn( true );
|
|
$runner = new VisualEditorHookRunner( $container );
|
|
|
|
$apiResponse = [];
|
|
$result = $runner->onVisualEditorApiVisualEditorEditPreSave(
|
|
PageIdentityValue::localIdentity( 0, 0, 'test' ),
|
|
UserIdentityValue::newAnonymous( '' ),
|
|
'',
|
|
[],
|
|
[],
|
|
$apiResponse
|
|
);
|
|
$this->assertTrue( $result );
|
|
}
|
|
|
|
public function testPostSaveHook() {
|
|
$container = $this->createNoOpMock( HookContainer::class, [ 'run' ] );
|
|
$container->expects( $this->once() )
|
|
->method( 'run' )
|
|
->with(
|
|
'VisualEditorApiVisualEditorEditPostSave',
|
|
$this->isType( 'array' ),
|
|
[ 'abortable' => false ]
|
|
);
|
|
$runner = new VisualEditorHookRunner( $container );
|
|
|
|
$apiResponse = [];
|
|
$runner->onVisualEditorApiVisualEditorEditPostSave(
|
|
PageIdentityValue::localIdentity( 0, 0, 'test' ),
|
|
UserIdentityValue::newAnonymous( '' ),
|
|
'',
|
|
[],
|
|
[],
|
|
[],
|
|
$apiResponse
|
|
);
|
|
}
|
|
|
|
}
|