2021-08-20 12:31:07 +00:00
|
|
|
<?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 = [];
|
2022-03-27 20:41:20 +00:00
|
|
|
$params = [];
|
2021-08-20 12:31:07 +00:00
|
|
|
$result = $runner->onVisualEditorApiVisualEditorEditPreSave(
|
|
|
|
PageIdentityValue::localIdentity( 0, 0, 'test' ),
|
|
|
|
UserIdentityValue::newAnonymous( '' ),
|
|
|
|
'',
|
2022-03-27 20:41:20 +00:00
|
|
|
$params,
|
2021-08-20 12:31:07 +00:00
|
|
|
[],
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|