wiki.techinc.nl/tests/phpunit/includes/api/ApiQueryTest.php
Paul Copperman f7e6dfb4a3 Various fixes for PHPUnit tests:
* Block.php: Set mExpiry to the value we store in the database, so that Block::equals() returns true. Fixes BlockTest::testInitializerFunctionsReturnCorrectBlock.
* In Title::checkUserBlock(): Convert message parameters to plain strings to make strict comparisons work. Fixes TitlePermissionTest::testUserBlock().
* ApiBlock.php: Follow-Up r85166, add 'Confirm' parameter to data array. Fixes ApiBlockTest::testMakeNormalBlock().
* ApiQueryTest.php: Use $wgMetaNamespace instead of $wgSitename	to account for customizations.
* RandomImageGenerator.php: Use default value for constructor param to prevent fatals.
* ApiTestCaseUpload.php: 
** Fix undefined variable $fileName.
** Remove stray ini_set statements, they don't belong there. Especially ini_set( 'error_reporting', 1 ) will effectively disable all reporting, which makes errors hard to track.
* ArticleTablesTest.php: Put testbug14404() in group Broken, as the fix for the bug has been reverted in r83868.
2011-04-07 14:54:38 +00:00

69 lines
1.5 KiB
PHP

<?php
require_once dirname( __FILE__ ) . '/ApiSetup.php';
/**
* @group Database
*/
class ApiQueryTest extends ApiTestSetup {
function setUp() {
parent::setUp();
$this->doLogin();
}
function testTitlesGetNormalized() {
global $wgMetaNamespace;
$data = $this->doApiRequest( array(
'action' => 'query',
'titles' => 'Project:articleA|article_B' ) );
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'normalized', $data[0]['query'] );
$this->assertEquals(
array(
'from' => 'Project:articleA',
'to' => $wgMetaNamespace . ':ArticleA'
),
$data[0]['query']['normalized'][0]
);
$this->assertEquals(
array(
'from' => 'article_B',
'to' => 'Article B'
),
$data[0]['query']['normalized'][1]
);
}
function testTitlesAreRejectedIfInvalid() {
$title = false;
while( !$title || Title::newFromText( $title )->exists() ) {
$title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
}
$data = $this->doApiRequest( array(
'action' => 'query',
'titles' => $title . '|Talk:' ) );
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'pages', $data[0]['query'] );
$this->assertEquals( 2, count( $data[0]['query']['pages'] ) );
$this->assertArrayHasKey( -2, $data[0]['query']['pages'] );
$this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
$this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
$this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
}
}