Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiMainTest.php
index d17334b..f06d97e 100644 (file)
@@ -434,6 +434,35 @@ class ApiMainTest extends ApiTestCase {
                }
        }
 
+       /**
+        * Test that 'assert' is processed before module errors
+        */
+       public function testAssertBeforeModule() {
+               // Sanity check that the query without assert throws too-many-titles
+               try {
+                       $this->doApiRequest( [
+                               'action' => 'query',
+                               'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+                       ], null, null, new User );
+                       $this->fail( 'Expected exception not thrown' );
+               } catch ( ApiUsageException $e ) {
+                       $this->assertTrue( self::apiExceptionHasCode( $e, 'too-many-titles' ), 'sanity check' );
+               }
+
+               // Now test that the assert happens first
+               try {
+                       $this->doApiRequest( [
+                               'action' => 'query',
+                               'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+                               'assert' => 'user',
+                       ], null, null, new User );
+                       $this->fail( 'Expected exception not thrown' );
+               } catch ( ApiUsageException $e ) {
+                       $this->assertTrue( self::apiExceptionHasCode( $e, 'assertuserfailed' ),
+                               "Error '{$e->getMessage()}' matched expected 'assertuserfailed'" );
+               }
+       }
+
        /**
         * Test if all classes in the main module manager exists
         */
@@ -491,7 +520,7 @@ class ApiMainTest extends ApiTestCase {
                $module->expects( $this->any() )
                        ->method( 'getConditionalRequestData' )
                        ->will( $this->returnCallback( function ( $condition ) use ( $conditions ) {
-                               return isset( $conditions[$condition] ) ? $conditions[$condition] : null;
+                               return $conditions[$condition] ?? null;
                        } ) );
 
                $ret = $priv->checkConditionalRequestHeaders( $module );
@@ -622,7 +651,7 @@ class ApiMainTest extends ApiTestCase {
                $module->expects( $this->any() )
                        ->method( 'getConditionalRequestData' )
                        ->will( $this->returnCallback( function ( $condition ) use ( $conditions ) {
-                               return isset( $conditions[$condition] ) ? $conditions[$condition] : null;
+                               return $conditions[$condition] ?? null;
                        } ) );
                $priv->mModule = $module;
 
@@ -630,7 +659,7 @@ class ApiMainTest extends ApiTestCase {
 
                foreach ( [ 'Last-Modified', 'ETag' ] as $header ) {
                        $this->assertEquals(
-                               isset( $headers[$header] ) ? $headers[$header] : null,
+                               $headers[$header] ?? null,
                                $response->getHeader( $header ),
                                $header
                        );