Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/83219


Change subject: Tests for API section editing
......................................................................

Tests for API section editing

Change-Id: Ibc05c54cd2c9e1775f72dd969e7677b5238e12ad
---
M tests/phpunit/includes/api/ApiEditPageTest.php
1 file changed, 31 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/19/83219/1

diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php 
b/tests/phpunit/includes/api/ApiEditPageTest.php
index e680af6..4fb2b6a 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -193,8 +193,38 @@
                $this->assertEquals( $expected, $text );
        }
 
+       /**
+        * Test editing of sections
+        */
        function testEditSection() {
-               $this->markTestIncomplete( "not yet implemented" );
+               $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->assertTrue(false, "Should have raised a 
UsageException" );
+               } catch ( UsageException $e ) {
+                       $this->assertEquals( $e->getCodeString(), 
'nosuchsection' );
+               }
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/83219
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc05c54cd2c9e1775f72dd969e7677b5238e12ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to