9 class ApiQueryTest
extends ApiTestCase
{
11 protected function setUp() {
16 public function testTitlesGetNormalized() {
18 global $wgMetaNamespace;
20 $data = $this->doApiRequest( array(
22 'titles' => 'Project:articleA|article_B' ) );
24 $this->assertArrayHasKey( 'query', $data[0] );
25 $this->assertArrayHasKey( 'normalized', $data[0]['query'] );
27 // Forge a normalized title
28 $to = Title
::newFromText( $wgMetaNamespace . ':ArticleA' );
32 'from' => 'Project:articleA',
33 'to' => $to->getPrefixedText(),
35 $data[0]['query']['normalized'][0]
40 'from' => 'article_B',
43 $data[0]['query']['normalized'][1]
47 public function testTitlesAreRejectedIfInvalid() {
49 while ( !$title || Title
::newFromText( $title )->exists() ) {
50 $title = md5( mt_rand( 0, 10000 ) +
rand( 0, 999000 ) );
53 $data = $this->doApiRequest( array(
55 'titles' => $title . '|Talk:' ) );
57 $this->assertArrayHasKey( 'query', $data[0] );
58 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
59 $this->assertEquals( 2, count( $data[0]['query']['pages'] ) );
61 $this->assertArrayHasKey( -2, $data[0]['query']['pages'] );
62 $this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
64 $this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
65 $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );