'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, $fh );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$obj->file = $fh;
ApiResult::setValue( $arr, 'sub', $obj );
'Expected exception'
);
}
+ try {
+ $obj->file = $fh;
+ ApiResult::setValue( $arr, null, $obj );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
fclose( $fh );
try {
'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, INF );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
ApiResult::setValue( $arr, 'nan', NAN );
$this->fail( 'Expected exception not thrown' );
'Expected exception'
);
}
+ try {
+ ApiResult::setValue( $arr, null, NAN );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
$arr = array();
$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" );
ApiResult::setValue( $arr, 'bar', "a\xcc\x81" );
ApiResult::setValue( $arr, 'baz', 74 );
+ ApiResult::setValue( $arr, null, "foo\x80bar" );
+ ApiResult::setValue( $arr, null, "a\xcc\x81" );
$this->assertSame( array(
'foo' => "foo\xef\xbf\xbdbar",
'bar' => "\xc3\xa1",
'baz' => 74,
+ 0 => "foo\xef\xbf\xbdbar",
+ 1 => "\xc3\xa1",
), $arr );
}
'unnamed 2',
'a' => array( 'b' => array() ),
'setContentValue' => '3',
+ ApiResult::META_TYPE => 'assoc',
ApiResult::META_CONTENT => 'setContentValue',
), $result->getResultData() );
$this->assertSame( 20, $result->getSize() );
$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 );
$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();
$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 ) );
$this->assertSame( array(
'title' => (string)$title,
'obj' => array( 'foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc' ),
+ ApiResult::META_TYPE => 'assoc',
), $result->getResultData() );
$fh = tmpfile();
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, $fh );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$obj->file = $fh;
$result->addValue( null, 'sub', $obj );
'Expected exception'
);
}
+ try {
+ $obj->file = $fh;
+ $result->addValue( null, null, $obj );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add resource(stream) to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
fclose( $fh );
try {
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, INF );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
try {
$result->addValue( null, 'nan', NAN );
$this->fail( 'Expected exception not thrown' );
'Expected exception'
);
}
+ try {
+ $result->addValue( null, null, NAN );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ $this->assertSame(
+ 'Cannot add non-finite floats to ApiResult',
+ $ex->getMessage(),
+ 'Expected exception'
+ );
+ }
$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 {
$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" );
$result->addValue( null, 'bar', "a\xcc\x81" );
$result->addValue( null, 'baz', 74 );
+ $result->addValue( null, null, "foo\x80bar" );
+ $result->addValue( null, null, "a\xcc\x81" );
$this->assertSame( array(
'foo' => "foo\xef\xbf\xbdbar",
'bar' => "\xc3\xa1",
'baz' => 74,
+ 0 => "foo\xef\xbf\xbdbar",
+ 1 => "\xc3\xa1",
+ ApiResult::META_TYPE => 'assoc',
), $result->getResultData() );
}
$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(
$data[ApiResult::META_CONTENT] = 'bar';
}
+ /**
+ * @covers ApiResult
+ */
+ public function testAddMetadataToResultVars() {
+ $arr = array(
+ 'a' => "foo",
+ 'b' => false,
+ 'c' => 10,
+ 'sequential_numeric_keys' => array( 'a', 'b', 'c' ),
+ 'non_sequential_numeric_keys' => array( 'a', 'b', 4 => 'c' ),
+ 'string_keys' => array(
+ 'one' => 1,
+ 'two' => 2
+ ),
+ 'object_sequential_keys' => (object)array( 'a', 'b', 'c' ),
+ '_type' => "should be overwritten in result",
+ );
+ $this->assertSame( array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array(
+ 'a', 'b', 'c',
+ 'sequential_numeric_keys', 'non_sequential_numeric_keys',
+ 'string_keys', 'object_sequential_keys'
+ ),
+ ApiResult::META_BC_BOOLS => array( 'b' ),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 'a' => "foo",
+ 'b' => false,
+ 'c' => 10,
+ 'sequential_numeric_keys' => array(
+ ApiResult::META_TYPE => 'array',
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'value',
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ ),
+ 'non_sequential_numeric_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 0, 1, 4 ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 0 => 'a',
+ 1 => 'b',
+ 4 => 'c',
+ ),
+ 'string_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 'one', 'two' ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 'one' => 1,
+ 'two' => 2,
+ ),
+ 'object_sequential_keys' => array(
+ ApiResult::META_TYPE => 'kvp',
+ ApiResult::META_KVP_KEY_NAME => 'key',
+ ApiResult::META_PRESERVE_KEYS => array( 0, 1, 2 ),
+ ApiResult::META_BC_BOOLS => array(),
+ ApiResult::META_INDEXED_TAG_NAME => 'var',
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ ),
+ ), ApiResult::addMetadataToResultVars( $arr ) );
+ }
+
/**
* @covers ApiResult
*/
if ( preg_match( '/Use of ApiResult::\S+ was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
return true;
}
+ if ( preg_match( '/Use of ApiMain to ApiResult::__construct was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
+ return true;
+ }
return false;
} );
$reset = new ScopedCallback( 'restore_error_handler' );
'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 ),
'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' ) );
'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' ) );
$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 );
try {
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
new ApiResultTestStringifiableObject()
) );
$this->fail( 'Expected exception not thrown' );
try {
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject( NAN ) );
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject( NAN ) );
$this->fail( 'Expected exception not thrown' );
} catch ( UnexpectedValueException $ex ) {
$this->assertSame(
}
$arr = array();
- ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
+ ApiResult::setValue( $arr, 'foo', new ApiResultTestSerializableObject(
array(
'one' => new ApiResultTestStringifiableObject( '1' ),
'two' => new ApiResultTestSerializableObject( 2 ),