diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2015-01-16 14:00:07 -0500 |
---|---|---|
committer | Brad Jorsch <bjorsch@wikimedia.org> | 2015-04-20 17:49:37 -0400 |
commit | beab6b009ef45d1d8e62943caa4bceb7a04f0c16 (patch) | |
tree | 600c4b865962317aac53a2fd9cf5bb333120b7e7 /tests/phpunit | |
parent | 6a9428babd1cd78b80fc6cca92e495cd444fc7d3 (diff) | |
download | mediawikicore-beab6b009ef45d1d8e62943caa4bceb7a04f0c16.tar.gz mediawikicore-beab6b009ef45d1d8e62943caa4bceb7a04f0c16.zip |
Change API result data structure to be cleaner in new formats
Nothing in this patch should result in changed output for format=json or
format=php except as noted in RELEASE-NOTES-1.25, and changed output for
format=xml should be similar or cosmetic. However, other code accessing
the result data directly may need to be updated.
Bug: T87053
Bug: T12887
Change-Id: I3500708965cb8869b5aed1543381aad208dadd13
Diffstat (limited to 'tests/phpunit')
6 files changed, 56 insertions, 23 deletions
diff --git a/tests/phpunit/includes/api/ApiContinuationManagerTest.php b/tests/phpunit/includes/api/ApiContinuationManagerTest.php index ea08c0284748..2edf0c6fb1dd 100644 --- a/tests/phpunit/includes/api/ApiContinuationManagerTest.php +++ b/tests/phpunit/includes/api/ApiContinuationManagerTest.php @@ -84,7 +84,7 @@ class ApiContinuationManagerTest extends MediaWikiTestCase { 'gcontinue' => 3, 'continue' => 'gcontinue||', ), $result->getResultData( 'continue' ) ); - $this->assertSame( '', $result->getResultData( 'batchcomplete' ) ); + $this->assertSame( true, $result->getResultData( 'batchcomplete' ) ); $manager = self::getManager( '', $allModules, array( 'mock1', 'mock2' ) ); $this->assertSame( false, $manager->isGeneratorDone() ); diff --git a/tests/phpunit/includes/api/ApiErrorFormatterTest.php b/tests/phpunit/includes/api/ApiErrorFormatterTest.php index 344af62fddeb..8ebdf60f5f19 100644 --- a/tests/phpunit/includes/api/ApiErrorFormatterTest.php +++ b/tests/phpunit/includes/api/ApiErrorFormatterTest.php @@ -15,6 +15,11 @@ class ApiErrorFormatterTest extends MediaWikiTestCase { $result = new ApiResult( 8388608 ); $formatter = new ApiErrorFormatter( $result, Language::factory( $lang ), $format, $useDB ); + // Add default type + $expect1[ApiResult::META_TYPE] = 'assoc'; + $expect2[ApiResult::META_TYPE] = 'assoc'; + $expect3[ApiResult::META_TYPE] = 'assoc'; + $formatter->addWarning( 'string', 'mainpage' ); $formatter->addError( 'err', 'mainpage' ); $this->assertSame( $expect1, $result->getResultData(), 'Simple test' ); @@ -262,6 +267,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase { ApiResult::META_CONTENT => 'warnings', ), ), + ApiResult::META_TYPE => 'assoc', ), $result->getResultData(), 'Simple test' ); $result->reset(); @@ -293,6 +299,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase { ApiResult::META_CONTENT => 'warnings', ), ), + ApiResult::META_TYPE => 'assoc', ), $result->getResultData(), 'Complex test' ); $result->reset(); @@ -315,6 +322,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase { ApiResult::META_CONTENT => 'warnings', ), ), + ApiResult::META_TYPE => 'assoc', ), $result->getResultData(), 'Status test' ); $I = ApiResult::META_INDEXED_TAG_NAME; diff --git a/tests/phpunit/includes/api/ApiResultTest.php b/tests/phpunit/includes/api/ApiResultTest.php index 7e43a240a718..03d058a7cf40 100644 --- a/tests/phpunit/includes/api/ApiResultTest.php +++ b/tests/phpunit/includes/api/ApiResultTest.php @@ -144,7 +144,12 @@ class ApiResultTest extends MediaWikiTestCase { $result2 = new ApiResult( 8388608 ); $result2->addValue( null, 'foo', 'bar' ); ApiResult::setValue( $arr, 'baz', $result2 ); - $this->assertSame( array( 'baz' => array( 'foo' => 'bar' ) ), $arr ); + $this->assertSame( array( + 'baz' => array( + ApiResult::META_TYPE => 'assoc', + 'foo' => 'bar', + ) + ), $arr ); $arr = array(); ApiResult::setValue( $arr, 'foo', "foo\x80bar" ); @@ -182,6 +187,7 @@ class ApiResultTest extends MediaWikiTestCase { 'unnamed 2', 'a' => array( 'b' => array() ), 'setContentValue' => '3', + ApiResult::META_TYPE => 'assoc', ApiResult::META_CONTENT => 'setContentValue', ), $result->getResultData() ); $this->assertSame( 20, $result->getSize() ); @@ -217,7 +223,9 @@ class ApiResultTest extends MediaWikiTestCase { $result->getResultData( array( ApiResult::META_CONTENT ) ) ); $result->reset(); - $this->assertSame( array(), $result->getResultData() ); + $this->assertSame( array( + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); $this->assertSame( 0, $result->getSize() ); $result->addValue( null, 'foo', 1 ); @@ -227,7 +235,7 @@ class ApiResultTest extends MediaWikiTestCase { $result->addValue( null, 'bottom', '2' ); $result->addValue( null, 'foo', '2', ApiResult::OVERRIDE ); $result->addValue( null, 'bar', '2', ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP ); - $this->assertSame( array( 0, 'top', 'foo', 'bar', 'bottom' ), + $this->assertSame( array( 0, 'top', 'foo', 'bar', 'bottom', ApiResult::META_TYPE ), array_keys( $result->getResultData() ) ); $result->reset(); @@ -240,8 +248,10 @@ class ApiResultTest extends MediaWikiTestCase { $result->reset(); $result->addValue( null, 'sub', array( 'foo' => 1 ) ); $result->addValue( null, 'sub', array( 'bar' => 1 ) ); - $this->assertSame( array( 'sub' => array( 'foo' => 1, 'bar' => 1 ) ), - $result->getResultData() ); + $this->assertSame( array( + 'sub' => array( 'foo' => 1, 'bar' => 1 ), + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); try { $result->addValue( null, 'sub', array( 'foo' => 2, 'baz' => 2 ) ); @@ -264,6 +274,7 @@ class ApiResultTest extends MediaWikiTestCase { $this->assertSame( array( 'title' => (string)$title, 'obj' => array( 'foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc' ), + ApiResult::META_TYPE => 'assoc', ), $result->getResultData() ); $fh = tmpfile(); @@ -313,9 +324,15 @@ class ApiResultTest extends MediaWikiTestCase { $result->reset(); $result->addParsedLimit( 'foo', 12 ); - $this->assertSame( array( 'limits' => array( 'foo' => 12 ) ), $result->getResultData() ); + $this->assertSame( array( + 'limits' => array( 'foo' => 12 ), + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); $result->addParsedLimit( 'foo', 13 ); - $this->assertSame( array( 'limits' => array( 'foo' => 13 ) ), $result->getResultData() ); + $this->assertSame( array( + 'limits' => array( 'foo' => 13 ), + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); $this->assertSame( null, $result->getResultData( array( 'foo', 'bar', 'baz' ) ) ); $this->assertSame( 13, $result->getResultData( array( 'limits', 'foo' ) ) ); try { @@ -345,7 +362,13 @@ class ApiResultTest extends MediaWikiTestCase { $result2 = new ApiResult( 8388608 ); $result2->addValue( null, 'foo', 'bar' ); $result->addValue( null, 'baz', $result2 ); - $this->assertSame( array( 'baz' => array( 'foo' => 'bar' ) ), $result->getResultData() ); + $this->assertSame( array( + 'baz' => array( + 'foo' => 'bar', + ApiResult::META_TYPE => 'assoc', + ), + ApiResult::META_TYPE => 'assoc', + ), $result->getResultData() ); $result = new ApiResult( 8388608 ); $result->addValue( null, 'foo', "foo\x80bar" ); @@ -355,6 +378,7 @@ class ApiResultTest extends MediaWikiTestCase { 'foo' => "foo\xef\xbf\xbdbar", 'bar' => "\xc3\xa1", 'baz' => 74, + ApiResult::META_TYPE => 'assoc', ), $result->getResultData() ); } @@ -403,7 +427,7 @@ class ApiResultTest extends MediaWikiTestCase { $result->removePreserveKeysList( null, 'baz' ); $result->addArrayTypeRecursive( null, 'default' ); $result->addArrayType( null, 'array' ); - $this->assertSame( $expect, $result->getResultData() ); + $this->assertEquals( $expect, $result->getResultData() ); $arr = array( 'foo' => array( 'bar' => array() ) ); $expect = array( @@ -1211,7 +1235,7 @@ class ApiResultTest extends MediaWikiTestCase { 'gcontinue' => 3, 'continue' => 'gcontinue||', ), $result->getResultData( 'continue' ) ); - $this->assertSame( '', $result->getResultData( 'batchcomplete' ) ); + $this->assertSame( true, $result->getResultData( 'batchcomplete' ) ); $this->assertSame( array( 'mocklist' => array( 'mlcontinue' => 2 ), 'generator' => array( 'gcontinue' => 3 ), @@ -1229,7 +1253,7 @@ class ApiResultTest extends MediaWikiTestCase { 'gcontinue' => 3, 'continue' => 'gcontinue||mocklist', ), $result->getResultData( 'continue' ) ); - $this->assertSame( '', $result->getResultData( 'batchcomplete' ) ); + $this->assertSame( true, $result->getResultData( 'batchcomplete' ) ); $this->assertSame( array( 'generator' => array( 'gcontinue' => 3 ), ), $result->getResultData( 'query-continue' ) ); @@ -1283,7 +1307,7 @@ class ApiResultTest extends MediaWikiTestCase { 'mlcontinue' => 2, 'continue' => '-||mock1|mock2', ), $result->getResultData( 'continue' ) ); - $this->assertSame( '', $result->getResultData( 'batchcomplete' ) ); + $this->assertSame( true, $result->getResultData( 'batchcomplete' ) ); $this->assertSame( array( 'mocklist' => array( 'mlcontinue' => 2 ), ), $result->getResultData( 'query-continue' ) ); @@ -1296,7 +1320,7 @@ class ApiResultTest extends MediaWikiTestCase { $result->endContinuation( 'raw' ); $result->endContinuation( 'standard' ); $this->assertSame( null, $result->getResultData( 'continue' ) ); - $this->assertSame( '', $result->getResultData( 'batchcomplete' ) ); + $this->assertSame( true, $result->getResultData( 'batchcomplete' ) ); $this->assertSame( null, $result->getResultData( 'query-continue' ) ); $main->setContinuationManager( null ); diff --git a/tests/phpunit/includes/api/format/ApiFormatTestBase.php b/tests/phpunit/includes/api/format/ApiFormatTestBase.php index 67949ab9f2df..cabf62b18a32 100644 --- a/tests/phpunit/includes/api/format/ApiFormatTestBase.php +++ b/tests/phpunit/includes/api/format/ApiFormatTestBase.php @@ -33,6 +33,7 @@ abstract class ApiFormatTestBase extends MediaWikiTestCase { $main->getModuleManager()->addModule( $this->printerName, 'format', $class ); } $result = $main->getResult(); + $result->addArrayType( null, 'default' ); foreach ( $data as $k => $v ) { $result->addValue( null, $k, $v ); } diff --git a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php index 243176139aff..cd735223c25e 100644 --- a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php +++ b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php @@ -61,7 +61,7 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase { }; // generator + 1 prop + 1 list $data = $this->query( $mk( 99, 99, true ), 1, 'g1p', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); diff --git a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php index de9965b6e9dd..d441f4c40632 100644 --- a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php @@ -67,7 +67,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { ); }; $data = $this->query( $mk( 99 ), 1, '1L', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); // 1 list $this->checkC( $data, $mk( 1 ), 5, '1L-1' ); @@ -95,7 +95,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // 2 lists $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); @@ -120,7 +120,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 1 prop $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); @@ -146,7 +146,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 2 props $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); @@ -180,7 +180,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 1 prop + 1 list $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); @@ -218,7 +218,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 1 prop + 1 list $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $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' ); @@ -249,7 +249,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 1 prop $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' ); $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' ); @@ -296,7 +296,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { }; // generator + 1 list $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) + - array( 'batchcomplete' => '' ); + array( 'batchcomplete' => true ); $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' ); $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' ); |