Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4115563
ApiVisualEditorTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ApiVisualEditorTest.php
View Options
<?php
namespace
MediaWiki\Extension\VisualEditor\Tests
;
use
MediaWiki\Config\HashConfig
;
use
MediaWiki\Extension\VisualEditor\ApiVisualEditor
;
use
MediaWiki\Registration\ExtensionRegistry
;
use
MediaWiki\Tests\Api\ApiTestCase
;
use
Wikimedia\ScopedCallback
;
/**
* @group medium
* @group Database
*
* @covers \MediaWiki\Extension\VisualEditor\ApiVisualEditor
*/
class
ApiVisualEditorTest
extends
ApiTestCase
{
/** @var ScopedCallback|null */
private
$scopedCallback
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
scopedCallback
=
ExtensionRegistry
::
getInstance
()->
setAttributeForTest
(
'VisualEditorAvailableNamespaces'
,
[
'User'
=>
true
,
'Template_Talk'
=>
true
]
);
}
protected
function
tearDown
():
void
{
$this
->
scopedCallback
=
null
;
parent
::
tearDown
();
}
private
function
loadEditor
(
array
$overrideParams
=
[]
):
array
{
$params
=
array_merge
(
[
'action'
=>
'visualeditor'
,
'paction'
=>
'metadata'
,
'page'
=>
'SomeTestPage'
,
],
$overrideParams
);
return
$this
->
doApiRequestWithToken
(
$params
);
}
public
function
testLoadEditorBasic
()
{
$data
=
$this
->
loadEditor
()[
0
][
'visualeditor'
];
$this
->
assertSame
(
'success'
,
$data
[
'result'
]
);
$properties
=
[
// When updating this, also update the sample response in
// ve.init.mw.DesktopArticleTarget.test.js
'result'
,
'notices'
,
'copyrightWarning'
,
'checkboxesDef'
,
'checkboxesMessages'
,
'protectedClasses'
,
'basetimestamp'
,
'starttimestamp'
,
'oldid'
,
'blockinfo'
,
'wouldautocreate'
,
'canEdit'
,
'content'
,
'preloaded'
,
// When updating this, also update the sample response in
// ve.init.mw.DesktopArticleTarget.test.js
];
foreach
(
$properties
as
$prop
)
{
$this
->
assertArrayHasKey
(
$prop
,
$data
,
"Result has key '$prop'"
);
}
$this
->
assertSameSize
(
$properties
,
$data
,
"No other properties are expected"
);
}
/**
* @dataProvider provideLoadEditorPreload
*/
public
function
testLoadEditorPreload
(
bool
$useMyLanguage
)
{
$content
=
'Some test page content'
;
$pageTitle
=
'Test VE preload'
;
$this
->
editPage
(
$pageTitle
,
$content
);
$params
=
[
'preload'
=>
$useMyLanguage
?
"Special:MyLanguage/$pageTitle"
:
$pageTitle
,
'paction'
=>
'wikitext'
,
];
// NB The page isn't actually translated, so we get the same content back.
$this
->
assertSame
(
$content
,
$this
->
loadEditor
(
$params
)[
0
][
'visualeditor'
][
'content'
]
);
}
public
static
function
provideLoadEditorPreload
()
{
return
[
'load with preload content'
=>
[
false
],
'load with preload via Special:MyLanguage'
=>
[
true
],
];
}
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
,
2
=>
false
,
'Template'
=>
true
,
'Foobar'
=>
true
,
]
]
);
$this
->
assertSame
(
[
-
1
,
0
,
10
,
11
],
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'
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 00:55 (1 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bb/3c/938fbd2af8a0db0b271989ce899b
Default Alt Text
ApiVisualEditorTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment