2021-09-26 19:33:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\VisualEditor\Tests;
|
|
|
|
|
|
|
|
use ApiVisualEditor;
|
|
|
|
use ExtensionRegistry;
|
|
|
|
use HashConfig;
|
|
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
use Wikimedia\ScopedCallback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \ApiVisualEditor
|
|
|
|
*/
|
|
|
|
class ApiVisualEditorTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
/** @var ScopedCallback|null */
|
|
|
|
private $scopedCallback;
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->scopedCallback = ExtensionRegistry::getInstance()->setAttributeForTest(
|
|
|
|
'VisualEditorAvailableNamespaces',
|
2021-10-01 12:00:56 +00:00
|
|
|
[ 'User' => true, 'Template_Talk' => true ]
|
2021-09-26 19:33:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown(): void {
|
|
|
|
$this->scopedCallback = null;
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsAllowedNamespace() {
|
|
|
|
$config = new HashConfig( [ 'VisualEditorAvailableNamespaces' => [
|
|
|
|
0 => true,
|
|
|
|
1 => false,
|
|
|
|
] ] );
|
|
|
|
$this->assertTrue( ApiVisualEditor::isAllowedNamespace( $config, 0 ) );
|
|
|
|
$this->assertFalse( ApiVisualEditor::isAllowedNamespace( $config, 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAvailableNamespaceIds() {
|
|
|
|
$config = new HashConfig( [ 'VisualEditorAvailableNamespaces' => [
|
|
|
|
0 => true,
|
|
|
|
1 => false,
|
|
|
|
-1 => true,
|
|
|
|
999999 => true,
|
2021-10-01 12:00:56 +00:00
|
|
|
2 => false,
|
2021-09-26 19:33:26 +00:00
|
|
|
'Template' => true,
|
|
|
|
'Foobar' => true,
|
|
|
|
] ] );
|
|
|
|
$this->assertSame(
|
2021-10-01 12:00:56 +00:00
|
|
|
[ -1, 0, 10, 11 ],
|
2021-09-26 19:33:26 +00:00
|
|
|
ApiVisualEditor::getAvailableNamespaceIds( $config )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsAllowedContentType() {
|
|
|
|
$config = new HashConfig( [ 'VisualEditorAvailableContentModels' => [
|
|
|
|
'on' => true,
|
|
|
|
'off' => false,
|
|
|
|
] ] );
|
|
|
|
$this->assertTrue( ApiVisualEditor::isAllowedContentType( $config, 'on' ) );
|
|
|
|
$this->assertFalse( ApiVisualEditor::isAllowedContentType( $config, 'off' ) );
|
|
|
|
$this->assertFalse( ApiVisualEditor::isAllowedContentType( $config, 'unknown' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|