8 class ApiQueryTest
extends ApiTestCase
{
10 protected function setUp() {
15 function testTitlesGetNormalized() {
17 global $wgMetaNamespace;
19 $data = $this->doApiRequest( array(
21 'titles' => 'Project:articleA|article_B' ) );
23 $this->assertArrayHasKey( 'query', $data[0] );
24 $this->assertArrayHasKey( 'normalized', $data[0]['query'] );
26 // Forge a normalized title
27 $to = Title
::newFromText( $wgMetaNamespace . ':ArticleA' );
31 'from' => 'Project:articleA',
32 'to' => $to->getPrefixedText(),
34 $data[0]['query']['normalized'][0]
39 'from' => 'article_B',
42 $data[0]['query']['normalized'][1]
46 function testTitlesAreRejectedIfInvalid() {
48 while ( !$title || Title
::newFromText( $title )->exists() ) {
49 $title = md5( mt_rand( 0, 10000 ) +
rand( 0, 999000 ) );
52 $data = $this->doApiRequest( array(
54 'titles' => $title . '|Talk:' ) );
56 $this->assertArrayHasKey( 'query', $data[0] );
57 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
58 $this->assertEquals( 2, count( $data[0]['query']['pages'] ) );
60 $this->assertArrayHasKey( -2, $data[0]['query']['pages'] );
61 $this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
63 $this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
64 $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );