Merge "EditPage::newSectionSummary should return a value in all code paths"
[lhc/web/wiklou.git] / tests / phpunit / maintenance / fetchTextTest.php
index dd80840..1ad4656 100644 (file)
@@ -11,7 +11,7 @@ require_once __DIR__ . "/../../../maintenance/fetchText.php";
 class SemiMockedFetchText extends FetchText {
 
        /**
-        * @var String|null Text to pass as stdin
+        * @var string|null Text to pass as stdin
         */
        private $mockStdinText = null;
 
@@ -21,14 +21,14 @@ class SemiMockedFetchText extends FetchText {
        private $mockSetUp = false;
 
        /**
-        * @var Array Invocation counters for the mocked aspects
+        * @var array Invocation counters for the mocked aspects
         */
        private $mockInvocations = array( 'getStdin' => 0 );
 
        /**
         * Data for the fake stdin
         *
-        * @param $stdin String The string to be used instead of stdin
+        * @param string $stdin The string to be used instead of stdin
         */
        function mockStdin( $stdin ) {
                $this->mockStdinText = $stdin;
@@ -38,7 +38,7 @@ class SemiMockedFetchText extends FetchText {
        /**
         * Gets invocation counters for mocked methods.
         *
-        * @return Array An array, whose keys are function names. The corresponding values
+        * @return array An array, whose keys are function names. The corresponding values
         * denote the number of times the function has been invoked.
         */
        function mockGetInvocations() {
@@ -91,29 +91,35 @@ class FetchTextTest extends MediaWikiTestCase {
        private $exceptionFromAddDBData;
 
        /**
-        * @var FetchText the (mocked) FetchText that is to test
+        * @var FetchText The (mocked) FetchText that is to test
         */
        private $fetchText;
 
        /**
         * Adds a revision to a page, while returning the resuting text's id
         *
-        * @param $page WikiPage The page to add the revision to
-        * @param $text String The revisions text
-        * @param $text String The revisions summare
+        * @param WikiPage $page The page to add the revision to
+        * @param string $text The revisions text
+        * @param string $text The revisions summare
         *
-        * @throws MWExcepion
+        * @throws MWException
         */
        private function addRevision( $page, $text, $summary ) {
-               $status = $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), $summary );
+               $status = $page->doEditContent(
+                       ContentHandler::makeContent( $text, $page->getTitle() ),
+                       $summary
+               );
+
                if ( $status->isGood() ) {
                        $value = $status->getValue();
                        $revision = $value['revision'];
                        $id = $revision->getTextId();
+
                        if ( $id > 0 ) {
                                return $id;
                        }
                }
+
                throw new MWException( "Could not determine text id" );
        }
 
@@ -127,14 +133,34 @@ class FetchTextTest extends MediaWikiTestCase {
                try {
                        $title = Title::newFromText( 'FetchTextTestPage1', $wikitextNamespace );
                        $page = WikiPage::factory( $title );
-                       $this->textId1 = $this->addRevision( $page, "FetchTextTestPage1Text1", "FetchTextTestPage1Summary1" );
+                       $this->textId1 = $this->addRevision(
+                               $page,
+                               "FetchTextTestPage1Text1",
+                               "FetchTextTestPage1Summary1"
+                       );
 
                        $title = Title::newFromText( 'FetchTextTestPage2', $wikitextNamespace );
                        $page = WikiPage::factory( $title );
-                       $this->textId2 = $this->addRevision( $page, "FetchTextTestPage2Text1", "FetchTextTestPage2Summary1" );
-                       $this->textId3 = $this->addRevision( $page, "FetchTextTestPage2Text2", "FetchTextTestPage2Summary2" );
-                       $this->textId4 = $this->addRevision( $page, "FetchTextTestPage2Text3", "FetchTextTestPage2Summary3" );
-                       $this->textId5 = $this->addRevision( $page, "FetchTextTestPage2Text4 some additional Text  ", "FetchTextTestPage2Summary4 extra " );
+                       $this->textId2 = $this->addRevision(
+                               $page,
+                               "FetchTextTestPage2Text1",
+                               "FetchTextTestPage2Summary1"
+                       );
+                       $this->textId3 = $this->addRevision(
+                               $page,
+                               "FetchTextTestPage2Text2",
+                               "FetchTextTestPage2Summary2"
+                       );
+                       $this->textId4 = $this->addRevision(
+                               $page,
+                               "FetchTextTestPage2Text3",
+                               "FetchTextTestPage2Summary3"
+                       );
+                       $this->textId5 = $this->addRevision(
+                               $page,
+                               "FetchTextTestPage2Text4 some additional Text  ",
+                               "FetchTextTestPage2Summary4 extra "
+                       );
                } catch ( Exception $e ) {
                        // We'd love to pass $e directly. However, ... see
                        // documentation of exceptionFromAddDBData
@@ -155,6 +181,8 @@ class FetchTextTest extends MediaWikiTestCase {
 
        /**
         * Helper to relate FetchText's input and output
+        * @param string $input
+        * @param string $expectedOutput
         */
        private function assertFilter( $input, $expectedOutput ) {
                $this->fetchText->mockStdin( $input );