Get ~100% test coverage for ApiEditPage.php and fix a couple of bugs
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index e887ef5..83f72e5 100644 (file)
@@ -133,7 +133,7 @@ class ApiEditPage extends ApiBase {
                                        }
 
                                        try {
-                                               $content = ContentHandler::makeContent( $text, $this->getTitle() );
+                                               $content = ContentHandler::makeContent( $text, $titleObj );
                                        } catch ( MWContentSerializationException $ex ) {
                                                $this->dieWithException( $ex, [
                                                        'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
@@ -402,10 +402,17 @@ class ApiEditPage extends ApiBase {
                                        return;
                                }
                                if ( !$status->getErrors() ) {
-                                       $status->fatal( 'hookaborted' );
+                                       // This appears to be unreachable right now, because all
+                                       // code paths will set an error.  Could change, though.
+                                       $status->fatal( 'hookaborted' ); //@codeCoverageIgnore
                                }
                                $this->dieStatus( $status );
 
+                       // These two cases will normally have been caught earlier, and will
+                       // only occur if something blocks the user between the earlier
+                       // check and the check in EditPage (presumably a hook).  It's not
+                       // obvious that this is even possible.
+                       // @codeCoverageIgnoreStart
                        case EditPage::AS_BLOCKED_PAGE_FOR_USER:
                                $this->dieWithError(
                                        'apierror-blocked',
@@ -415,6 +422,7 @@ class ApiEditPage extends ApiBase {
 
                        case EditPage::AS_READ_ONLY_PAGE:
                                $this->dieReadOnly();
+                       // @codeCoverageIgnoreEnd
 
                        case EditPage::AS_SUCCESS_NEW_ARTICLE:
                                $r['new'] = true;
@@ -446,7 +454,7 @@ class ApiEditPage extends ApiBase {
                                                        $status->fatal( 'apierror-noimageredirect-anon' );
                                                        break;
                                                case EditPage::AS_IMAGE_REDIRECT_LOGGED:
-                                                       $status->fatal( 'apierror-noimageredirect-logged' );
+                                                       $status->fatal( 'apierror-noimageredirect' );
                                                        break;
                                                case EditPage::AS_CONTENT_TOO_BIG:
                                                case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
@@ -468,6 +476,7 @@ class ApiEditPage extends ApiBase {
                                                // Currently shouldn't be needed, but here in case
                                                // hooks use them without setting appropriate
                                                // errors on the status.
+                                               // @codeCoverageIgnoreStart
                                                case EditPage::AS_SPAM_ERROR:
                                                        $status->fatal( 'apierror-spamdetected', $result['spam'] );
                                                        break;
@@ -493,10 +502,10 @@ class ApiEditPage extends ApiBase {
                                                        wfWarn( __METHOD__ . ": Unknown EditPage code {$status->value} with no message" );
                                                        $status->fatal( 'apierror-unknownerror-editpage', $status->value );
                                                        break;
+                                               // @codeCoverageIgnoreEnd
                                        }
                                }
                                $this->dieStatus( $status );
-                               break;
                }
                $apiResult->addValue( null, $this->getModuleName(), $r );
        }
@@ -566,10 +575,14 @@ class ApiEditPage extends ApiBase {
                                ApiBase::PARAM_TYPE => 'text',
                        ],
                        'undo' => [
-                               ApiBase::PARAM_TYPE => 'integer'
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_MIN => 0,
+                               ApiBase::PARAM_RANGE_ENFORCE => true,
                        ],
                        'undoafter' => [
-                               ApiBase::PARAM_TYPE => 'integer'
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_MIN => 0,
+                               ApiBase::PARAM_RANGE_ENFORCE => true,
                        ],
                        'redirect' => [
                                ApiBase::PARAM_TYPE => 'boolean',