3 namespace MediaWiki\Tests\EditPage
;
5 use MediaWiki\EditPage\PreloadedContentBuilder
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWiki\Permissions\UltimateAuthority
;
8 use MediaWiki\Title\Title
;
9 use MediaWikiIntegrationTestCase
;
12 * @covers \MediaWiki\EditPage\PreloadedContentBuilder
15 class PreloadedContentBuilderTest
extends MediaWikiIntegrationTestCase
{
17 /** @var PreloadedContentBuilder */
18 private $preloadedContentBuilder;
20 protected function setUp(): void
{
21 $services = $this->getServiceContainer();
23 // Needed for the 'Default preload section' test case due to use of wfMessage()
24 $this->overrideConfigValue( MainConfigNames
::UseDatabaseMessages
, true );
26 $this->preloadedContentBuilder
= $services->getPreloadedContentBuilder();
29 public static function provideCases() {
30 // title, preload, preloadParams, section, pages, expectedContent
32 yield
'Non-existent page, no preload' =>
33 [ 'Does-not-exist-asdfasdf', null, [], null, [],
35 yield
'Non-existent page, preload' =>
36 [ 'Does-not-exist-asdfasdf', 'Template:Preload', [], null, [ 'Template:Preload' => 'Preload' ],
38 yield
'Non-existent page, preload with parameters' =>
39 [ 'Does-not-exist-asdfasdf', 'Template:Preloadparams', [ 'a', 'b' ], null, [ 'Template:Preloadparams' => 'Preload $1 $2' ],
42 yield
'Existing page content is ignored (it is not our responsibility)' =>
43 [ 'Exists', null, [], null, [ 'Exists' => 'Hello' ],
45 yield
'Existing page content is ignored (it is not our responsibility), preload' =>
46 [ 'Exists', 'Template:Preload', [], null, [ 'Exists' => 'Hello', 'Template:Preload' => 'Preload' ],
49 yield
'Preload section' =>
50 [ 'Exists', 'Template:Preload', [], 'new', [ 'Exists' => 'Hello', 'Template:Preload' => 'Preload' ],
52 yield
'Default preload section' =>
53 [ 'Exists', null, [], 'new', [ 'Exists' => 'Hello', 'MediaWiki:Addsection-preload' => 'Preloadsection' ],
56 yield
'Non-existent page in MediaWiki: namespace is prefilled with message' =>
57 [ 'MediaWiki:View', null, [], null, [],
59 yield
'Non-existent page in MediaWiki: namespace for non-existent message' =>
60 [ 'MediaWiki:Does-not-exist-asdfasdf', null, [], null, [],
62 yield
'Non-existent page in MediaWiki: namespace does not support preload' =>
63 [ 'MediaWiki:View', 'Template:Preload', [], null, [ 'Template:Preload' => 'Preload' ],
65 yield
'Non-existent message supports preload' =>
66 [ 'MediaWiki:Does-not-exist-asdfasdf', 'Template:Preload', [], null, [ 'Template:Preload' => 'Preload' ],
69 yield
'JSON page in MediaWiki: namespace is prefilled with empty JSON' =>
70 [ 'MediaWiki:Foo.json', null, [], null, [],
73 yield
'Preload using Special:MyLanguage' =>
74 [ 'Does-not-exist-asdfasdf', 'Special:MyLanguage/Template:Preload', [], null, [ 'Template:Preload' => 'Preload' ],
77 yield
'Preload using a localisation message' =>
78 [ 'Does-not-exist-asdfasdf', 'MediaWiki:View', [], null, [],
80 yield
'Preload using a page in mediawiki namespace' =>
81 [ 'Does-not-exist-asdfasdf', 'MediaWiki:For-preloading', [], null, [ 'MediaWiki:For-preloading' => '<noinclude>Noinclude</noinclude><includeonly>Includeonly</includeonly>' ],
84 yield
'Preload over redirect' =>
85 [ 'Does-not-exist-asdfasdf', 'Template:Preload2', [], null, [ 'Template:Preload' => 'Preload', 'Template:Preload2' => '#REDIRECT[[Template:Preload]]' ],
90 * @dataProvider provideCases
92 public function testGetPreloadedContent( $title, $preload, $preloadParams, $section, $pages, $expectedContent ) {
93 foreach ( $pages as $page => $content ) {
94 $this->editPage( $page, $content );
97 $content = $this->preloadedContentBuilder
->getPreloadedContent(
98 Title
::newFromText( $title )->toPageIdentity(),
99 new UltimateAuthority( $this->getTestUser()->getUser() ),
105 $this->assertEquals( $expectedContent, $content->serialize() );