Merge "Collapse some else statements and nested if statements"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBaseTest.php
index 4f65ae9..8049a47 100644 (file)
@@ -175,6 +175,9 @@ class ApiBaseTest extends ApiTestCase {
        }
 
        public function testGetTitleOrPageIdInvalidPageId() {
+               // FIXME: fails under postgres
+               $this->markTestSkippedIfDbType( 'postgres' );
+
                $this->setExpectedException( ApiUsageException::class,
                        'There is no page with ID 2147483648.' );
                $mock = new MockApi();
@@ -256,7 +259,6 @@ class ApiBaseTest extends ApiTestCase {
        }
 
        /**
-        * @dataProvider provideGetParameterFromSettings
         * @param string|null $input
         * @param array $paramSettings
         * @param mixed $expected
@@ -264,13 +266,20 @@ class ApiBaseTest extends ApiTestCase {
         *   'parseLimits': true|false
         *   'apihighlimits': true|false
         *   'internalmode': true|false
+        *   'prefix': true|false
         * @param string[] $warnings
         */
-       public function testGetParameterFromSettings(
+       private function doGetParameterFromSettings(
                $input, $paramSettings, $expected, $warnings, $options = []
        ) {
                $mock = new MockApi();
                $wrapper = TestingAccessWrapper::newFromObject( $mock );
+               if ( $options['prefix'] ) {
+                       $wrapper->mModulePrefix = 'my';
+                       $paramName = 'Param';
+               } else {
+                       $paramName = 'myParam';
+               }
 
                $context = new DerivativeContext( $mock );
                $context->setRequest( new FauxRequest(
@@ -298,14 +307,14 @@ class ApiBaseTest extends ApiTestCase {
 
                if ( $expected instanceof Exception ) {
                        try {
-                               $wrapper->getParameterFromSettings( 'myParam', $paramSettings,
+                               $wrapper->getParameterFromSettings( $paramName, $paramSettings,
                                        $parseLimits );
                                $this->fail( 'No exception thrown' );
                        } catch ( Exception $ex ) {
                                $this->assertEquals( $expected, $ex );
                        }
                } else {
-                       $result = $wrapper->getParameterFromSettings( 'myParam',
+                       $result = $wrapper->getParameterFromSettings( $paramName,
                                $paramSettings, $parseLimits );
                        if ( isset( $paramSettings[ApiBase::PARAM_TYPE] ) &&
                                $paramSettings[ApiBase::PARAM_TYPE] === 'timestamp' &&
@@ -339,6 +348,28 @@ class ApiBaseTest extends ApiTestCase {
                }
        }
 
+       /**
+        * @dataProvider provideGetParameterFromSettings
+        * @see self::doGetParameterFromSettings()
+        */
+       public function testGetParameterFromSettings_noprefix(
+               $input, $paramSettings, $expected, $warnings, $options = []
+       ) {
+               $options['prefix'] = false;
+               $this->doGetParameterFromSettings( $input, $paramSettings, $expected, $warnings, $options );
+       }
+
+       /**
+        * @dataProvider provideGetParameterFromSettings
+        * @see self::doGetParameterFromSettings()
+        */
+       public function testGetParameterFromSettings_prefix(
+               $input, $paramSettings, $expected, $warnings, $options = []
+       ) {
+               $options['prefix'] = true;
+               $this->doGetParameterFromSettings( $input, $paramSettings, $expected, $warnings, $options );
+       }
+
        public static function provideGetParameterFromSettings() {
                $warnings = [
                        [ 'apiwarn-badutf8', 'myParam' ],
@@ -498,12 +529,36 @@ class ApiBaseTest extends ApiTestCase {
                                'foo',
                                [ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
                        ],
+                       'Deprecated parameter with default, unspecified' => [
+                               null,
+                               [ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
+                               'foo',
+                               [],
+                       ],
+                       'Deprecated parameter with default, specified' => [
+                               'foo',
+                               [ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
+                               'foo',
+                               [ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
+                       ],
                        'Deprecated parameter value' => [
                                'a',
                                [ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ] ],
                                'a',
                                [ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
                        ],
+                       'Deprecated parameter value as default, unspecified' => [
+                               null,
+                               [ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
+                               'a',
+                               [],
+                       ],
+                       'Deprecated parameter value as default, specified' => [
+                               'a',
+                               [ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
+                               'a',
+                               [ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
+                       ],
                        'Multiple deprecated parameter values' => [
                                'a|b|c|d',
                                [ ApiBase::PARAM_DEPRECATED_VALUES =>