2022-08-29 10:44:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\VisualEditor\Tests;
|
|
|
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2022-09-04 09:00:14 +00:00
|
|
|
use MediaWiki\Extension\VisualEditor\DirectParsoidClient;
|
2022-10-19 12:43:26 +00:00
|
|
|
use MediaWiki\Extension\VisualEditor\DualParsoidClient;
|
2022-08-29 10:44:06 +00:00
|
|
|
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
|
|
|
|
use MediaWiki\Http\HttpRequestFactory;
|
2022-10-19 12:43:26 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2023-01-16 13:11:20 +00:00
|
|
|
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
|
2022-08-29 10:44:06 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
use MultiHttpClient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory
|
|
|
|
*/
|
|
|
|
class VisualEditorParsoidClientFactoryTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::__construct
|
|
|
|
*/
|
|
|
|
public function testGetVisualEditorParsoidClientFactory() {
|
|
|
|
$veParsoidClientFactory = $this->getServiceContainer()
|
|
|
|
->get( VisualEditorParsoidClientFactory::SERVICE_NAME );
|
|
|
|
|
|
|
|
$this->assertInstanceOf( VisualEditorParsoidClientFactory::class, $veParsoidClientFactory );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function newClientFactory( array $optionValues ) {
|
|
|
|
$options = new ServiceOptions( VisualEditorParsoidClientFactory::CONSTRUCTOR_OPTIONS, $optionValues );
|
|
|
|
|
|
|
|
$httpRequestFactory = $this->createNoOpMock( HttpRequestFactory::class, [ 'createMultiClient' ] );
|
|
|
|
$httpRequestFactory->method( 'createMultiClient' )->willReturn(
|
|
|
|
$this->createNoOpMock( MultiHttpClient::class )
|
|
|
|
);
|
|
|
|
|
|
|
|
return new VisualEditorParsoidClientFactory(
|
|
|
|
$options,
|
2022-11-18 19:46:23 +00:00
|
|
|
$this->createNoOpMock( PageRestHelperFactory::class )
|
2022-08-29 10:44:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-19 12:43:26 +00:00
|
|
|
* @covers ::createParsoidClientInternal
|
2022-09-04 09:00:14 +00:00
|
|
|
* @covers ::createParsoidClient
|
2022-08-29 10:44:06 +00:00
|
|
|
*/
|
2023-07-10 07:57:45 +00:00
|
|
|
public function testGetClient() {
|
2022-10-19 12:43:26 +00:00
|
|
|
$authority = $this->createNoOpMock( Authority::class );
|
2022-08-29 10:44:06 +00:00
|
|
|
|
2023-07-10 07:57:45 +00:00
|
|
|
$factory = $this->newClientFactory( [
|
|
|
|
VisualEditorParsoidClientFactory::ENABLE_COOKIE_FORWARDING => false,
|
|
|
|
VisualEditorParsoidClientFactory::DEFAULT_PARSOID_CLIENT_SETTING => 'direct',
|
|
|
|
] );
|
2022-10-13 10:05:13 +00:00
|
|
|
|
2023-07-10 07:57:45 +00:00
|
|
|
$client = $factory->createParsoidClientInternal( $authority );
|
|
|
|
$this->assertInstanceOf( DirectParsoidClient::class, $client );
|
2022-10-19 12:43:26 +00:00
|
|
|
|
|
|
|
// This just checks that nothing explodes.
|
|
|
|
$client = $factory->createParsoidClient( false, $authority );
|
|
|
|
$this->assertInstanceOf( DualParsoidClient::class, $client );
|
2022-08-29 10:44:06 +00:00
|
|
|
}
|
|
|
|
}
|