summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/api/ApiEditPageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/api/ApiEditPageTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php107
1 files changed, 86 insertions, 21 deletions
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 1efbaeaf..0c49b12b 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -11,10 +11,10 @@
*/
class ApiEditPageTest extends ApiTestCase {
- public function setup() {
+ public function setUp() {
global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
- parent::setup();
+ parent::setUp();
$wgExtraNamespaces[12312] = 'Dummy';
$wgExtraNamespaces[12313] = 'Dummy_talk';
@@ -28,7 +28,7 @@ class ApiEditPageTest extends ApiTestCase {
$this->doLogin();
}
- public function teardown() {
+ public function tearDown() {
global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
unset( $wgExtraNamespaces[12312] );
@@ -40,10 +40,10 @@ class ApiEditPageTest extends ApiTestCase {
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
- parent::teardown();
+ parent::tearDown();
}
- function testEdit() {
+ public function testEdit() {
$name = 'Help:ApiEditPageTest_testEdit'; // assume Help namespace to default to wikitext
// -- test new page --------------------------------------------
@@ -97,7 +97,7 @@ class ApiEditPageTest extends ApiTestCase {
);
}
- function testNonTextEdit() {
+ public function testNonTextEdit() {
$name = 'Dummy:ApiEditPageTest_testNonTextEdit';
$data = serialize( 'some bla bla text' );
@@ -124,7 +124,7 @@ class ApiEditPageTest extends ApiTestCase {
$this->assertEquals( $data, $page->getContent()->serialize() );
}
- static function provideEditAppend() {
+ public static function provideEditAppend() {
return array(
array( #0: append
'foo', 'append', 'bar', "foobar"
@@ -150,7 +150,7 @@ class ApiEditPageTest extends ApiTestCase {
/**
* @dataProvider provideEditAppend
*/
- function testEditAppend( $text, $op, $append, $expected ) {
+ public function testEditAppend( $text, $op, $append, $expected ) {
static $count = 0;
$count++;
@@ -161,13 +161,13 @@ class ApiEditPageTest extends ApiTestCase {
if ( $text !== null ) {
if ( $text === '' ) {
// can't create an empty page, so create it with some content
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => '(dummy)', ) );
}
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ list( $re ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => $text, ) );
@@ -176,7 +176,7 @@ class ApiEditPageTest extends ApiTestCase {
}
// -- try append/prepend --------------------------------------------
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ list( $re ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
$op . 'text' => $append, ) );
@@ -193,15 +193,80 @@ class ApiEditPageTest extends ApiTestCase {
$this->assertEquals( $expected, $text );
}
- function testEditSection() {
- $this->markTestIncomplete( "not yet implemented" );
+ /**
+ * Test editing of sections
+ */
+ public function testEditSection() {
+ $name = 'Help:ApiEditPageTest_testEditSection';
+ $page = WikiPage::factory( Title::newFromText( $name ) );
+ $text = "==section 1==\ncontent 1\n==section 2==\ncontent2";
+ // Preload the page with some text
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), 'summary' );
+
+ list( $re ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '1',
+ 'text' => "==section 1==\nnew content 1",
+ ) );
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+ $newtext = WikiPage::factory( Title::newFromText( $name) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $newtext, "==section 1==\nnew content 1\n\n==section 2==\ncontent2" );
+
+ // Test that we raise a 'nosuchsection' error
+ try {
+ $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '9999',
+ 'text' => 'text',
+ ) );
+ $this->fail( "Should have raised a UsageException" );
+ } catch ( UsageException $e ) {
+ $this->assertEquals( $e->getCodeString(), 'nosuchsection' );
+ }
}
- function testUndo() {
- $this->markTestIncomplete( "not yet implemented" );
+ /**
+ * Test action=edit&section=new
+ * Run it twice so we test adding a new section on a
+ * page that doesn't exist (bug 52830) and one that
+ * does exist
+ */
+ public function testEditNewSection() {
+ $name = 'Help:ApiEditPageTest_testEditNewSection';
+
+ // Test on a page that does not already exist
+ $this->assertFalse( Title::newFromText( $name )->exists() );
+ list( $re ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => 'new',
+ 'text' => 'test',
+ 'summary' => 'header',
+ ));
+
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+ // Check the page text is correct
+ $text = WikiPage::factory( Title::newFromText( $name ) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $text, "== header ==\n\ntest" );
+
+ // Now on one that does
+ $this->assertTrue( Title::newFromText( $name )->exists() );
+ list( $re2 ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => 'new',
+ 'text' => 'test',
+ 'summary' => 'header',
+ ));
+
+ $this->assertEquals( 'Success', $re2['edit']['result'] );
+ $text = WikiPage::factory( Title::newFromText( $name ) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $text, "== header ==\n\ntest\n\n== header ==\n\ntest" );
}
- function testEditConflict() {
+ public function testEditConflict() {
static $count = 0;
$count++;
@@ -224,7 +289,7 @@ class ApiEditPageTest extends ApiTestCase {
// try to save edit, expect conflict
try {
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => 'nix bar!',
@@ -237,7 +302,7 @@ class ApiEditPageTest extends ApiTestCase {
}
}
- function testEditConflict_redirect() {
+ public function testEditConflict_redirect() {
static $count = 0;
$count++;
@@ -280,7 +345,7 @@ class ApiEditPageTest extends ApiTestCase {
// try again, without following the redirect. Should fail.
try {
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $rname,
'text' => 'nix bar!',
@@ -293,13 +358,13 @@ class ApiEditPageTest extends ApiTestCase {
}
}
- function testEditConflict_bug41990() {
+ public function testEditConflict_bug41990() {
static $count = 0;
$count++;
/*
* bug 41990: if the target page has a newer revision than the redirect, then editing the
- * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erronously
+ * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erroneously
* caused an edit conflict to be detected.
*/