doEditContent( new WikitextContent( '' ), 'Summary' ); $page = WikiPage::factory( Title::newFromText( 'MediaWiki:ApiFormatXmlTest' ) ); $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' ); $page = WikiPage::factory( Title::newFromText( 'ApiFormatXmlTest' ) ); $page->doEditContent( new WikitextContent( 'Bogus' ), 'Summary' ); } public static function provideGeneralEncoding() { $tests = array( // Basic types array( array( null ), '' ), array( array( true, 'a' => true ), '1' ), array( array( false, 'a' => false ), '' ), array( array( 42, 'a' => 42 ), '42' ), array( array( 42.5, 'a' => 42.5 ), '42.5' ), array( array( 1e42, 'a' => 1e42 ), '1.0E+42' ), array( array( 'foo', 'a' => 'foo' ), 'foo' ), array( array( 'fóo', 'a' => 'fóo' ), 'fóo' ), // Arrays and objects array( array( array() ), '' ), array( array( array( 'x' => 1 ) ), '' ), array( array( array( 2 => 1, '_element' => 'x' ) ), '1' ), // Content array( array( '*' => 'foo' ), 'foo' ), // Subelements array( array( 'a' => 1, 's' => 1, '_subelements' => array( 's' ) ), '1' ), // includenamespace param array( array( 'x' => 'foo' ), '', array( 'includexmlnamespace' => 1 ) ), // xslt param array( array(), 'Invalid or non-existent stylesheet specified', array( 'xslt' => 'DoesNotExist' ) ), array( array(), 'Stylesheet should be in the MediaWiki namespace.', array( 'xslt' => 'ApiFormatXmlTest' ) ), array( array(), 'Stylesheet should have .xsl extension.', array( 'xslt' => 'MediaWiki:ApiFormatXmlTest' ) ), array( array(), 'getLocalURL( 'action=raw' ) ) . '" type="text/xsl" ?>', array( 'xslt' => 'MediaWiki:ApiFormatXmlTest.xsl' ) ), ); // Add in the needed "_element" for all indexed arrays $ret = array(); foreach ( $tests as $v ) { $v[0] += array( '_element' => 'x' ); $ret[] = $v; } return $ret; } /** * @dataProvider provideXmlFail */ public function testXmlFail( array $data, $expect, array $params = array() ) { try { echo $this->encodeData( $params, $data ) . "\n"; $this->fail( "Expected exception not thrown" ); } catch ( MWException $ex ) { $this->assertSame( $expect, $ex->getMessage(), 'Expected exception' ); } } public static function provideXmlFail() { return array( // Array without _element array( array( 1 ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName().' ), // Content and subelement array( array( 1, 's' => array(), '*' => 2, '_element' => 'x' ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has content and subelements' ), array( array( 1, 's' => 1, '*' => 2, '_element' => 'x', '_subelements' => array( 's' ) ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has content and subelements' ), // These should fail but don't because of a long-standing bug (see T57371#639713) //array( array( 1, '*' => 2, '_element' => 'x' ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has content and subelements' ), //array( array( 's' => array(), '*' => 2 ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has content and subelements' ), //array( array( 's' => 1, '*' => 2, '_subelements' => array( 's' ) ), 'Internal error in ApiFormatXml::recXmlPrint: (api, ...) has content and subelements' ), ); } }