MediaWiki  REL1_21
ApiQueryTest.php
Go to the documentation of this file.
00001 <?php
00002 
00008 class ApiQueryTest extends ApiTestCase {
00009 
00010         protected function setUp() {
00011                 parent::setUp();
00012                 $this->doLogin();
00013         }
00014 
00015         function testTitlesGetNormalized() {
00016 
00017                 global $wgMetaNamespace;
00018 
00019                 $data = $this->doApiRequest( array(
00020                         'action' => 'query',
00021                         'titles' => 'Project:articleA|article_B' ) );
00022 
00023 
00024                 $this->assertArrayHasKey( 'query', $data[0] );
00025                 $this->assertArrayHasKey( 'normalized', $data[0]['query'] );
00026 
00027                 // Forge a normalized title
00028                 $to = Title::newFromText( $wgMetaNamespace . ':ArticleA' );
00029 
00030                 $this->assertEquals(
00031                         array(
00032                                 'from' => 'Project:articleA',
00033                                 'to' => $to->getPrefixedText(),
00034                         ),
00035                         $data[0]['query']['normalized'][0]
00036                 );
00037 
00038                 $this->assertEquals(
00039                         array(
00040                                 'from' => 'article_B',
00041                                 'to' => 'Article B'
00042                         ),
00043                         $data[0]['query']['normalized'][1]
00044                 );
00045 
00046         }
00047 
00048         function testTitlesAreRejectedIfInvalid() {
00049                 $title = false;
00050                 while ( !$title || Title::newFromText( $title )->exists() ) {
00051                         $title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
00052                 }
00053 
00054                 $data = $this->doApiRequest( array(
00055                         'action' => 'query',
00056                         'titles' => $title . '|Talk:' ) );
00057 
00058                 $this->assertArrayHasKey( 'query', $data[0] );
00059                 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
00060                 $this->assertEquals( 2, count( $data[0]['query']['pages'] ) );
00061 
00062                 $this->assertArrayHasKey( -2, $data[0]['query']['pages'] );
00063                 $this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
00064 
00065                 $this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
00066                 $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
00067         }
00068 
00069 }