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