Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / api / format / ApiFormatXmlTest.php
blob0f8c8ee6c125197019f0cb956f958cc9d5817586
1 <?php
3 /**
4 * @group API
5 * @group Database
6 * @covers ApiFormatXml
7 */
8 class ApiFormatXmlTest extends ApiFormatTestBase {
10 protected $printerName = 'xml';
12 public static function setUpBeforeClass() {
13 parent::setUpBeforeClass();
14 $page = WikiPage::factory( Title::newFromText( 'MediaWiki:ApiFormatXmlTest.xsl' ) );
15 // @codingStandardsIgnoreStart Generic.Files.LineLength
16 $page->doEditContent( new WikitextContent(
17 '<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />'
18 ), 'Summary' );
19 // @codingStandardsIgnoreEnd
20 $page = WikiPage::factory( Title::newFromText( 'MediaWiki:ApiFormatXmlTest' ) );
21 $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' );
22 $page = WikiPage::factory( Title::newFromText( 'ApiFormatXmlTest' ) );
23 $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' );
26 public static function provideGeneralEncoding() {
27 // @codingStandardsIgnoreStart Generic.Files.LineLength
28 return [
29 // Basic types
30 [ [ null, 'a' => null ], '<?xml version="1.0"?><api><_v _idx="0" /></api>' ],
31 [ [ true, 'a' => true ], '<?xml version="1.0"?><api a=""><_v _idx="0">true</_v></api>' ],
32 [ [ false, 'a' => false ], '<?xml version="1.0"?><api><_v _idx="0">false</_v></api>' ],
33 [ [ true, 'a' => true, ApiResult::META_BC_BOOLS => [ 0, 'a' ] ],
34 '<?xml version="1.0"?><api a=""><_v _idx="0">1</_v></api>' ],
35 [ [ false, 'a' => false, ApiResult::META_BC_BOOLS => [ 0, 'a' ] ],
36 '<?xml version="1.0"?><api><_v _idx="0"></_v></api>' ],
37 [ [ 42, 'a' => 42 ], '<?xml version="1.0"?><api a="42"><_v _idx="0">42</_v></api>' ],
38 [ [ 42.5, 'a' => 42.5 ], '<?xml version="1.0"?><api a="42.5"><_v _idx="0">42.5</_v></api>' ],
39 [ [ 1e42, 'a' => 1e42 ], '<?xml version="1.0"?><api a="1.0E+42"><_v _idx="0">1.0E+42</_v></api>' ],
40 [ [ 'foo', 'a' => 'foo' ], '<?xml version="1.0"?><api a="foo"><_v _idx="0">foo</_v></api>' ],
41 [ [ 'fóo', 'a' => 'fóo' ], '<?xml version="1.0"?><api a="fóo"><_v _idx="0">fóo</_v></api>' ],
43 // Arrays and objects
44 [ [ [] ], '<?xml version="1.0"?><api><_v /></api>' ],
45 [ [ [ 'x' => 1 ] ], '<?xml version="1.0"?><api><_v x="1" /></api>' ],
46 [ [ [ 2 => 1 ] ], '<?xml version="1.0"?><api><_v><_v _idx="2">1</_v></_v></api>' ],
47 [ [ (object)[] ], '<?xml version="1.0"?><api><_v /></api>' ],
48 [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], '<?xml version="1.0"?><api><_v><_v _idx="0">1</_v></_v></api>' ],
49 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], '<?xml version="1.0"?><api><_v><_v>1</_v></_v></api>' ],
50 [ [ [ 'x' => 1, 'y' => [ 'z' => 1 ], ApiResult::META_TYPE => 'kvp' ] ],
51 '<?xml version="1.0"?><api><_v><_v _name="x" xml:space="preserve">1</_v><_v _name="y"><z xml:space="preserve">1</z></_v></_v></api>' ],
52 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp', ApiResult::META_INDEXED_TAG_NAME => 'i', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
53 '<?xml version="1.0"?><api><_v><i key="x" xml:space="preserve">1</i></_v></api>' ],
54 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
55 '<?xml version="1.0"?><api><_v><_v key="x" xml:space="preserve">1</_v></_v></api>' ],
56 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], '<?xml version="1.0"?><api><_v x="1" /></api>' ],
57 [ [ [ 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ] ], '<?xml version="1.0"?><api><_v><_v _idx="0">a</_v><_v _idx="1">b</_v></_v></api>' ],
59 // Content
60 [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
61 '<?xml version="1.0"?><api xml:space="preserve">foo</api>' ],
63 // Specified element name
64 [ [ 'foo', 'bar', ApiResult::META_INDEXED_TAG_NAME => 'itn' ],
65 '<?xml version="1.0"?><api><itn>foo</itn><itn>bar</itn></api>' ],
67 // Subelements
68 [ [ 'a' => 1, 's' => 1, '_subelements' => [ 's' ] ],
69 '<?xml version="1.0"?><api a="1"><s xml:space="preserve">1</s></api>' ],
71 // Content and subelement
72 [ [ 'a' => 1, 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
73 '<?xml version="1.0"?><api a="1" xml:space="preserve">foo</api>' ],
74 [ [ 's' => [], 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
75 '<?xml version="1.0"?><api><s /><content xml:space="preserve">foo</content></api>' ],
78 's' => 1,
79 'content' => 'foo',
80 ApiResult::META_CONTENT => 'content',
81 ApiResult::META_SUBELEMENTS => [ 's' ]
83 '<?xml version="1.0"?><api><s xml:space="preserve">1</s><content xml:space="preserve">foo</content></api>'
86 // BC Subelements
87 [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
88 '<?xml version="1.0"?><api><foo xml:space="preserve">foo</foo></api>' ],
90 // Name mangling
91 [ [ 'foo.bar' => 1 ], '<?xml version="1.0"?><api foo.bar="1" />' ],
92 [ [ '' => 1 ], '<?xml version="1.0"?><api _="1" />' ],
93 [ [ 'foo bar' => 1 ], '<?xml version="1.0"?><api _foo.20.bar="1" />' ],
94 [ [ 'foo:bar' => 1 ], '<?xml version="1.0"?><api _foo.3A.bar="1" />' ],
95 [ [ 'foo%.bar' => 1 ], '<?xml version="1.0"?><api _foo.25..2E.bar="1" />' ],
96 [ [ '4foo' => 1, 'foo4' => 1 ], '<?xml version="1.0"?><api _4foo="1" foo4="1" />' ],
97 [ [ "foo\xe3\x80\x80bar" => 1 ], '<?xml version="1.0"?><api _foo.3000.bar="1" />' ],
98 [ [ 'foo:bar' => 1, ApiResult::META_PRESERVE_KEYS => [ 'foo:bar' ] ],
99 '<?xml version="1.0"?><api foo:bar="1" />' ],
100 [ [ 'a', 'b', ApiResult::META_INDEXED_TAG_NAME => 'foo bar' ],
101 '<?xml version="1.0"?><api><_foo.20.bar>a</_foo.20.bar><_foo.20.bar>b</_foo.20.bar></api>' ],
103 // includenamespace param
104 [ [ 'x' => 'foo' ], '<?xml version="1.0"?><api x="foo" xmlns="http://www.mediawiki.org/xml/api/" />',
105 [ 'includexmlnamespace' => 1 ] ],
107 // xslt param
108 [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Invalid or non-existent stylesheet specified.</xml></warnings></api>',
109 [ 'xslt' => 'DoesNotExist' ] ],
110 [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Stylesheet should be in the MediaWiki namespace.</xml></warnings></api>',
111 [ 'xslt' => 'ApiFormatXmlTest' ] ],
112 [ [], '<?xml version="1.0"?><api><warnings><xml xml:space="preserve">Stylesheet should have &quot;.xsl&quot; extension.</xml></warnings></api>',
113 [ 'xslt' => 'MediaWiki:ApiFormatXmlTest' ] ],
114 [ [],
115 '<?xml version="1.0"?><?xml-stylesheet href="' .
116 htmlspecialchars( Title::newFromText( 'MediaWiki:ApiFormatXmlTest.xsl' )->getLocalURL( 'action=raw' ) ) .
117 '" type="text/xsl" ?><api />',
118 [ 'xslt' => 'MediaWiki:ApiFormatXmlTest.xsl' ] ],
120 // @codingStandardsIgnoreEnd