summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/api
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/api')
-rw-r--r--tests/phpunit/includes/api/ApiAccountCreationTest.php56
-rw-r--r--tests/phpunit/includes/api/ApiBlockTest.php21
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php107
-rw-r--r--tests/phpunit/includes/api/ApiOptionsTest.php38
-rw-r--r--tests/phpunit/includes/api/ApiParseTest.php5
-rw-r--r--tests/phpunit/includes/api/ApiPurgeTest.php3
-rw-r--r--tests/phpunit/includes/api/ApiTest.php47
-rw-r--r--tests/phpunit/includes/api/ApiTestCase.php40
-rw-r--r--tests/phpunit/includes/api/ApiTestCaseUpload.php4
-rw-r--r--tests/phpunit/includes/api/ApiUploadTest.php42
-rw-r--r--tests/phpunit/includes/api/ApiWatchTest.php55
-rw-r--r--tests/phpunit/includes/api/RandomImageGenerator.php13
-rw-r--r--tests/phpunit/includes/api/format/ApiFormatPhpTest.php4
-rw-r--r--tests/phpunit/includes/api/generateRandomImages.php6
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryBasicTest.php77
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryContinue2Test.php14
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryContinueTest.php198
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php62
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryTest.php7
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryTestBase.php15
21 files changed, 456 insertions, 360 deletions
diff --git a/tests/phpunit/includes/api/ApiAccountCreationTest.php b/tests/phpunit/includes/api/ApiAccountCreationTest.php
index 94082e5a..68f80ac9 100644
--- a/tests/phpunit/includes/api/ApiAccountCreationTest.php
+++ b/tests/phpunit/includes/api/ApiAccountCreationTest.php
@@ -20,7 +20,7 @@ class ApiCreateAccountTest extends ApiTestCase {
* a bit slow. Raise the default timeout.
* @group medium
*/
- function testValid() {
+ public function testValid() {
global $wgServer;
if ( !isset( $wgServer ) ) {
@@ -47,13 +47,16 @@ class ApiCreateAccountTest extends ApiTestCase {
$token = $a['token'];
// Finally create the account
- $ret = $this->doApiRequest( array(
- 'action' => 'createaccount',
- 'name' => 'Apitestnew',
- 'password' => $password,
- 'token' => $token,
- 'email' => 'test@domain.test',
- 'realname' => 'Test Name' ), $ret[2]
+ $ret = $this->doApiRequest(
+ array(
+ 'action' => 'createaccount',
+ 'name' => 'Apitestnew',
+ 'password' => $password,
+ 'token' => $token,
+ 'email' => 'test@domain.test',
+ 'realname' => 'Test Name'
+ ),
+ $ret[2]
);
$result = $ret[0];
@@ -65,8 +68,7 @@ class ApiCreateAccountTest extends ApiTestCase {
'action' => 'login',
'lgname' => 'Apitestnew',
'lgpassword' => $password,
- )
- );
+ ) );
$result = $ret[0];
$this->assertNotInternalType( 'bool', $result );
@@ -76,12 +78,14 @@ class ApiCreateAccountTest extends ApiTestCase {
$this->assertEquals( 'NeedToken', $a );
$token = $result['login']['token'];
- $ret = $this->doApiRequest( array(
- 'action' => 'login',
- 'lgtoken' => $token,
- 'lgname' => 'Apitestnew',
- 'lgpassword' => $password,
- ), $ret[2]
+ $ret = $this->doApiRequest(
+ array(
+ 'action' => 'login',
+ 'lgtoken' => $token,
+ 'lgname' => 'Apitestnew',
+ 'lgpassword' => $password,
+ ),
+ $ret[2]
);
$result = $ret[0];
@@ -92,9 +96,11 @@ class ApiCreateAccountTest extends ApiTestCase {
$this->assertEquals( 'Success', $a );
// log out to destroy the session
- $ret = $this->doApiRequest( array(
- 'action' => 'logout',
- ), $ret[2]
+ $ret = $this->doApiRequest(
+ array(
+ 'action' => 'logout',
+ ),
+ $ret[2]
);
$this->assertEquals( array(), $ret[0] );
}
@@ -103,8 +109,8 @@ class ApiCreateAccountTest extends ApiTestCase {
* Make sure requests with no names are invalid.
* @expectedException UsageException
*/
- function testNoName() {
- $ret = $this->doApiRequest( array(
+ public function testNoName() {
+ $this->doApiRequest( array(
'action' => 'createaccount',
'token' => LoginForm::getCreateaccountToken(),
'password' => 'password',
@@ -115,8 +121,8 @@ class ApiCreateAccountTest extends ApiTestCase {
* Make sure requests with no password are invalid.
* @expectedException UsageException
*/
- function testNoPassword() {
- $ret = $this->doApiRequest( array(
+ public function testNoPassword() {
+ $this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'testName',
'token' => LoginForm::getCreateaccountToken(),
@@ -127,7 +133,7 @@ class ApiCreateAccountTest extends ApiTestCase {
* Make sure requests with existing users are invalid.
* @expectedException UsageException
*/
- function testExistingUser() {
+ public function testExistingUser() {
$this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Apitestsysop',
@@ -141,7 +147,7 @@ class ApiCreateAccountTest extends ApiTestCase {
* Make sure requests with invalid emails are invalid.
* @expectedException UsageException
*/
- function testInvalidEmail() {
+ public function testInvalidEmail() {
$this->doApiRequest( array(
'action' => 'createaccount',
'name' => 'Test User',
diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php
index 94643b10..8afb748a 100644
--- a/tests/phpunit/includes/api/ApiBlockTest.php
+++ b/tests/phpunit/includes/api/ApiBlockTest.php
@@ -6,7 +6,6 @@
* @group medium
*/
class ApiBlockTest extends ApiTestCase {
-
protected function setUp() {
parent::setUp();
$this->doLogin();
@@ -35,9 +34,8 @@ class ApiBlockTest extends ApiTestCase {
* Which made the Block/Unblock API to actually verify the token
* previously always considered valid (bug 34212).
*/
- function testMakeNormalBlock() {
-
- $data = $this->getTokens();
+ public function testMakeNormalBlock() {
+ $tokens = $this->getTokens();
$user = User::newFromName( 'UTApiBlockee' );
@@ -45,19 +43,15 @@ class ApiBlockTest extends ApiTestCase {
$this->markTestIncomplete( "The user UTApiBlockee does not exist" );
}
- if ( !isset( $data[0]['query']['pages'] ) ) {
+ if ( !array_key_exists( 'blocktoken', $tokens ) ) {
$this->markTestIncomplete( "No block token found" );
}
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
- $pageinfo = $data[0]['query']['pages'][$key];
-
- $data = $this->doApiRequest( array(
+ $this->doApiRequest( array(
'action' => 'block',
'user' => 'UTApiBlockee',
'reason' => 'Some reason',
- 'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user );
+ 'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user );
$block = Block::newFromTarget( 'UTApiBlockee' );
@@ -66,7 +60,6 @@ class ApiBlockTest extends ApiTestCase {
$this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
$this->assertEquals( 'Some reason', $block->mReason );
$this->assertEquals( 'infinity', $block->mExpiry );
-
}
/**
@@ -77,7 +70,7 @@ class ApiBlockTest extends ApiTestCase {
* @dataProvider provideBlockUnblockAction
* @expectedException UsageException
*/
- function testBlockingActionWithNoToken( $action ) {
+ public function testBlockingActionWithNoToken( $action ) {
$this->doApiRequest(
array(
'action' => $action,
@@ -93,7 +86,7 @@ class ApiBlockTest extends ApiTestCase {
/**
* Just provide the 'block' and 'unblock' action to test both API calls
*/
- function provideBlockUnblockAction() {
+ public static function provideBlockUnblockAction() {
return array(
array( 'block' ),
array( 'unblock' ),
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 1efbaeaf..0c49b12b 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -11,10 +11,10 @@
*/
class ApiEditPageTest extends ApiTestCase {
- public function setup() {
+ public function setUp() {
global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
- parent::setup();
+ parent::setUp();
$wgExtraNamespaces[12312] = 'Dummy';
$wgExtraNamespaces[12313] = 'Dummy_talk';
@@ -28,7 +28,7 @@ class ApiEditPageTest extends ApiTestCase {
$this->doLogin();
}
- public function teardown() {
+ public function tearDown() {
global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
unset( $wgExtraNamespaces[12312] );
@@ -40,10 +40,10 @@ class ApiEditPageTest extends ApiTestCase {
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
- parent::teardown();
+ parent::tearDown();
}
- function testEdit() {
+ public function testEdit() {
$name = 'Help:ApiEditPageTest_testEdit'; // assume Help namespace to default to wikitext
// -- test new page --------------------------------------------
@@ -97,7 +97,7 @@ class ApiEditPageTest extends ApiTestCase {
);
}
- function testNonTextEdit() {
+ public function testNonTextEdit() {
$name = 'Dummy:ApiEditPageTest_testNonTextEdit';
$data = serialize( 'some bla bla text' );
@@ -124,7 +124,7 @@ class ApiEditPageTest extends ApiTestCase {
$this->assertEquals( $data, $page->getContent()->serialize() );
}
- static function provideEditAppend() {
+ public static function provideEditAppend() {
return array(
array( #0: append
'foo', 'append', 'bar', "foobar"
@@ -150,7 +150,7 @@ class ApiEditPageTest extends ApiTestCase {
/**
* @dataProvider provideEditAppend
*/
- function testEditAppend( $text, $op, $append, $expected ) {
+ public function testEditAppend( $text, $op, $append, $expected ) {
static $count = 0;
$count++;
@@ -161,13 +161,13 @@ class ApiEditPageTest extends ApiTestCase {
if ( $text !== null ) {
if ( $text === '' ) {
// can't create an empty page, so create it with some content
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => '(dummy)', ) );
}
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ list( $re ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => $text, ) );
@@ -176,7 +176,7 @@ class ApiEditPageTest extends ApiTestCase {
}
// -- try append/prepend --------------------------------------------
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ list( $re ) = $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
$op . 'text' => $append, ) );
@@ -193,15 +193,80 @@ class ApiEditPageTest extends ApiTestCase {
$this->assertEquals( $expected, $text );
}
- function testEditSection() {
- $this->markTestIncomplete( "not yet implemented" );
+ /**
+ * Test editing of sections
+ */
+ public function testEditSection() {
+ $name = 'Help:ApiEditPageTest_testEditSection';
+ $page = WikiPage::factory( Title::newFromText( $name ) );
+ $text = "==section 1==\ncontent 1\n==section 2==\ncontent2";
+ // Preload the page with some text
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), 'summary' );
+
+ list( $re ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '1',
+ 'text' => "==section 1==\nnew content 1",
+ ) );
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+ $newtext = WikiPage::factory( Title::newFromText( $name) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $newtext, "==section 1==\nnew content 1\n\n==section 2==\ncontent2" );
+
+ // Test that we raise a 'nosuchsection' error
+ try {
+ $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '9999',
+ 'text' => 'text',
+ ) );
+ $this->fail( "Should have raised a UsageException" );
+ } catch ( UsageException $e ) {
+ $this->assertEquals( $e->getCodeString(), 'nosuchsection' );
+ }
}
- function testUndo() {
- $this->markTestIncomplete( "not yet implemented" );
+ /**
+ * Test action=edit&section=new
+ * Run it twice so we test adding a new section on a
+ * page that doesn't exist (bug 52830) and one that
+ * does exist
+ */
+ public function testEditNewSection() {
+ $name = 'Help:ApiEditPageTest_testEditNewSection';
+
+ // Test on a page that does not already exist
+ $this->assertFalse( Title::newFromText( $name )->exists() );
+ list( $re ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => 'new',
+ 'text' => 'test',
+ 'summary' => 'header',
+ ));
+
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+ // Check the page text is correct
+ $text = WikiPage::factory( Title::newFromText( $name ) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $text, "== header ==\n\ntest" );
+
+ // Now on one that does
+ $this->assertTrue( Title::newFromText( $name )->exists() );
+ list( $re2 ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => 'new',
+ 'text' => 'test',
+ 'summary' => 'header',
+ ));
+
+ $this->assertEquals( 'Success', $re2['edit']['result'] );
+ $text = WikiPage::factory( Title::newFromText( $name ) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $text, "== header ==\n\ntest\n\n== header ==\n\ntest" );
}
- function testEditConflict() {
+ public function testEditConflict() {
static $count = 0;
$count++;
@@ -224,7 +289,7 @@ class ApiEditPageTest extends ApiTestCase {
// try to save edit, expect conflict
try {
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $name,
'text' => 'nix bar!',
@@ -237,7 +302,7 @@ class ApiEditPageTest extends ApiTestCase {
}
}
- function testEditConflict_redirect() {
+ public function testEditConflict_redirect() {
static $count = 0;
$count++;
@@ -280,7 +345,7 @@ class ApiEditPageTest extends ApiTestCase {
// try again, without following the redirect. Should fail.
try {
- list( $re, , ) = $this->doApiRequestWithToken( array(
+ $this->doApiRequestWithToken( array(
'action' => 'edit',
'title' => $rname,
'text' => 'nix bar!',
@@ -293,13 +358,13 @@ class ApiEditPageTest extends ApiTestCase {
}
}
- function testEditConflict_bug41990() {
+ public function testEditConflict_bug41990() {
static $count = 0;
$count++;
/*
* bug 41990: if the target page has a newer revision than the redirect, then editing the
- * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erronously
+ * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erroneously
* caused an edit conflict to be detected.
*/
diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php
index 902b7b85..ad1e73ab 100644
--- a/tests/phpunit/includes/api/ApiOptionsTest.php
+++ b/tests/phpunit/includes/api/ApiOptionsTest.php
@@ -20,9 +20,11 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
->disableOriginalConstructor()
->getMock();
- // Set up groups
+ // Set up groups and rights
$this->mUserMock->expects( $this->any() )
->method( 'getEffectiveGroups' )->will( $this->returnValue( array( '*', 'user' ) ) );
+ $this->mUserMock->expects( $this->any() )
+ ->method( 'isAllowed' )->will( $this->returnValue( true ) );
// Set up callback for User::getOptionKinds
$this->mUserMock->expects( $this->any() )
@@ -116,6 +118,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
$mapping[$key] = 'unused';
}
}
+
return $mapping;
}
@@ -126,12 +129,14 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
'optionname' => null,
'optionvalue' => null,
);
+
return array_merge( $request, $custom );
}
private function executeQuery( $request ) {
$this->mContext->setRequest( new FauxRequest( $request, true, $this->mSession ) );
$this->mTested->execute();
+
return $this->mTested->getResult()->getData();
}
@@ -156,6 +161,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
} catch ( UsageException $e ) {
$this->assertEquals( 'notloggedin', $e->getCodeString() );
$this->assertEquals( 'Anonymous users cannot change preferences', $e->getMessage() );
+
return;
}
$this->fail( "UsageException was not thrown" );
@@ -169,6 +175,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
} catch ( UsageException $e ) {
$this->assertEquals( 'nooptionname', $e->getCodeString() );
$this->assertEquals( 'The optionname parameter must be set', $e->getMessage() );
+
return;
}
$this->fail( "UsageException was not thrown" );
@@ -191,6 +198,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
} catch ( UsageException $e ) {
$this->assertEquals( 'nochanges', $e->getCodeString() );
$this->assertEquals( 'No changes were requested', $e->getMessage() );
+
return;
}
$this->fail( "UsageException was not thrown" );
@@ -274,21 +282,21 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
$this->mUserMock->expects( $this->at( 2 ) )
->method( 'getOptions' );
- $this->mUserMock->expects( $this->at( 3 ) )
+ $this->mUserMock->expects( $this->at( 4 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeNull' ), $this->identicalTo( null ) );
- $this->mUserMock->expects( $this->at( 4 ) )
+ $this->mUserMock->expects( $this->at( 5 ) )
->method( 'getOptions' );
- $this->mUserMock->expects( $this->at( 5 ) )
+ $this->mUserMock->expects( $this->at( 6 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeEmpty' ), $this->equalTo( '' ) );
- $this->mUserMock->expects( $this->at( 6 ) )
+ $this->mUserMock->expects( $this->at( 7 ) )
->method( 'getOptions' );
- $this->mUserMock->expects( $this->at( 7 ) )
+ $this->mUserMock->expects( $this->at( 8 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) );
@@ -306,17 +314,17 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
$this->mUserMock->expects( $this->once() )
->method( 'resetOptions' );
- $this->mUserMock->expects( $this->at( 3 ) )
+ $this->mUserMock->expects( $this->at( 4 ) )
->method( 'getOptions' );
- $this->mUserMock->expects( $this->at( 4 ) )
+ $this->mUserMock->expects( $this->at( 5 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) );
- $this->mUserMock->expects( $this->at( 5 ) )
+ $this->mUserMock->expects( $this->at( 6 ) )
->method( 'getOptions' );
- $this->mUserMock->expects( $this->at( 6 ) )
+ $this->mUserMock->expects( $this->at( 7 ) )
->method( 'setOption' )
->with( $this->equalTo( 'name' ), $this->equalTo( 'value' ) );
@@ -339,19 +347,19 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
$this->mUserMock->expects( $this->never() )
->method( 'resetOptions' );
- $this->mUserMock->expects( $this->at( 2 ) )
+ $this->mUserMock->expects( $this->at( 3 ) )
->method( 'setOption' )
->with( $this->equalTo( 'testmultiselect-opt1' ), $this->identicalTo( true ) );
- $this->mUserMock->expects( $this->at( 3 ) )
+ $this->mUserMock->expects( $this->at( 4 ) )
->method( 'setOption' )
->with( $this->equalTo( 'testmultiselect-opt2' ), $this->identicalTo( null ) );
- $this->mUserMock->expects( $this->at( 4 ) )
+ $this->mUserMock->expects( $this->at( 5 ) )
->method( 'setOption' )
->with( $this->equalTo( 'testmultiselect-opt3' ), $this->identicalTo( false ) );
- $this->mUserMock->expects( $this->at( 5 ) )
+ $this->mUserMock->expects( $this->at( 6 ) )
->method( 'setOption' )
->with( $this->equalTo( 'testmultiselect-opt4' ), $this->identicalTo( false ) );
@@ -394,7 +402,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
$this->mUserMock->expects( $this->never() )
->method( 'resetOptions' );
- $this->mUserMock->expects( $this->at( 2 ) )
+ $this->mUserMock->expects( $this->at( 3 ) )
->method( 'setOption' )
->with( $this->equalTo( 'userjs-option' ), $this->equalTo( '1' ) );
diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php
index a42e5aa5..2d714e65 100644
--- a/tests/phpunit/includes/api/ApiParseTest.php
+++ b/tests/phpunit/includes/api/ApiParseTest.php
@@ -12,11 +12,11 @@ class ApiParseTest extends ApiTestCase {
$this->doLogin();
}
- function testParseNonexistentPage() {
+ public function testParseNonexistentPage() {
$somePage = mt_rand();
try {
- $data = $this->doApiRequest( array(
+ $this->doApiRequest( array(
'action' => 'parse',
'page' => $somePage ) );
@@ -26,5 +26,4 @@ class ApiParseTest extends ApiTestCase {
"Parse request for nonexistent page must give 'missingtitle' error: " . var_export( $ex->getMessageArray(), true ) );
}
}
-
}
diff --git a/tests/phpunit/includes/api/ApiPurgeTest.php b/tests/phpunit/includes/api/ApiPurgeTest.php
index a7f9229d..28b5ff4d 100644
--- a/tests/phpunit/includes/api/ApiPurgeTest.php
+++ b/tests/phpunit/includes/api/ApiPurgeTest.php
@@ -15,7 +15,7 @@ class ApiPurgeTest extends ApiTestCase {
/**
* @group Broken
*/
- function testPurgeMainPage() {
+ public function testPurgeMainPage() {
if ( !Title::newFromText( 'UTPage' )->exists() ) {
$this->markTestIncomplete( "The article [[UTPage]] does not exist" );
}
@@ -37,5 +37,4 @@ class ApiPurgeTest extends ApiTestCase {
$this->assertArrayHasKey( $pages[$v['title']], $v );
}
}
-
}
diff --git a/tests/phpunit/includes/api/ApiTest.php b/tests/phpunit/includes/api/ApiTest.php
index 22770288..472f8c4a 100644
--- a/tests/phpunit/includes/api/ApiTest.php
+++ b/tests/phpunit/includes/api/ApiTest.php
@@ -7,7 +7,7 @@
*/
class ApiTest extends ApiTestCase {
- function testRequireOnlyOneParameterDefault() {
+ public function testRequireOnlyOneParameterDefault() {
$mock = new MockApi();
$this->assertEquals(
@@ -18,7 +18,7 @@ class ApiTest extends ApiTestCase {
/**
* @expectedException UsageException
*/
- function testRequireOnlyOneParameterZero() {
+ public function testRequireOnlyOneParameterZero() {
$mock = new MockApi();
$this->assertEquals(
@@ -29,7 +29,7 @@ class ApiTest extends ApiTestCase {
/**
* @expectedException UsageException
*/
- function testRequireOnlyOneParameterTrue() {
+ public function testRequireOnlyOneParameterTrue() {
$mock = new MockApi();
$this->assertEquals(
@@ -43,7 +43,7 @@ class ApiTest extends ApiTestCase {
*
* @expectedException UsageException
*/
- function testApi() {
+ public function testApi() {
$api = new ApiMain(
new FauxRequest( array( 'action' => 'help', 'format' => 'xml' ) )
);
@@ -61,14 +61,14 @@ class ApiTest extends ApiTestCase {
/**
* Test result of attempted login with an empty username
*/
- function testApiLoginNoName() {
+ public function testApiLoginNoName() {
$data = $this->doApiRequest( array( 'action' => 'login',
'lgname' => '', 'lgpassword' => self::$users['sysop']->password,
) );
$this->assertEquals( 'NoName', $data[0]['login']['result'] );
}
- function testApiLoginBadPass() {
+ public function testApiLoginBadPass() {
global $wgServer;
$user = self::$users['sysop'];
@@ -81,8 +81,7 @@ class ApiTest extends ApiTestCase {
"action" => "login",
"lgname" => $user->username,
"lgpassword" => "bad",
- )
- );
+ ) );
$result = $ret[0];
@@ -110,7 +109,7 @@ class ApiTest extends ApiTestCase {
$this->assertEquals( "WrongPass", $a );
}
- function testApiLoginGoodPass() {
+ public function testApiLoginGoodPass() {
global $wgServer;
if ( !isset( $wgServer ) ) {
@@ -136,7 +135,7 @@ class ApiTest extends ApiTestCase {
$token = $result["login"]["token"];
$ret = $this->doApiRequest(
- array(
+ array(
"action" => "login",
"lgtoken" => $token,
"lgname" => $user->username,
@@ -156,7 +155,7 @@ class ApiTest extends ApiTestCase {
/**
* @group Broken
*/
- function testApiGotCookie() {
+ public function testApiGotCookie() {
$this->markTestIncomplete( "The server can't do external HTTP requests, and the internal one won't give cookies" );
global $wgServer, $wgScriptPath;
@@ -202,7 +201,7 @@ class ApiTest extends ApiTestCase {
return $cj;
}
- function testRunLogin() {
+ public function testRunLogin() {
$sysopUser = self::$users['sysop'];
$data = $this->doApiRequest( array(
'action' => 'login',
@@ -228,39 +227,33 @@ class ApiTest extends ApiTestCase {
return $data;
}
- function testGettingToken() {
+ public function testGettingToken() {
foreach ( self::$users as $user ) {
$this->runTokenTest( $user );
}
}
function runTokenTest( $user ) {
- $data = $this->getTokenList( $user );
-
- $this->assertArrayHasKey( 'query', $data[0] );
- $this->assertArrayHasKey( 'pages', $data[0]['query'] );
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
+ $tokens = $this->getTokenList( $user );
$rights = $user->user->getRights();
- $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
- $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
- $this->assertArrayHasKey( 'movetoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'edittoken', $tokens );
+ $this->assertArrayHasKey( 'movetoken', $tokens );
if ( isset( $rights['delete'] ) ) {
- $this->assertArrayHasKey( 'deletetoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'deletetoken', $tokens );
}
if ( isset( $rights['block'] ) ) {
- $this->assertArrayHasKey( 'blocktoken', $data[0]['query']['pages'][$key] );
- $this->assertArrayHasKey( 'unblocktoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'blocktoken', $tokens );
+ $this->assertArrayHasKey( 'unblocktoken', $tokens );
}
if ( isset( $rights['protect'] ) ) {
- $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'protecttoken', $tokens );
}
- return $data;
+ return $tokens;
}
}
diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php
index 552fbfbf..94ef9c68 100644
--- a/tests/phpunit/includes/api/ApiTestCase.php
+++ b/tests/phpunit/includes/api/ApiTestCase.php
@@ -52,6 +52,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
$title = Title::newFromText( $pageName, $defaultNs );
$page = WikiPage::factory( $title );
+
return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary );
}
@@ -131,17 +132,22 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
$session['wsEditToken'] = $session['wsToken'];
// add token to request parameters
$params['token'] = md5( $session['wsToken'] ) . User::EDIT_TOKEN_SUFFIX;
+
return $this->doApiRequest( $params, $session, false, $user );
} else {
throw new Exception( "request data not in right format" );
}
}
- protected function doLogin() {
+ protected function doLogin( $user = 'sysop' ) {
+ if ( !array_key_exists( $user, self::$users ) ) {
+ throw new MWException( "Can not log in to undefined user $user" );
+ }
+
$data = $this->doApiRequest( array(
'action' => 'login',
- 'lgname' => self::$users['sysop']->username,
- 'lgpassword' => self::$users['sysop']->password ) );
+ 'lgname' => self::$users[ $user ]->username,
+ 'lgpassword' => self::$users[ $user ]->password ) );
$token = $data[0]['login']['token'];
@@ -149,8 +155,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
array(
'action' => 'login',
'lgtoken' => $token,
- 'lgname' => self::$users['sysop']->username,
- 'lgpassword' => self::$users['sysop']->password,
+ 'lgname' => self::$users[ $user ]->username,
+ 'lgpassword' => self::$users[ $user ]->password,
),
$data[2]
);
@@ -160,11 +166,15 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
protected function getTokenList( $user, $session = null ) {
$data = $this->doApiRequest( array(
- 'action' => 'query',
- 'titles' => 'Main Page',
- 'intoken' => 'edit|delete|protect|move|block|unblock|watch',
- 'prop' => 'info' ), $session, false, $user->user );
- return $data;
+ 'action' => 'tokens',
+ 'type' => 'edit|delete|protect|move|block|unblock|watch'
+ ), $session, false, $user->user );
+
+ if ( !array_key_exists( 'tokens', $data[0] ) ) {
+ throw new MWException( 'Api failed to return a token list' );
+ }
+
+ return $data[0]['tokens'];
}
public function testApiTestGroup() {
@@ -204,11 +214,14 @@ class UserWrapper {
}
class MockApi extends ApiBase {
- public function execute() {}
+ public function execute() {
+ }
- public function getVersion() {}
+ public function getVersion() {
+ }
- public function __construct() {}
+ public function __construct() {
+ }
public function getAllowedParams() {
return array(
@@ -234,6 +247,7 @@ class ApiTestContext extends RequestContext {
if ( $user !== null ) {
$context->setUser( $user );
}
+
return $context;
}
}
diff --git a/tests/phpunit/includes/api/ApiTestCaseUpload.php b/tests/phpunit/includes/api/ApiTestCaseUpload.php
index 80284917..7e18b6ed 100644
--- a/tests/phpunit/includes/api/ApiTestCaseUpload.php
+++ b/tests/phpunit/includes/api/ApiTestCaseUpload.php
@@ -47,6 +47,7 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
// see if it now doesn't exist; reload
$title = Title::newFromText( $title->getText(), NS_FILE );
}
+
return !( $title && $title instanceof Title && $title->exists() );
}
@@ -69,6 +70,7 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
foreach ( $dupes as $dupe ) {
$success &= $this->deleteFileByTitle( $dupe->getTitle() );
}
+
return $success;
}
@@ -105,7 +107,6 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
);
return true;
-
}
function fakeUploadChunk( $fieldName, $fileName, $type, & $chunkData ) {
@@ -145,5 +146,4 @@ abstract class ApiTestCaseUpload extends ApiTestCase {
function clearFakeUploads() {
$_FILES = array();
}
-
}
diff --git a/tests/phpunit/includes/api/ApiUploadTest.php b/tests/phpunit/includes/api/ApiUploadTest.php
index 0d98b04d..1540af55 100644
--- a/tests/phpunit/includes/api/ApiUploadTest.php
+++ b/tests/phpunit/includes/api/ApiUploadTest.php
@@ -16,7 +16,7 @@
// TODO: port the other Upload tests, and other API tests to this framework
-require_once( 'ApiTestCaseUpload.php' );
+require_once 'ApiTestCaseUpload.php';
/**
* @group Database
@@ -27,12 +27,11 @@ require_once( 'ApiTestCaseUpload.php' );
* This is pretty sucky... needs to be prettified.
*/
class ApiUploadTest extends ApiTestCaseUpload {
-
/**
* Testing login
* XXX this is a funny way of getting session context
*/
- function testLogin() {
+ public function testLogin() {
$user = self::$users['uploader'];
$params = array(
@@ -59,8 +58,8 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->assertArrayHasKey( 'lgtoken', $result['login'] );
$this->assertNotEmpty( $session, 'API Login must return a session' );
- return $session;
+ return $session;
}
/**
@@ -118,7 +117,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->deleteFileByFileName( $fileName );
$this->deleteFileByContent( $filePath );
-
if ( !$this->fakeUploadFile( 'file', $fileName, $mimeType, $filePath ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
@@ -140,7 +138,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
}
$this->assertTrue( isset( $result['upload'] ) );
$this->assertEquals( 'Success', $result['upload']['result'] );
- $this->assertEquals( $fileSize, ( int )$result['upload']['imageinfo']['size'] );
+ $this->assertEquals( $fileSize, (int)$result['upload']['imageinfo']['size'] );
$this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
$this->assertFalse( $exception );
@@ -298,7 +296,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$exception = false;
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user );
} catch ( UsageException $e ) {
$exception = true;
@@ -307,7 +305,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->assertEquals( 'Success', $result['upload']['result'] );
$this->assertFalse( $exception );
-
// second upload with the same content (but different name)
if ( !$this->fakeUploadFile( 'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
@@ -324,7 +321,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$exception = false;
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user ); // FIXME: leaks a temporary file
} catch ( UsageException $e ) {
$exception = true;
@@ -341,7 +338,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
unlink( $filePaths[0] );
}
-
/**
* @depends testLogin
*/
@@ -382,7 +378,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$exception = false;
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user ); // FIXME: leaks a temporary file
} catch ( UsageException $e ) {
$exception = true;
@@ -390,7 +386,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->assertFalse( $exception );
$this->assertTrue( isset( $result['upload'] ) );
$this->assertEquals( 'Success', $result['upload']['result'] );
- $this->assertEquals( $fileSize, ( int )$result['upload']['imageinfo']['size'] );
+ $this->assertEquals( $fileSize, (int)$result['upload']['imageinfo']['size'] );
$this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
$this->assertEquals( $result['upload']['sessionkey'], $result['upload']['filekey'] );
@@ -411,7 +407,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->clearFakeUploads();
$exception = false;
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user );
} catch ( UsageException $e ) {
$exception = true;
@@ -454,7 +450,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->deleteFileByFileName( $fileName );
$this->deleteFileByContent( $filePath );
- // Base upload params:
+ // Base upload params:
$params = array(
'action' => 'upload',
'stash' => 1,
@@ -466,7 +462,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
// Upload chunks
$chunkSessionKey = false;
$resultOffset = 0;
- // Open the file:
+ // Open the file:
$handle = @fopen( $filePath, "r" );
if ( $handle === false ) {
$this->markTestIncomplete( "could not open file: $filePath" );
@@ -482,15 +478,15 @@ class ApiUploadTest extends ApiTestCaseUpload {
if ( !$chunkSessionKey ) {
// Upload fist chunk ( and get the session key )
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user );
} catch ( UsageException $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
- // Make sure we got a valid chunk continue:
+ // Make sure we got a valid chunk continue:
$this->assertTrue( isset( $result['upload'] ) );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
- // If we don't get a session key mark test incomplete.
+ // If we don't get a session key mark test incomplete.
if ( !isset( $result['upload']['filekey'] ) ) {
$this->markTestIncomplete( "no filekey provided" );
}
@@ -509,16 +505,16 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->assertEquals( $resultOffset, $params['offset'] );
// Upload current chunk
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result, , $session ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user );
} catch ( UsageException $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
- // Make sure we got a valid chunk continue:
+ // Make sure we got a valid chunk continue:
$this->assertTrue( isset( $result['upload'] ) );
$this->assertTrue( isset( $result['upload']['filekey'] ) );
- // Check if we were on the last chunk:
+ // Check if we were on the last chunk:
if ( $params['offset'] + $chunkSize >= $fileSize ) {
$this->assertEquals( 'Success', $result['upload']['result'] );
break;
@@ -548,7 +544,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
$this->clearFakeUploads();
$exception = false;
try {
- list( $result, $request, $session ) = $this->doApiRequestWithToken( $params, $session,
+ list( $result ) = $this->doApiRequestWithToken( $params, $session,
self::$users['uploader']->user );
} catch ( UsageException $e ) {
$exception = true;
@@ -559,7 +555,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- // don't remove downloaded temporary file for fast subquent tests.
+ // don't remove downloaded temporary file for fast subquent tests.
//unlink( $filePath );
}
}
diff --git a/tests/phpunit/includes/api/ApiWatchTest.php b/tests/phpunit/includes/api/ApiWatchTest.php
index aefd9398..028ea9ff 100644
--- a/tests/phpunit/includes/api/ApiWatchTest.php
+++ b/tests/phpunit/includes/api/ApiWatchTest.php
@@ -7,32 +7,25 @@
* @todo This test suite is severly broken and need a full review
*/
class ApiWatchTest extends ApiTestCase {
-
protected function setUp() {
parent::setUp();
$this->doLogin();
}
function getTokens() {
- $data = $this->getTokenList( self::$users['sysop'] );
-
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
- $pageinfo = $data[0]['query']['pages'][$key];
-
- return $pageinfo;
+ return $this->getTokenList( self::$users['sysop'] );
}
/**
*/
- function testWatchEdit() {
- $pageinfo = $this->getTokens();
+ public function testWatchEdit() {
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'edit',
'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
'text' => 'new text',
- 'token' => $pageinfo['edittoken'],
+ 'token' => $tokens['edittoken'],
'watchlist' => 'watch' ) );
$this->assertArrayHasKey( 'edit', $data[0] );
$this->assertArrayHasKey( 'result', $data[0]['edit'] );
@@ -44,9 +37,8 @@ class ApiWatchTest extends ApiTestCase {
/**
* @depends testWatchEdit
*/
- function testWatchClear() {
-
- $pageinfo = $this->getTokens();
+ public function testWatchClear() {
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'query',
@@ -60,7 +52,7 @@ class ApiWatchTest extends ApiTestCase {
'action' => 'watch',
'title' => $page['title'],
'unwatch' => true,
- 'token' => $pageinfo['watchtoken'] ) );
+ 'token' => $tokens['watchtoken'] ) );
}
}
$data = $this->doApiRequest( array(
@@ -75,13 +67,12 @@ class ApiWatchTest extends ApiTestCase {
/**
*/
- function testWatchProtect() {
-
- $pageinfo = $this->getTokens();
+ public function testWatchProtect() {
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'protect',
- 'token' => $pageinfo['protecttoken'],
+ 'token' => $tokens['protecttoken'],
'title' => 'Help:UTPage',
'protections' => 'edit=sysop',
'watchlist' => 'unwatch' ) );
@@ -94,9 +85,8 @@ class ApiWatchTest extends ApiTestCase {
/**
*/
- function testGetRollbackToken() {
-
- $pageinfo = $this->getTokens();
+ public function testGetRollbackToken() {
+ $this->getTokens();
if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
$this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
@@ -131,7 +121,7 @@ class ApiWatchTest extends ApiTestCase {
*
* @depends testGetRollbackToken
*/
- function testWatchRollback( $data ) {
+ public function testWatchRollback( $data ) {
$keys = array_keys( $data[0]['query']['pages'] );
$key = array_pop( $keys );
$pageinfo = $data[0]['query']['pages'][$key];
@@ -155,23 +145,4 @@ class ApiWatchTest extends ApiTestCase {
}
}
}
-
- /**
- */
- function testWatchDelete() {
- $pageinfo = $this->getTokens();
-
- $data = $this->doApiRequest( array(
- 'action' => 'delete',
- 'token' => $pageinfo['deletetoken'],
- 'title' => 'Help:UTPage' ) );
- $this->assertArrayHasKey( 'delete', $data[0] );
- $this->assertArrayHasKey( 'title', $data[0]['delete'] );
-
- $data = $this->doApiRequest( array(
- 'action' => 'query',
- 'list' => 'watchlist' ) );
-
- $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
- }
}
diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php b/tests/phpunit/includes/api/RandomImageGenerator.php
index 30407582..59756b21 100644
--- a/tests/phpunit/includes/api/RandomImageGenerator.php
+++ b/tests/phpunit/includes/api/RandomImageGenerator.php
@@ -34,7 +34,7 @@ class RandomImageGenerator {
private $shapesToDraw = 5;
/**
- * Orientations: 0th row, 0th column, EXIF orientation code, rotation 2x2 matrix that is opposite of orientation
+ * Orientations: 0th row, 0th column, Exif orientation code, rotation 2x2 matrix that is opposite of orientation
* n.b. we do not handle the 'flipped' orientations, which is why there is no entry for 2, 4, 5, or 7. Those
* seem to be rare in real images anyway
* (we also would need a non-symmetric shape for the images to test those, like a letter F)
@@ -108,6 +108,7 @@ class RandomImageGenerator {
foreach ( $filenames as $filename ) {
$this->{$imageWriteMethod}( $this->getImageSpec(), $format, $filename );
}
+
return $filenames;
}
@@ -156,7 +157,6 @@ class RandomImageGenerator {
}
return $filenames;
-
}
@@ -196,7 +196,6 @@ class RandomImageGenerator {
array( 'x' => $originX, 'y' => $originY - $radius )
);
$draws[] = $draw;
-
}
$spec['draws'] = $draws;
@@ -216,6 +215,7 @@ class RandomImageGenerator {
foreach ( $shape as $point ) {
$points[] = $point['x'] . ',' . $point['y'];
}
+
return join( " ", $points );
}
@@ -304,7 +304,7 @@ class RandomImageGenerator {
/**
* Given an image specification, produce rotated version
- * This is used when simulating a rotated image capture with EXIF orientation
+ * This is used when simulating a rotated image capture with Exif orientation
* @param $spec Object returned by getImageSpec
* @param $matrix 2x2 transformation matrix
* @return transformed Spec
@@ -337,6 +337,7 @@ class RandomImageGenerator {
}
$tSpec['draws'][] = $tDraw;
}
+
return $tSpec;
}
@@ -384,6 +385,7 @@ class RandomImageGenerator {
$command = wfEscapeShellArg( $wgImageMagickConvertCommand ) . " " . implode( " ", $args );
$retval = null;
wfShellExec( $command, $retval );
+
return ( $retval === 0 );
}
@@ -397,6 +399,7 @@ class RandomImageGenerator {
for ( $i = 0; $i <= 2; $i++ ) {
$components[] = mt_rand( 0, 255 );
}
+
return 'rgb(' . join( ', ', $components ) . ')';
}
@@ -414,6 +417,7 @@ class RandomImageGenerator {
for ( $i = 0; $i < $count; $i += 2 ) {
$pairs[] = array( $lines[$i], $lines[$i + 1] );
}
+
return $pairs;
}
@@ -461,5 +465,4 @@ class RandomImageGenerator {
return $lines;
}
-
}
diff --git a/tests/phpunit/includes/api/format/ApiFormatPhpTest.php b/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
index a59983d8..a0bbb2dc 100644
--- a/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
+++ b/tests/phpunit/includes/api/format/ApiFormatPhpTest.php
@@ -7,13 +7,11 @@
*/
class ApiFormatPhpTest extends ApiFormatTestBase {
- function testValidPhpSyntax() {
+ public function testValidPhpSyntax() {
$data = $this->apiRequest( 'php', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
$this->assertInternalType( 'array', unserialize( $data ) );
$this->assertGreaterThan( 0, count( (array)$data ) );
-
}
-
}
diff --git a/tests/phpunit/includes/api/generateRandomImages.php b/tests/phpunit/includes/api/generateRandomImages.php
index bdd15c48..87f5c4c0 100644
--- a/tests/phpunit/includes/api/generateRandomImages.php
+++ b/tests/phpunit/includes/api/generateRandomImages.php
@@ -6,8 +6,8 @@
*/
// Start up MediaWiki in command-line mode
-require_once( __DIR__ . "/../../../../maintenance/Maintenance.php" );
-require( __DIR__ . "/RandomImageGenerator.php" );
+require_once __DIR__ . "/../../../../maintenance/Maintenance.php";
+require __DIR__ . "/RandomImageGenerator.php";
class GenerateRandomImages extends Maintenance {
@@ -43,4 +43,4 @@ class GenerateRandomImages extends Maintenance {
}
$maintClass = 'GenerateRandomImages';
-require( RUN_MAINTENANCE_IF_MAIN );
+require RUN_MAINTENANCE_IF_MAIN;
diff --git a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php
index 6d4e3711..1a2aa832 100644
--- a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php
@@ -24,7 +24,7 @@
* @file
*/
-require_once( 'ApiQueryTestBase.php' );
+require_once 'ApiQueryTestBase.php';
/** These tests validate basic functionality of the api query module
*
@@ -67,7 +67,10 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
'title' => 'AQBT-All',
'links' => array(
array( 'ns' => 0, 'title' => 'AQBT-Links' ),
- ) ) ) ) );
+ )
+ )
+ ) )
+ );
private static $templates = array(
array( 'prop' => 'templates', 'titles' => 'AQBT-All' ),
@@ -78,7 +81,10 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
'title' => 'AQBT-All',
'templates' => array(
array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
- ) ) ) ) );
+ )
+ )
+ ) )
+ );
private static $categories = array(
array( 'prop' => 'categories', 'titles' => 'AQBT-All' ),
@@ -89,7 +95,10 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
'title' => 'AQBT-All',
'categories' => array(
array( 'ns' => 14, 'title' => 'Category:AQBT-Cat' ),
- ) ) ) ) );
+ )
+ )
+ ) )
+ );
private static $allpages = array(
array( 'list' => 'allpages', 'apprefix' => 'AQBT-' ),
@@ -98,7 +107,8 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
array( 'pageid' => 3, 'ns' => 0, 'title' => 'AQBT-Links' ),
array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
- ) ) );
+ ) )
+ );
private static $alllinks = array(
array( 'list' => 'alllinks', 'alprefix' => 'AQBT-' ),
@@ -107,40 +117,46 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
array( 'ns' => 0, 'title' => 'AQBT-Categories' ),
array( 'ns' => 0, 'title' => 'AQBT-Links' ),
array( 'ns' => 0, 'title' => 'AQBT-Templates' ),
- ) ) );
+ ) )
+ );
private static $alltransclusions = array(
array( 'list' => 'alltransclusions', 'atprefix' => 'AQBT-' ),
array( 'alltransclusions' => array(
array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
array( 'ns' => 10, 'title' => 'Template:AQBT-T' ),
- ) ) );
+ ) )
+ );
private static $allcategories = array(
array( 'list' => 'allcategories', 'acprefix' => 'AQBT-' ),
array( 'allcategories' => array(
array( '*' => 'AQBT-Cat' ),
- ) ) );
+ ) )
+ );
private static $backlinks = array(
array( 'list' => 'backlinks', 'bltitle' => 'AQBT-Links' ),
array( 'backlinks' => array(
array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
- ) ) );
+ ) )
+ );
private static $embeddedin = array(
array( 'list' => 'embeddedin', 'eititle' => 'Template:AQBT-T' ),
array( 'embeddedin' => array(
array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
array( 'pageid' => 4, 'ns' => 0, 'title' => 'AQBT-Templates' ),
- ) ) );
+ ) )
+ );
private static $categorymembers = array(
array( 'list' => 'categorymembers', 'cmtitle' => 'Category:AQBT-Cat' ),
array( 'categorymembers' => array(
array( 'pageid' => 1, 'ns' => 0, 'title' => 'AQBT-All' ),
array( 'pageid' => 2, 'ns' => 0, 'title' => 'AQBT-Categories' ),
- ) ) );
+ ) )
+ );
private static $generatorAllpages = array(
array( 'generator' => 'allpages', 'gapprefix' => 'AQBT-' ),
@@ -161,7 +177,8 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
'pageid' => 4,
'ns' => 0,
'title' => 'AQBT-Templates' ),
- ) ) );
+ ) )
+ );
private static $generatorLinks = array(
array( 'generator' => 'links', 'titles' => 'AQBT-Links' ),
@@ -178,14 +195,17 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
'pageid' => 4,
'ns' => 0,
'title' => 'AQBT-Templates' ),
- ) ) );
+ ) )
+ );
private static $generatorLinksPropLinks = array(
array( 'prop' => 'links' ),
array( 'pages' => array(
'1' => array( 'links' => array(
array( 'ns' => 0, 'title' => 'AQBT-Links' ),
- ) ) ) ) );
+ ) )
+ ) )
+ );
private static $generatorLinksPropTemplates = array(
array( 'prop' => 'templates' ),
@@ -194,7 +214,8 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
'4' => array( 'templates' => array(
array( 'ns' => 10, 'title' => 'Template:AQBT-T' ) ) ),
- ) ) );
+ ) )
+ );
/**
* Test basic props
@@ -300,6 +321,32 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
}
/**
+ * Test bug 51821
+ */
+ public function testGeneratorRedirects() {
+ $this->editPage( 'AQBT-Target', 'test' );
+ $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
+ $this->check( array(
+ array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
+ array(
+ 'redirects' => array(
+ array(
+ 'from' => 'AQBT-Redir',
+ 'to' => 'AQBT-Target',
+ )
+ ),
+ 'pages' => array(
+ '6' => array(
+ 'pageid' => 6,
+ 'ns' => 0,
+ 'title' => 'AQBT-Target',
+ )
+ ),
+ )
+ ) );
+ }
+
+ /**
* Recursively merges the expected values in the $item into the $all
*/
private function mergeExpected( &$all, $item ) {
diff --git a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php
index 0a3ac1da..4d5ddbae 100644
--- a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php
+++ b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php
@@ -18,7 +18,7 @@
* http://www.gnu.org/copyleft/gpl.html
*/
-require_once( 'ApiQueryContinueTestBase.php' );
+require_once 'ApiQueryContinueTestBase.php';
/**
* @group API
@@ -48,7 +48,7 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase {
*/
public function testA() {
$this->mVerbose = false;
- $mk = function( $g, $p, $gDir ) {
+ $mk = function ( $g, $p, $gDir ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT73462-',
@@ -59,10 +59,10 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase {
);
};
// generator + 1 prop + 1 list
- $data = $this->query( $mk(99,99,true), 1, 'g1p', false );
- $this->checkC( $data, $mk(1,1,true), 6, 'g1p-11t' );
- $this->checkC( $data, $mk(2,2,true), 3, 'g1p-22t' );
- $this->checkC( $data, $mk(1,1,false), 6, 'g1p-11f' );
- $this->checkC( $data, $mk(2,2,false), 3, 'g1p-22f' );
+ $data = $this->query( $mk( 99, 99, true ), 1, 'g1p', false );
+ $this->checkC( $data, $mk( 1, 1, true ), 6, 'g1p-11t' );
+ $this->checkC( $data, $mk( 2, 2, true ), 3, 'g1p-22t' );
+ $this->checkC( $data, $mk( 1, 1, false ), 6, 'g1p-11f' );
+ $this->checkC( $data, $mk( 2, 2, false ), 3, 'g1p-22f' );
}
}
diff --git a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php
index cb8f1812..f494e9ca 100644
--- a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php
@@ -18,7 +18,7 @@
* http://www.gnu.org/copyleft/gpl.html
*/
-require_once( 'ApiQueryContinueTestBase.php' );
+require_once 'ApiQueryContinueTestBase.php';
/**
* These tests validate the new continue functionality of the api query module by
@@ -58,21 +58,21 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function test1List() {
$this->mVerbose = false;
- $mk = function( $l ) {
+ $mk = function ( $l ) {
return array(
'list' => 'allpages',
'apprefix' => 'AQCT-',
'aplimit' => "$l",
);
};
- $data = $this->query( $mk(99), 1, '1L', false );
+ $data = $this->query( $mk( 99 ), 1, '1L', false );
// 1 list
- $this->checkC( $data, $mk(1), 5, '1L-1' );
- $this->checkC( $data, $mk(2), 3, '1L-2' );
- $this->checkC( $data, $mk(3), 2, '1L-3' );
- $this->checkC( $data, $mk(4), 2, '1L-4' );
- $this->checkC( $data, $mk(5), 1, '1L-5' );
+ $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
+ $this->checkC( $data, $mk( 2 ), 3, '1L-2' );
+ $this->checkC( $data, $mk( 3 ), 2, '1L-3' );
+ $this->checkC( $data, $mk( 4 ), 2, '1L-4' );
+ $this->checkC( $data, $mk( 5 ), 1, '1L-5' );
}
/**
@@ -81,7 +81,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function test2Lists() {
$this->mVerbose = false;
- $mk = function( $l1, $l2 ) {
+ $mk = function ( $l1, $l2 ) {
return array(
'list' => 'allpages|alltransclusions',
'apprefix' => 'AQCT-',
@@ -92,12 +92,12 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// 2 lists
- $data = $this->query( $mk(99,99), 1, '2L', false );
- $this->checkC( $data, $mk(1,1), 5, '2L-11' );
- $this->checkC( $data, $mk(2,2), 3, '2L-22' );
- $this->checkC( $data, $mk(3,3), 2, '2L-33' );
- $this->checkC( $data, $mk(4,4), 2, '2L-44' );
- $this->checkC( $data, $mk(5,5), 1, '2L-55' );
+ $data = $this->query( $mk( 99, 99 ), 1, '2L', false );
+ $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
+ $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
+ $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
+ $this->checkC( $data, $mk( 4, 4 ), 2, '2L-44' );
+ $this->checkC( $data, $mk( 5, 5 ), 1, '2L-55' );
}
/**
@@ -106,7 +106,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function testGen1Prop() {
$this->mVerbose = false;
- $mk = function( $g, $p ) {
+ $mk = function ( $g, $p ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT-',
@@ -116,12 +116,12 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 1 prop
- $data = $this->query( $mk(99,99), 1, 'G1P', false );
- $this->checkC( $data, $mk(1,1), 11, 'G1P-11' );
- $this->checkC( $data, $mk(2,2), 6, 'G1P-22' );
- $this->checkC( $data, $mk(3,3), 4, 'G1P-33' );
- $this->checkC( $data, $mk(4,4), 3, 'G1P-44' );
- $this->checkC( $data, $mk(5,5), 2, 'G1P-55' );
+ $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false );
+ $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
+ $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
+ $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
+ $this->checkC( $data, $mk( 4, 4 ), 3, 'G1P-44' );
+ $this->checkC( $data, $mk( 5, 5 ), 2, 'G1P-55' );
}
/**
@@ -130,7 +130,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function testGen2Prop() {
$this->mVerbose = false;
- $mk = function( $g, $p1, $p2 ) {
+ $mk = function ( $g, $p1, $p2 ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT-',
@@ -141,17 +141,17 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 2 props
- $data = $this->query( $mk(99,99,99), 1, 'G2P', false );
- $this->checkC( $data, $mk(1,1,1), 16, 'G2P-111' );
- $this->checkC( $data, $mk(2,2,2), 9, 'G2P-222' );
- $this->checkC( $data, $mk(3,3,3), 6, 'G2P-333' );
- $this->checkC( $data, $mk(4,4,4), 4, 'G2P-444' );
- $this->checkC( $data, $mk(5,5,5), 2, 'G2P-555' );
- $this->checkC( $data, $mk(5,1,1), 10, 'G2P-511' );
- $this->checkC( $data, $mk(4,2,2), 7, 'G2P-422' );
- $this->checkC( $data, $mk(2,3,3), 7, 'G2P-233' );
- $this->checkC( $data, $mk(2,4,4), 5, 'G2P-244' );
- $this->checkC( $data, $mk(1,5,5), 5, 'G2P-155' );
+ $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false );
+ $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
+ $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
+ $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
+ $this->checkC( $data, $mk( 4, 4, 4 ), 4, 'G2P-444' );
+ $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G2P-555' );
+ $this->checkC( $data, $mk( 5, 1, 1 ), 10, 'G2P-511' );
+ $this->checkC( $data, $mk( 4, 2, 2 ), 7, 'G2P-422' );
+ $this->checkC( $data, $mk( 2, 3, 3 ), 7, 'G2P-233' );
+ $this->checkC( $data, $mk( 2, 4, 4 ), 5, 'G2P-244' );
+ $this->checkC( $data, $mk( 1, 5, 5 ), 5, 'G2P-155' );
}
/**
@@ -160,7 +160,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function testGen1Prop1List() {
$this->mVerbose = false;
- $mk = function( $g, $p, $l ) {
+ $mk = function ( $g, $p, $l ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT-',
@@ -174,24 +174,24 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 1 prop + 1 list
- $data = $this->query( $mk(99,99,99), 1, 'G1P1L', false );
- $this->checkC( $data, $mk(1,1,1), 11, 'G1P1L-111' );
- $this->checkC( $data, $mk(2,2,2), 6, 'G1P1L-222' );
- $this->checkC( $data, $mk(3,3,3), 4, 'G1P1L-333' );
- $this->checkC( $data, $mk(4,4,4), 3, 'G1P1L-444' );
- $this->checkC( $data, $mk(5,5,5), 2, 'G1P1L-555' );
- $this->checkC( $data, $mk(5,5,1), 4, 'G1P1L-551' );
- $this->checkC( $data, $mk(5,5,2), 2, 'G1P1L-552' );
+ $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false );
+ $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
+ $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
+ $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
+ $this->checkC( $data, $mk( 4, 4, 4 ), 3, 'G1P1L-444' );
+ $this->checkC( $data, $mk( 5, 5, 5 ), 2, 'G1P1L-555' );
+ $this->checkC( $data, $mk( 5, 5, 1 ), 4, 'G1P1L-551' );
+ $this->checkC( $data, $mk( 5, 5, 2 ), 2, 'G1P1L-552' );
}
/**
* Test smart continue - generator=allpages, prop=links|templates,
- * list=alllinks|alltransclusions, meta=siteinfo
+ * list=alllinks|alltransclusions, meta=siteinfo
* @medium
*/
public function testGen2Prop2List1Meta() {
$this->mVerbose = false;
- $mk = function( $g, $p1, $p2, $l1, $l2 ) {
+ $mk = function ( $g, $p1, $p2, $l1, $l2 ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT-',
@@ -211,16 +211,16 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 1 prop + 1 list
- $data = $this->query( $mk(99,99,99,99,99), 1, 'G2P2L1M', false );
- $this->checkC( $data, $mk(1,1,1,1,1), 16, 'G2P2L1M-11111' );
- $this->checkC( $data, $mk(2,2,2,2,2), 9, 'G2P2L1M-22222' );
- $this->checkC( $data, $mk(3,3,3,3,3), 6, 'G2P2L1M-33333' );
- $this->checkC( $data, $mk(4,4,4,4,4), 4, 'G2P2L1M-44444' );
- $this->checkC( $data, $mk(5,5,5,5,5), 2, 'G2P2L1M-55555' );
- $this->checkC( $data, $mk(5,5,5,1,1), 4, 'G2P2L1M-55511' );
- $this->checkC( $data, $mk(5,5,5,2,2), 2, 'G2P2L1M-55522' );
- $this->checkC( $data, $mk(5,1,1,5,5), 10, 'G2P2L1M-51155' );
- $this->checkC( $data, $mk(5,2,2,5,5), 5, 'G2P2L1M-52255' );
+ $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false );
+ $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
+ $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
+ $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
+ $this->checkC( $data, $mk( 4, 4, 4, 4, 4 ), 4, 'G2P2L1M-44444' );
+ $this->checkC( $data, $mk( 5, 5, 5, 5, 5 ), 2, 'G2P2L1M-55555' );
+ $this->checkC( $data, $mk( 5, 5, 5, 1, 1 ), 4, 'G2P2L1M-55511' );
+ $this->checkC( $data, $mk( 5, 5, 5, 2, 2 ), 2, 'G2P2L1M-55522' );
+ $this->checkC( $data, $mk( 5, 1, 1, 5, 5 ), 10, 'G2P2L1M-51155' );
+ $this->checkC( $data, $mk( 5, 2, 2, 5, 5 ), 5, 'G2P2L1M-52255' );
}
/**
@@ -229,7 +229,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function testSameGenAndProp() {
$this->mVerbose = false;
- $mk = function( $g, $gDir, $p, $pDir ) {
+ $mk = function ( $g, $gDir, $p, $pDir ) {
return array(
'titles' => 'AQCT-1',
'generator' => 'templates',
@@ -241,31 +241,31 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 1 prop
- $data = $this->query( $mk(99,true,99,true), 1, 'G=P', false );
+ $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false );
- $this->checkC( $data, $mk(1,true,1,true), 4, 'G=P-1t1t' );
- $this->checkC( $data, $mk(2,true,2,true), 2, 'G=P-2t2t' );
- $this->checkC( $data, $mk(3,true,3,true), 2, 'G=P-3t3t' );
- $this->checkC( $data, $mk(1,true,3,true), 4, 'G=P-1t3t' );
- $this->checkC( $data, $mk(3,true,1,true), 2, 'G=P-3t1t' );
+ $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
+ $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
+ $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=P-3t3t' );
+ $this->checkC( $data, $mk( 1, true, 3, true ), 4, 'G=P-1t3t' );
+ $this->checkC( $data, $mk( 3, true, 1, true ), 2, 'G=P-3t1t' );
- $this->checkC( $data, $mk(1,true,1,false), 4, 'G=P-1t1f' );
- $this->checkC( $data, $mk(2,true,2,false), 2, 'G=P-2t2f' );
- $this->checkC( $data, $mk(3,true,3,false), 2, 'G=P-3t3f' );
- $this->checkC( $data, $mk(1,true,3,false), 4, 'G=P-1t3f' );
- $this->checkC( $data, $mk(3,true,1,false), 2, 'G=P-3t1f' );
+ $this->checkC( $data, $mk( 1, true, 1, false ), 4, 'G=P-1t1f' );
+ $this->checkC( $data, $mk( 2, true, 2, false ), 2, 'G=P-2t2f' );
+ $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=P-3t3f' );
+ $this->checkC( $data, $mk( 1, true, 3, false ), 4, 'G=P-1t3f' );
+ $this->checkC( $data, $mk( 3, true, 1, false ), 2, 'G=P-3t1f' );
- $this->checkC( $data, $mk(1,false,1,true), 4, 'G=P-1f1t' );
- $this->checkC( $data, $mk(2,false,2,true), 2, 'G=P-2f2t' );
- $this->checkC( $data, $mk(3,false,3,true), 2, 'G=P-3f3t' );
- $this->checkC( $data, $mk(1,false,3,true), 4, 'G=P-1f3t' );
- $this->checkC( $data, $mk(3,false,1,true), 2, 'G=P-3f1t' );
+ $this->checkC( $data, $mk( 1, false, 1, true ), 4, 'G=P-1f1t' );
+ $this->checkC( $data, $mk( 2, false, 2, true ), 2, 'G=P-2f2t' );
+ $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=P-3f3t' );
+ $this->checkC( $data, $mk( 1, false, 3, true ), 4, 'G=P-1f3t' );
+ $this->checkC( $data, $mk( 3, false, 1, true ), 2, 'G=P-3f1t' );
- $this->checkC( $data, $mk(1,false,1,false), 4, 'G=P-1f1f' );
- $this->checkC( $data, $mk(2,false,2,false), 2, 'G=P-2f2f' );
- $this->checkC( $data, $mk(3,false,3,false), 2, 'G=P-3f3f' );
- $this->checkC( $data, $mk(1,false,3,false), 4, 'G=P-1f3f' );
- $this->checkC( $data, $mk(3,false,1,false), 2, 'G=P-3f1f' );
+ $this->checkC( $data, $mk( 1, false, 1, false ), 4, 'G=P-1f1f' );
+ $this->checkC( $data, $mk( 2, false, 2, false ), 2, 'G=P-2f2f' );
+ $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=P-3f3f' );
+ $this->checkC( $data, $mk( 1, false, 3, false ), 4, 'G=P-1f3f' );
+ $this->checkC( $data, $mk( 3, false, 1, false ), 2, 'G=P-3f1f' );
}
/**
@@ -274,7 +274,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
*/
public function testSameGenList() {
$this->mVerbose = false;
- $mk = function( $g, $gDir, $l, $pDir ) {
+ $mk = function ( $g, $gDir, $l, $pDir ) {
return array(
'generator' => 'allpages',
'gapprefix' => 'AQCT-',
@@ -287,27 +287,27 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
);
};
// generator + 1 list
- $data = $this->query( $mk(99,true,99,true), 1, 'G=L', false );
+ $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false );
- $this->checkC( $data, $mk(1,true,1,true), 5, 'G=L-1t1t' );
- $this->checkC( $data, $mk(2,true,2,true), 3, 'G=L-2t2t' );
- $this->checkC( $data, $mk(3,true,3,true), 2, 'G=L-3t3t' );
- $this->checkC( $data, $mk(1,true,3,true), 5, 'G=L-1t3t' );
- $this->checkC( $data, $mk(3,true,1,true), 5, 'G=L-3t1t' );
- $this->checkC( $data, $mk(1,true,1,false), 5, 'G=L-1t1f' );
- $this->checkC( $data, $mk(2,true,2,false), 3, 'G=L-2t2f' );
- $this->checkC( $data, $mk(3,true,3,false), 2, 'G=L-3t3f' );
- $this->checkC( $data, $mk(1,true,3,false), 5, 'G=L-1t3f' );
- $this->checkC( $data, $mk(3,true,1,false), 5, 'G=L-3t1f' );
- $this->checkC( $data, $mk(1,false,1,true), 5, 'G=L-1f1t' );
- $this->checkC( $data, $mk(2,false,2,true), 3, 'G=L-2f2t' );
- $this->checkC( $data, $mk(3,false,3,true), 2, 'G=L-3f3t' );
- $this->checkC( $data, $mk(1,false,3,true), 5, 'G=L-1f3t' );
- $this->checkC( $data, $mk(3,false,1,true), 5, 'G=L-3f1t' );
- $this->checkC( $data, $mk(1,false,1,false), 5, 'G=L-1f1f' );
- $this->checkC( $data, $mk(2,false,2,false), 3, 'G=L-2f2f' );
- $this->checkC( $data, $mk(3,false,3,false), 2, 'G=L-3f3f' );
- $this->checkC( $data, $mk(1,false,3,false), 5, 'G=L-1f3f' );
- $this->checkC( $data, $mk(3,false,1,false), 5, 'G=L-3f1f' );
+ $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
+ $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );
+ $this->checkC( $data, $mk( 3, true, 3, true ), 2, 'G=L-3t3t' );
+ $this->checkC( $data, $mk( 1, true, 3, true ), 5, 'G=L-1t3t' );
+ $this->checkC( $data, $mk( 3, true, 1, true ), 5, 'G=L-3t1t' );
+ $this->checkC( $data, $mk( 1, true, 1, false ), 5, 'G=L-1t1f' );
+ $this->checkC( $data, $mk( 2, true, 2, false ), 3, 'G=L-2t2f' );
+ $this->checkC( $data, $mk( 3, true, 3, false ), 2, 'G=L-3t3f' );
+ $this->checkC( $data, $mk( 1, true, 3, false ), 5, 'G=L-1t3f' );
+ $this->checkC( $data, $mk( 3, true, 1, false ), 5, 'G=L-3t1f' );
+ $this->checkC( $data, $mk( 1, false, 1, true ), 5, 'G=L-1f1t' );
+ $this->checkC( $data, $mk( 2, false, 2, true ), 3, 'G=L-2f2t' );
+ $this->checkC( $data, $mk( 3, false, 3, true ), 2, 'G=L-3f3t' );
+ $this->checkC( $data, $mk( 1, false, 3, true ), 5, 'G=L-1f3t' );
+ $this->checkC( $data, $mk( 3, false, 1, true ), 5, 'G=L-3f1t' );
+ $this->checkC( $data, $mk( 1, false, 1, false ), 5, 'G=L-1f1f' );
+ $this->checkC( $data, $mk( 2, false, 2, false ), 3, 'G=L-2f2f' );
+ $this->checkC( $data, $mk( 3, false, 3, false ), 2, 'G=L-3f3f' );
+ $this->checkC( $data, $mk( 1, false, 3, false ), 5, 'G=L-1f3f' );
+ $this->checkC( $data, $mk( 3, false, 1, false ), 5, 'G=L-3f1f' );
}
}
diff --git a/tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php b/tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php
index 47174796..fbb1e640 100644
--- a/tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php
+++ b/tests/phpunit/includes/api/query/ApiQueryContinueTestBase.php
@@ -24,7 +24,7 @@
* @file
*/
-require_once( 'ApiQueryTestBase.php' );
+require_once 'ApiQueryTestBase.php';
abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
@@ -36,7 +36,7 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
/**
* Run query() and compare against expected values
*/
- protected function checkC( $expected, $params, $expectedCount, $id, $continue = true ) {
+ protected function checkC( $expected, $params, $expectedCount, $id, $continue = true ) {
$result = $this->query( $params, $expectedCount, $id, $continue );
$this->assertResult( $expected, $result, $id );
}
@@ -52,7 +52,7 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
*/
protected function query( $params, $expectedCount, $id, $useContinue = true ) {
if ( isset( $params['action'] ) ) {
- $this->assertEquals( 'query', $params['action'], 'Invalid query action');
+ $this->assertEquals( 'query', $params['action'], 'Invalid query action' );
} else {
$params['action'] = 'query';
}
@@ -64,17 +64,18 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
$continue = array();
do {
$request = array_merge( $params, $continue );
- uksort( $request, function( $a, $b ) {
+ uksort( $request, function ( $a, $b ) {
// put 'continue' params at the end - lazy method
$a = strpos( $a, 'continue' ) !== false ? 'zzz ' . $a : $a;
$b = strpos( $b, 'continue' ) !== false ? 'zzz ' . $b : $b;
+
return strcmp( $a, $b );
} );
$reqStr = http_build_query( $request );
//$reqStr = str_replace( '&', ' & ', $reqStr );
$this->assertLessThan( $expectedCount, $count, "$id more data: $reqStr" );
if ( $this->mVerbose ) {
- print ("$id (#$count): $reqStr\n");
+ print "$id (#$count): $reqStr\n";
}
try {
$data = $this->doApiRequest( $request );
@@ -103,52 +104,57 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
if ( $expectedCount > $count ) {
print "***** $id Finished early in $count turns. $expectedCount was expected\n";
}
+
return $result;
} elseif ( !$useContinue ) {
$this->assertFalse( 'Non-smart query must be requested all at once' );
}
- } while( true );
+ } while ( true );
}
private function printResult( $data ) {
$q = $data['query'];
$print = array();
- if (isset($q['pages'])) {
- foreach ($q['pages'] as $p) {
+ if ( isset( $q['pages'] ) ) {
+ foreach ( $q['pages'] as $p ) {
$m = $p['title'];
- if (isset($p['links'])) {
- $m .= '/[' . implode(',', array_map(
- function ($v) {
+ if ( isset( $p['links'] ) ) {
+ $m .= '/[' . implode( ',', array_map(
+ function ( $v ) {
return $v['title'];
},
- $p['links'])) . ']';
+ $p['links'] ) ) . ']';
}
- if (isset($p['categories'])) {
- $m .= '/(' . implode(',', array_map(
- function ($v) {
- return str_replace('Category:', '', $v['title']);
+ if ( isset( $p['categories'] ) ) {
+ $m .= '/(' . implode( ',', array_map(
+ function ( $v ) {
+ return str_replace( 'Category:', '', $v['title'] );
},
- $p['categories'])) . ')';
+ $p['categories'] ) ) . ')';
}
$print[] = $m;
}
}
- if (isset($q['allcategories'])) {
- $print[] = '*Cats/(' . implode(',', array_map(
- function ($v) { return $v['*']; },
- $q['allcategories'])) . ')';
+ if ( isset( $q['allcategories'] ) ) {
+ $print[] = '*Cats/(' . implode( ',', array_map(
+ function ( $v ) {
+ return $v['*'];
+ },
+ $q['allcategories'] ) ) . ')';
}
self::GetItems( $q, 'allpages', 'Pages', $print );
self::GetItems( $q, 'alllinks', 'Links', $print );
self::GetItems( $q, 'alltransclusions', 'Trnscl', $print );
- print(' ' . implode(' ', $print) . "\n");
+ print ' ' . implode( ' ', $print ) . "\n";
}
private static function GetItems( $q, $moduleName, $name, &$print ) {
- if (isset($q[$moduleName])) {
- $print[] = "*$name/[" . implode(',',
- array_map( function ($v) { return $v['title']; },
- $q[$moduleName])) . ']';
+ if ( isset( $q[$moduleName] ) ) {
+ $print[] = "*$name/[" . implode( ',',
+ array_map( function ( $v ) {
+ return $v['title'];
+ },
+ $q[$moduleName] ) ) . ']';
}
}
@@ -164,12 +170,12 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
$this->assertEquals( $results, $newResult, 'Repeated result must be the same as before' );
} else {
$sort = null;
- foreach( $newResult as $key => $value ) {
+ foreach ( $newResult as $key => $value ) {
if ( !$numericIds && $sort === null ) {
if ( !is_array( $value ) ) {
$sort = false;
} elseif ( array_key_exists( 'title', $value ) ) {
- $sort = function( $a, $b ) {
+ $sort = function ( $a, $b ) {
return strcmp( $a['title'], $b['title'] );
};
} else {
diff --git a/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php b/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
index 7f5fe91c..1bca2256 100644
--- a/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
@@ -10,7 +10,7 @@ class ApiQueryRevisionsTest extends ApiTestCase {
/**
* @group medium
*/
- function testContentComesWithContentModelAndFormat() {
+ public function testContentComesWithContentModelAndFormat() {
$pageName = 'Help:' . __METHOD__;
$title = Title::newFromText( $pageName );
$page = WikiPage::factory( $title );
diff --git a/tests/phpunit/includes/api/query/ApiQueryTest.php b/tests/phpunit/includes/api/query/ApiQueryTest.php
index 7fb53073..f5645555 100644
--- a/tests/phpunit/includes/api/query/ApiQueryTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryTest.php
@@ -12,7 +12,7 @@ class ApiQueryTest extends ApiTestCase {
$this->doLogin();
}
- function testTitlesGetNormalized() {
+ public function testTitlesGetNormalized() {
global $wgMetaNamespace;
@@ -20,7 +20,6 @@ class ApiQueryTest extends ApiTestCase {
'action' => 'query',
'titles' => 'Project:articleA|article_B' ) );
-
$this->assertArrayHasKey( 'query', $data[0] );
$this->assertArrayHasKey( 'normalized', $data[0]['query'] );
@@ -42,10 +41,9 @@ class ApiQueryTest extends ApiTestCase {
),
$data[0]['query']['normalized'][1]
);
-
}
- function testTitlesAreRejectedIfInvalid() {
+ public function testTitlesAreRejectedIfInvalid() {
$title = false;
while ( !$title || Title::newFromText( $title )->exists() ) {
$title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
@@ -65,5 +63,4 @@ class ApiQueryTest extends ApiTestCase {
$this->assertArrayHasKey( 'missing', $data[0]['query']['pages'][-2] );
$this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
}
-
}
diff --git a/tests/phpunit/includes/api/query/ApiQueryTestBase.php b/tests/phpunit/includes/api/query/ApiQueryTestBase.php
index 7b9f8ede..8ee8ea96 100644
--- a/tests/phpunit/includes/api/query/ApiQueryTestBase.php
+++ b/tests/phpunit/includes/api/query/ApiQueryTestBase.php
@@ -24,7 +24,6 @@
* @file
*/
-
/** This class has some common functionality for testing query module
*/
abstract class ApiQueryTestBase extends ApiTestCase {
@@ -43,11 +42,12 @@ STR;
protected function merge( /*...*/ ) {
$request = array();
$expected = array();
- foreach ( func_get_args() as $v ) {
+ foreach ( func_get_args() as $v ) {
list( $req, $exp ) = $this->validateRequestExpectedPair( $v );
$request = array_merge_recursive( $request, $req );
$this->mergeExpected( $expected, $exp );
}
+
return array( $request, $expected );
}
@@ -57,11 +57,12 @@ STR;
*/
private function validateRequestExpectedPair( $v ) {
$this->assertType( 'array', $v, self::PARAM_ASSERT );
- $this->assertEquals( 2, count($v), self::PARAM_ASSERT );
+ $this->assertEquals( 2, count( $v ), self::PARAM_ASSERT );
$this->assertArrayHasKey( 0, $v, self::PARAM_ASSERT );
$this->assertArrayHasKey( 1, $v, self::PARAM_ASSERT );
$this->assertType( 'array', $v[0], self::PARAM_ASSERT );
$this->assertType( 'array', $v[1], self::PARAM_ASSERT );
+
return $v;
}
@@ -71,7 +72,7 @@ STR;
private function mergeExpected( &$all, $item ) {
foreach ( $item as $k => $v ) {
if ( array_key_exists( $k, $all ) ) {
- if ( is_array ( $all[$k] ) ) {
+ if ( is_array( $all[$k] ) ) {
$this->mergeExpected( $all[$k], $v );
} else {
$this->assertEquals( $all[$k], $v );
@@ -108,10 +109,10 @@ STR;
if ( is_array( $message ) ) {
$message = http_build_query( $message );
}
- print( "\nRequest: $message\n" );
- print( "\nExpected:\n" );
+ print "\nRequest: $message\n";
+ print "\nExpected:\n";
print_r( $exp );
- print( "\nResult:\n" );
+ print "\nResult:\n";
print_r( $result );
throw $e; // rethrow it
}