{
$content = $pageObj->getContent();
- // @todo: Add support for appending/prepending to the Content interface
-
- if ( !( $content instanceof TextContent ) ) {
- $mode = $contentHandler->getModelID();
- $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
- }
-
if ( !$content ) {
- # If this is a MediaWiki:x message, then load the messages
- # and return the message value for x.
if ( $titleObj->getNamespace() == NS_MEDIAWIKI ) {
+ # If this is a MediaWiki:x message, then load the messages
+ # and return the message value for x.
$text = $titleObj->getDefaultMessageText();
if ( $text === false ) {
$text = '';
$this->dieUsage( $ex->getMessage(), 'parseerror' );
return;
}
+ } else {
+ # Otherwise, make a new empty content.
+ $content = $contentHandler->makeEmptyContent();
}
}
+ // @todo: Add support for appending/prepending to the Content interface
+
+ if ( !( $content instanceof TextContent ) ) {
+ $mode = $contentHandler->getModelID();
+ $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
+ }
+
if ( !is_null( $params['section'] ) ) {
if ( !$contentHandler->supportsSections() ) {
$modelName = $contentHandler->getModelID();
$this->assertEquals( $data, $page->getContent()->serialize() );
}
- function testEditAppend() {
- $this->markTestIncomplete( "not yet implemented" );
+ static function provideEditAppend() {
+ return array(
+ array( #0: append
+ 'foo', 'append', 'bar', "foobar"
+ ),
+ array( #1: prepend
+ 'foo', 'prepend', 'bar', "barfoo"
+ ),
+ array( #2: append to empty page
+ '', 'append', 'foo', "foo"
+ ),
+ array( #3: prepend to empty page
+ '', 'prepend', 'foo', "foo"
+ ),
+ array( #4: append to non-existing page
+ null, 'append', 'foo', "foo"
+ ),
+ array( #5: prepend to non-existing page
+ null, 'prepend', 'foo', "foo"
+ ),
+ );
}
- function testEditSection() {
- $this->markTestIncomplete( "not yet implemented" );
+ /**
+ * @dataProvider provideEditAppend
+ */
+ function testEditAppend( $text, $op, $append, $expected ) {
+ static $count = 0;
+ $count++;
+
+ // assume NS_HELP defaults to wikitext
+ $name = "Help:ApiEditPageTest_testEditAppend_$count";
+
+ // -- create page (or not) -----------------------------------------
+ if ( $text !== null ) {
+ if ( $text === '' ) {
+ // can't create an empty page, so create it with some content
+ list( $re,, ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => '(dummy)', ) );
+ }
+
+ list( $re,, ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => $text, ) );
+
+ $this->assertEquals( 'Success', $re['edit']['result'] ); // sanity
+ }
+
+ // -- try append/prepend --------------------------------------------
+ list( $re,, ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ $op . 'text' => $append, ) );
+
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+
+ // -- validate -----------------------------------------------------
+ $page = new WikiPage( Title::newFromText( $name ) );
+ $content = $page->getContent();
+ $this->assertNotNull( $content, 'Page should have been created' );
+
+ $text = $content->getNativeData();
+
+ $this->assertEquals( $expected, $text );
}
- function testUndo() {
+ function testEditSection() {
$this->markTestIncomplete( "not yet implemented" );
}
- function testEditNonText() {
+ function testUndo() {
$this->markTestIncomplete( "not yet implemented" );
}
}