Index: trunk/phase3/tests/phpunit/includes/api/ApiQueryTest.php |
— | — | @@ -0,0 +1,73 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once dirname( __FILE__ ) . '/ApiSetup.php'; |
| 5 | + |
| 6 | +/** |
| 7 | + * @group Database |
| 8 | + */ |
| 9 | +class ApiQueryTest extends ApiTestSetup { |
| 10 | + |
| 11 | + function setUp() { |
| 12 | + parent::setUp(); |
| 13 | + $this->doLogin(); |
| 14 | + } |
| 15 | + |
| 16 | + function testTitlesGetNormalized() { |
| 17 | + |
| 18 | + global $wgSitename; |
| 19 | + |
| 20 | + $data = $this->doApiRequest( array( |
| 21 | + 'action' => 'query', |
| 22 | + 'titles' => 'Project:articleA|article_B' ) ); |
| 23 | + |
| 24 | + |
| 25 | + $this->assertArrayHasKey( 'query', $data[0] ); |
| 26 | + $this->assertArrayHasKey( 'normalized', $data[0]['query'] ); |
| 27 | + |
| 28 | + $this->assertEquals( |
| 29 | + array( |
| 30 | + 'from' => 'Project:articleA', |
| 31 | + 'to' => $wgSitename . ':ArticleA' |
| 32 | + ), |
| 33 | + $data[0]['query']['normalized'][0] |
| 34 | + ); |
| 35 | + |
| 36 | + $this->assertEquals( |
| 37 | + array( |
| 38 | + 'from' => 'article_B', |
| 39 | + 'to' => 'Article B' |
| 40 | + ), |
| 41 | + $data[0]['query']['normalized'][1] |
| 42 | + ); |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + function testTitlesAreRejectedIfInvalid() { |
| 47 | + |
| 48 | + global $wgSitename; |
| 49 | + |
| 50 | + |
| 51 | + $title = false; |
| 52 | + while( !$title || Title::newFromText( $title )->exists() ) { |
| 53 | + $title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) ); |
| 54 | + } |
| 55 | + |
| 56 | + $data = $this->doApiRequest( array( |
| 57 | + 'action' => 'query', |
| 58 | + 'titles' => $title . '|Talk:' ) ); |
| 59 | + |
| 60 | + |
| 61 | + $this->assertArrayHasKey( 'query', $data[0] ); |
| 62 | + $this->assertArrayHasKey( 'pages', $data[0]['query'] ); |
| 63 | + $this->assertEquals( 2, count( $data[0]['query']['pages'] ) ); |
| 64 | + |
| 65 | + $this->assertArrayHasKey( -2, $data[0]['query']['pages'] ); |
| 66 | + $this->assertArrayHasKey( -1, $data[0]['query']['pages'] ); |
| 67 | + |
| 68 | + $this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] ); |
| 69 | + $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] ); |
| 70 | + |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/api/ApiQueryTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 75 | + native |