Tests for API section editing
authorKunal Mehta <legoktm@gmail.com>
Sat, 7 Sep 2013 05:56:37 +0000 (22:56 -0700)
committerKunal Mehta <legoktm@gmail.com>
Wed, 9 Oct 2013 18:01:52 +0000 (11:01 -0700)
Change-Id: Ibc05c54cd2c9e1775f72dd969e7677b5238e12ad

tests/phpunit/includes/api/ApiEditPageTest.php

index b0efd19..c19b54e 100644 (file)
@@ -193,6 +193,40 @@ class ApiEditPageTest extends ApiTestCase {
                $this->assertEquals( $expected, $text );
        }
 
+       /**
+        * Test editing of sections
+        */
+       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' );
+               }
+       }
+
        /**
         * Test action=edit&section=new
         * Run it twice so we test adding a new section on a