MediaWiki  REL1_24
ApiQueryBasicTest.php
Go to the documentation of this file.
00001 <?php
00026 require_once 'ApiQueryTestBase.php';
00027 
00036 class ApiQueryBasicTest extends ApiQueryTestBase {
00037     protected $exceptionFromAddDBData;
00038 
00043     function addDBData() {
00044         try {
00045             if ( Title::newFromText( 'AQBT-All' )->exists() ) {
00046                 return;
00047             }
00048 
00049             // Ordering is important, as it will be returned in the same order as stored in the index
00050             $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
00051             $this->editPage( 'AQBT-Categories', '[[Category:AQBT-Cat]]' );
00052             $this->editPage( 'AQBT-Links', '[[AQBT-All]] [[AQBT-Categories]] [[AQBT-Templates]]' );
00053             $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
00054             $this->editPage( 'AQBT-T', 'Content', '', NS_TEMPLATE );
00055 
00056             // Refresh due to the bug with listing transclusions as links if they don't exist
00057             $this->editPage( 'AQBT-All', '[[Category:AQBT-Cat]] [[AQBT-Links]] {{AQBT-T}}' );
00058             $this->editPage( 'AQBT-Templates', '{{AQBT-T}}' );
00059         } catch ( Exception $e ) {
00060             $this->exceptionFromAddDBData = $e;
00061         }
00062     }
00063 
00064     private static $links = array(
00065         array( 'prop' => 'links', 'titles' => 'AQBT-All' ),
00066         array( 'pages' => array(
00067             '1' => array(
00068                 'pageid' => 1,
00069                 'ns' => 0,
00070                 'title' => 'AQBT-All',
00071                 'links' => array(
00072                     array( 'ns' => 0, 'title' => 'AQBT-Links' ),
00073                 )
00074             )
00075         ) )
00076     );
00077 
00078     private static $templates = array(
00079         array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
00080         array( 'pages' => array(
00081             '1' => array(
00082                 'pageid' => 1,
00083                 'ns' => 0,
00084                 'title' => 'AQBT-All',
00085                 'templates' => array(
00086                     array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
00087                 )
00088             )
00089         ) )
00090     );
00091 
00092     private static $categories = array(
00093         array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
00094         array( 'pages' => array(
00095             '1' => array(
00096                 'pageid' => 1,
00097                 'ns' => 0,
00098                 'title' => 'AQBT-All',
00099                 'categories' => array(
00100                     array( 'ns' => 14, 'title' => 'Category:AQBT-Cat' ),
00101                 )
00102             )
00103         ) )
00104     );
00105 
00106     private static $allpages = array(
00107         array( 'list' => 'allpages', 'apprefix' => 'AQBT-' ),
00108         array( 'allpages' => array(
00109             array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
00110             array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
00111             array( 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ),
00112             array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
00113         ) )
00114     );
00115 
00116     private static $alllinks = array(
00117         array( 'list' => 'alllinks', 'alprefix' => 'AQBT-' ),
00118         array( 'alllinks' => array(
00119             array( 'ns' => 0, 'title' => 'AQBT-All' ),
00120             array( 'ns' => 0, 'title' => 'AQBT-Categories' ),
00121             array( 'ns' => 0, 'title' => 'AQBT-Links' ),
00122             array( 'ns' => 0, 'title' => 'AQBT-Templates' ),
00123         ) )
00124     );
00125 
00126     private static $alltransclusions = array(
00127         array( 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ),
00128         array( 'alltransclusions' => array(
00129             array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
00130             array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
00131         ) )
00132     );
00133 
00134     // Although this appears to have no use it is used by testLists()
00135     private static $allcategories = array(
00136         array( 'list' => 'allcategories', 'acprefix' => 'AQBT-' ),
00137         array( 'allcategories' => array(
00138             array( '*' => 'AQBT-Cat' ),
00139         ) )
00140     );
00141 
00142     private static $backlinks = array(
00143         array( 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ),
00144         array( 'backlinks' => array(
00145             array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
00146         ) )
00147     );
00148 
00149     private static $embeddedin = array(
00150         array( 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ),
00151         array( 'embeddedin' => array(
00152             array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
00153             array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
00154         ) )
00155     );
00156 
00157     private static $categorymembers = array(
00158         array( 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ),
00159         array( 'categorymembers' => array(
00160             array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
00161             array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
00162         ) )
00163     );
00164 
00165     private static $generatorAllpages = array(
00166         array( 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ),
00167         array( 'pages' => array(
00168             '1' => array(
00169                 'pageid' => 1,
00170                 'ns' => 0,
00171                 'title' => 'AQBT-All' ),
00172             '2' => array(
00173                 'pageid' => 2,
00174                 'ns' => 0,
00175                 'title' => 'AQBT-Categories' ),
00176             '3' => array(
00177                 'pageid' => 3,
00178                 'ns' => 0,
00179                 'title' => 'AQBT-Links' ),
00180             '4' => array(
00181                 'pageid' => 4,
00182                 'ns' => 0,
00183                 'title' => 'AQBT-Templates' ),
00184         ) )
00185     );
00186 
00187     private static $generatorLinks = array(
00188         array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
00189         array( 'pages' => array(
00190             '1' => array(
00191                 'pageid' => 1,
00192                 'ns' => 0,
00193                 'title' => 'AQBT-All' ),
00194             '2' => array(
00195                 'pageid' => 2,
00196                 'ns' => 0,
00197                 'title' => 'AQBT-Categories' ),
00198             '4' => array(
00199                 'pageid' => 4,
00200                 'ns' => 0,
00201                 'title' => 'AQBT-Templates' ),
00202         ) )
00203     );
00204 
00205     private static $generatorLinksPropLinks = array(
00206         array( 'prop' => 'links' ),
00207         array( 'pages' => array(
00208             '1' => array( 'links' => array(
00209                 array( 'ns' => 0, 'title' => 'AQBT-Links' ),
00210             ) )
00211         ) )
00212     );
00213 
00214     private static $generatorLinksPropTemplates = array(
00215         array( 'prop' => 'templates' ),
00216         array( 'pages' => array(
00217             '1' => array( 'templates' => array(
00218                 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
00219             '4' => array( 'templates' => array(
00220                 array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
00221         ) )
00222     );
00223 
00227     public function testProps() {
00228         $this->check( self::$links );
00229         $this->check( self::$templates );
00230         $this->check( self::$categories );
00231     }
00232 
00236     public function testLists() {
00237         $this->check( self::$allpages );
00238         $this->check( self::$alllinks );
00239         $this->check( self::$alltransclusions );
00240         // This test is temporarily disabled until a sqlite bug is fixed
00241         // Confirmed still broken 15-nov-2013
00242         // $this->check( self::$allcategories );
00243         $this->check( self::$backlinks );
00244         $this->check( self::$embeddedin );
00245         $this->check( self::$categorymembers );
00246     }
00247 
00251     public function testAllTogether() {
00252 
00253         // All props together
00254         $this->check( $this->merge(
00255             self::$links,
00256             self::$templates,
00257             self::$categories
00258         ) );
00259 
00260         // All lists together
00261         $this->check( $this->merge(
00262             self::$allpages,
00263             self::$alllinks,
00264             self::$alltransclusions,
00265             // This test is temporarily disabled until a sqlite bug is fixed
00266             // self::$allcategories,
00267             self::$backlinks,
00268             self::$embeddedin,
00269             self::$categorymembers
00270         ) );
00271 
00272         // All props+lists together
00273         $this->check( $this->merge(
00274             self::$links,
00275             self::$templates,
00276             self::$categories,
00277             self::$allpages,
00278             self::$alllinks,
00279             self::$alltransclusions,
00280             // This test is temporarily disabled until a sqlite bug is fixed
00281             // self::$allcategories,
00282             self::$backlinks,
00283             self::$embeddedin,
00284             self::$categorymembers
00285         ) );
00286     }
00287 
00291     public function testGenerator() {
00292         // generator=allpages
00293         $this->check( self::$generatorAllpages );
00294         // generator=allpages & list=allpages
00295         $this->check( $this->merge(
00296             self::$generatorAllpages,
00297             self::$allpages ) );
00298         // generator=links
00299         $this->check( self::$generatorLinks );
00300         // generator=links & prop=links
00301         $this->check( $this->merge(
00302             self::$generatorLinks,
00303             self::$generatorLinksPropLinks ) );
00304         // generator=links & prop=templates
00305         $this->check( $this->merge(
00306             self::$generatorLinks,
00307             self::$generatorLinksPropTemplates ) );
00308         // generator=links & prop=links|templates
00309         $this->check( $this->merge(
00310             self::$generatorLinks,
00311             self::$generatorLinksPropLinks,
00312             self::$generatorLinksPropTemplates ) );
00313         // generator=links & prop=links|templates & list=allpages|...
00314         $this->check( $this->merge(
00315             self::$generatorLinks,
00316             self::$generatorLinksPropLinks,
00317             self::$generatorLinksPropTemplates,
00318             self::$allpages,
00319             self::$alllinks,
00320             self::$alltransclusions,
00321             // This test is temporarily disabled until a sqlite bug is fixed
00322             // self::$allcategories,
00323             self::$backlinks,
00324             self::$embeddedin,
00325             self::$categorymembers ) );
00326     }
00327 
00331     public function testGeneratorRedirects() {
00332         $this->editPage( 'AQBT-Target', 'test' );
00333         $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
00334         $this->check( array(
00335             array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
00336             array(
00337                 'redirects' => array(
00338                     array(
00339                         'from' => 'AQBT-Redir',
00340                         'to' => 'AQBT-Target',
00341                     )
00342                 ),
00343                 'pages' => array(
00344                     '6' => array(
00345                         'pageid' => 6,
00346                         'ns' => 0,
00347                         'title' => 'AQBT-Target',
00348                     )
00349                 ),
00350             )
00351         ) );
00352     }
00353 }