Merge "Remove incorrect timezone conversion from date parameters"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBaseTest.php
index b1f4e0c..121820a 100644 (file)
@@ -164,13 +164,20 @@ class ApiBaseTest extends ApiTestCase {
        }
 
        public function testGetTitleOrPageIdPageId() {
+               $page = $this->getExistingTestPage();
                $result = ( new MockApi() )->getTitleOrPageId(
-                       [ 'pageid' => Title::newFromText( 'UTPage' )->getArticleId() ] );
+                       [ 'pageid' => $page->getId() ] );
                $this->assertInstanceOf( WikiPage::class, $result );
-               $this->assertSame( 'UTPage', $result->getTitle()->getPrefixedText() );
+               $this->assertSame(
+                       $page->getTitle()->getPrefixedText(),
+                       $result->getTitle()->getPrefixedText()
+               );
        }
 
        public function testGetTitleOrPageIdInvalidPageId() {
+               // FIXME: fails under postgres
+               $this->markTestSkippedIfDbType( 'postgres' );
+
                $this->setExpectedException( ApiUsageException::class,
                        'There is no page with ID 2147483648.' );
                $mock = new MockApi();
@@ -199,10 +206,11 @@ class ApiBaseTest extends ApiTestCase {
        }
 
        public function testGetTitleFromTitleOrPageIdPageId() {
+               $page = $this->getExistingTestPage();
                $result = ( new MockApi() )->getTitleFromTitleOrPageId(
-                       [ 'pageid' => Title::newFromText( 'UTPage' )->getArticleId() ] );
+                       [ 'pageid' => $page->getId() ] );
                $this->assertInstanceOf( Title::class, $result );
-               $this->assertSame( 'UTPage', $result->getPrefixedText() );
+               $this->assertSame( $page->getTitle()->getPrefixedText(), $result->getPrefixedText() );
        }
 
        public function testGetTitleFromTitleOrPageIdInvalidPageId() {
@@ -251,7 +259,6 @@ class ApiBaseTest extends ApiTestCase {
        }
 
        /**
-        * @dataProvider provideGetParameterFromSettings
         * @param string|null $input
         * @param array $paramSettings
         * @param mixed $expected
@@ -259,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(
@@ -293,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' &&
@@ -334,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' ],