MediaWiki
REL1_22
|
00001 <?php 00002 00008 class ApiQueryTest extends ApiTestCase { 00009 00010 protected function setUp() { 00011 parent::setUp(); 00012 $this->doLogin(); 00013 } 00014 00015 public function testTitlesGetNormalized() { 00016 00017 global $wgMetaNamespace; 00018 00019 $data = $this->doApiRequest( array( 00020 'action' => 'query', 00021 'titles' => 'Project:articleA|article_B' ) ); 00022 00023 $this->assertArrayHasKey( 'query', $data[0] ); 00024 $this->assertArrayHasKey( 'normalized', $data[0]['query'] ); 00025 00026 // Forge a normalized title 00027 $to = Title::newFromText( $wgMetaNamespace . ':ArticleA' ); 00028 00029 $this->assertEquals( 00030 array( 00031 'from' => 'Project:articleA', 00032 'to' => $to->getPrefixedText(), 00033 ), 00034 $data[0]['query']['normalized'][0] 00035 ); 00036 00037 $this->assertEquals( 00038 array( 00039 'from' => 'article_B', 00040 'to' => 'Article B' 00041 ), 00042 $data[0]['query']['normalized'][1] 00043 ); 00044 } 00045 00046 public 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 }