Merge "Improve logging for wfShellExec() and ignore missing cgroup"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / query / ApiQueryTest.php
1 <?php
2
3 /**
4 * @group API
5 * @group Database
6 * @group medium
7 * @covers ApiQuery
8 */
9 class ApiQueryTest extends ApiTestCase {
10
11 protected function setUp() {
12 parent::setUp();
13 $this->doLogin();
14 }
15
16 public function testTitlesGetNormalized() {
17
18 global $wgMetaNamespace;
19
20 $data = $this->doApiRequest( array(
21 'action' => 'query',
22 'titles' => 'Project:articleA|article_B' ) );
23
24 $this->assertArrayHasKey( 'query', $data[0] );
25 $this->assertArrayHasKey( 'normalized', $data[0]['query'] );
26
27 // Forge a normalized title
28 $to = Title::newFromText( $wgMetaNamespace . ':ArticleA' );
29
30 $this->assertEquals(
31 array(
32 'from' => 'Project:articleA',
33 'to' => $to->getPrefixedText(),
34 ),
35 $data[0]['query']['normalized'][0]
36 );
37
38 $this->assertEquals(
39 array(
40 'from' => 'article_B',
41 'to' => 'Article B'
42 ),
43 $data[0]['query']['normalized'][1]
44 );
45 }
46
47 public function testTitlesAreRejectedIfInvalid() {
48 $title = false;
49 while ( !$title || Title::newFromText( $title )->exists() ) {
50 $title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
51 }
52
53 $data = $this->doApiRequest( array(
54 'action' => 'query',
55 'titles' => $title . '|Talk:' ) );
56
57 $this->assertArrayHasKey( 'query', $data[0] );
58 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
59 $this->assertEquals( 2, count( $data[0]['query']['pages'] ) );
60
61 $this->assertArrayHasKey( -2, $data[0]['query']['pages'] );
62 $this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
63
64 $this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
65 $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
66 }
67 }