| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\VisualEditor\Tests; |
| 4 |
|
| 5 |
use MediaWiki\Extension\VisualEditor\VisualEditorHookRunner; |
| 6 |
use MediaWiki\HookContainer\HookContainer; |
| 7 |
use MediaWiki\Page\PageIdentityValue; |
| 8 |
use MediaWiki\User\UserIdentityValue; |
| 9 |
use MediaWikiUnitTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class VisualEditorHookRunnerTest extends MediaWikiUnitTestCase { |
| 15 |
|
| 16 |
public function testPreSaveHook() { |
| 17 |
$container = $this->createNoOpMock( HookContainer::class, [ 'run' ] ); |
| 18 |
$container->expects( $this->once() ) |
| 19 |
->method( 'run' ) |
| 20 |
->with( |
| 21 |
'VisualEditorApiVisualEditorEditPreSave', |
| 22 |
$this->isType( 'array' ), |
| 23 |
[ 'abortable' => true ] |
| 24 |
) |
| 25 |
->willReturn( true ); |
| 26 |
$runner = new VisualEditorHookRunner( $container ); |
| 27 |
|
| 28 |
$apiResponse = []; |
| 29 |
$params = []; |
| 30 |
$result = $runner->onVisualEditorApiVisualEditorEditPreSave( |
| 31 |
PageIdentityValue::localIdentity( 0, 0, 'test' ), |
| 32 |
UserIdentityValue::newAnonymous( '' ), |
| 33 |
'', |
| 34 |
$params, |
| 35 |
[], |
| 36 |
$apiResponse |
| 37 |
); |
| 38 |
$this->assertTrue( $result ); |
| 39 |
} |
| 40 |
|
| 41 |
public function testPostSaveHook() { |
| 42 |
$container = $this->createNoOpMock( HookContainer::class, [ 'run' ] ); |
| 43 |
$container->expects( $this->once() ) |
| 44 |
->method( 'run' ) |
| 45 |
->with( |
| 46 |
'VisualEditorApiVisualEditorEditPostSave', |
| 47 |
$this->isType( 'array' ), |
| 48 |
[ 'abortable' => false ] |
| 49 |
); |
| 50 |
$runner = new VisualEditorHookRunner( $container ); |
| 51 |
|
| 52 |
$apiResponse = []; |
| 53 |
$runner->onVisualEditorApiVisualEditorEditPostSave( |
| 54 |
PageIdentityValue::localIdentity( 0, 0, 'test' ), |
| 55 |
UserIdentityValue::newAnonymous( '' ), |
| 56 |
'', |
| 57 |
[], |
| 58 |
[], |
| 59 |
[], |
| 60 |
$apiResponse |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
} |