30 'setContentValue' =>
'3',
35 $this->fail(
'Expected exception not thrown' );
38 'Attempting to add element setValue=99, existing value is 1',
46 $this->fail(
'Expected exception not thrown' );
49 'Attempting to set content element as setContentValue2 when setContentValue ' .
50 'is already set as the content element',
57 $this->assertSame(
'99', $arr[
'setValue'] );
62 $arr = [
'foo' => 1,
'bar' => 1 ];
68 $this->assertSame( [ 0,
'top',
'foo',
'bar',
'bottom' ], array_keys( $arr ) );
73 $this->assertSame( [
'sub' => [
'foo' => 1,
'bar' => 1 ] ], $arr );
77 $this->fail(
'Expected exception not thrown' );
80 'Conflicting keys (foo) when attempting to merge element sub',
101 $this->fail(
'Expected exception not thrown' );
104 'Cannot add resource(stream) to ApiResult',
111 $this->fail(
'Expected exception not thrown' );
114 'Cannot add resource(stream) to ApiResult',
122 $this->fail(
'Expected exception not thrown' );
125 'Cannot add resource(stream) to ApiResult',
133 $this->fail(
'Expected exception not thrown' );
136 'Cannot add resource(stream) to ApiResult',
145 $this->fail(
'Expected exception not thrown' );
148 'Cannot add non-finite floats to ApiResult',
155 $this->fail(
'Expected exception not thrown' );
158 'Cannot add non-finite floats to ApiResult',
165 $this->fail(
'Expected exception not thrown' );
168 'Cannot add non-finite floats to ApiResult',
175 $this->fail(
'Expected exception not thrown' );
178 'Cannot add non-finite floats to ApiResult',
188 $this->fail(
'Expected exception not thrown' );
191 'Cannot add non-finite floats to ApiResult',
199 $result2->addValue( null,
'foo',
'bar' );
215 'foo' =>
"foo\xef\xbf\xbdbar",
218 0 =>
"foo\xef\xbf\xbdbar",
240 $result->addValue( null,
'setValue',
'1' );
242 $result->addValue( null, null,
'unnamed 1' );
243 $result->addValue( null, null,
'unnamed 2' );
245 $result->addValue( null,
'deleteValue',
'2' );
246 $result->removeValue( null,
'deleteValue' );
248 $result->addValue( [
'a',
'b' ],
'deleteValue',
'3' );
249 $result->removeValue( [
'a',
'b',
'deleteValue' ], null,
'3' );
251 $result->addContentValue( null,
'setContentValue',
'3' );
257 'a' => [
'b' => [] ],
258 'setContentValue' =>
'3',
262 $this->assertSame( 20,
$result->getSize() );
265 $result->addValue( null,
'setValue',
'99' );
266 $this->fail(
'Expected exception not thrown' );
269 'Attempting to add element setValue=99, existing value is 1',
276 $result->addContentValue( null,
'setContentValue2',
'99' );
277 $this->fail(
'Expected exception not thrown' );
280 'Attempting to set content element as setContentValue2 when setContentValue ' .
281 'is already set as the content element',
288 $this->assertSame(
'99',
$result->getResultData( [
'setValue' ] ) );
291 $this->assertSame(
'setContentValue2',
298 $this->assertSame( 0,
$result->getSize() );
300 $result->addValue( null,
'foo', 1 );
301 $result->addValue( null,
'bar', 1 );
304 $result->addValue( null,
'bottom',
'2' );
308 array_keys(
$result->getResultData() ) );
311 $result->addValue( null,
'foo', [
'bar' => 1 ] );
313 $result->addValue( [
'foo',
'bottom' ],
'x', 2 );
314 $this->assertSame( [
'top',
'bar',
'bottom' ],
315 array_keys(
$result->getResultData( [
'foo' ] ) ) );
318 $result->addValue( null,
'sub', [
'foo' => 1 ] );
319 $result->addValue( null,
'sub', [
'bar' => 1 ] );
321 'sub' => [
'foo' => 1,
'bar' => 1 ],
326 $result->addValue( null,
'sub', [
'foo' => 2,
'baz' => 2 ] );
327 $this->fail(
'Expected exception not thrown' );
330 'Conflicting keys (foo) when attempting to merge element sub',
342 $result->addValue( null,
'obj', $obj );
344 'title' => (
string)
$title,
351 $result->addValue( null,
'file', $fh );
352 $this->fail(
'Expected exception not thrown' );
355 'Cannot add resource(stream) to ApiResult',
361 $result->addValue( null, null, $fh );
362 $this->fail(
'Expected exception not thrown' );
365 'Cannot add resource(stream) to ApiResult',
372 $result->addValue( null,
'sub', $obj );
373 $this->fail(
'Expected exception not thrown' );
376 'Cannot add resource(stream) to ApiResult',
383 $result->addValue( null, null, $obj );
384 $this->fail(
'Expected exception not thrown' );
387 'Cannot add resource(stream) to ApiResult',
395 $result->addValue( null,
'inf', INF );
396 $this->fail(
'Expected exception not thrown' );
399 'Cannot add non-finite floats to ApiResult',
405 $result->addValue( null, null, INF );
406 $this->fail(
'Expected exception not thrown' );
409 'Cannot add non-finite floats to ApiResult',
415 $result->addValue( null,
'nan', NAN );
416 $this->fail(
'Expected exception not thrown' );
419 'Cannot add non-finite floats to ApiResult',
425 $result->addValue( null, null, NAN );
426 $this->fail(
'Expected exception not thrown' );
429 'Cannot add non-finite floats to ApiResult',
439 $this->fail(
'Expected exception not thrown' );
442 'Cannot add non-finite floats to ApiResult',
449 $result->addParsedLimit(
'foo', 12 );
451 'limits' => [
'foo' => 12 ],
454 $result->addParsedLimit(
'foo', 13 );
456 'limits' => [
'foo' => 13 ],
459 $this->assertSame( null,
$result->getResultData( [
'foo',
'bar',
'baz' ] ) );
460 $this->assertSame( 13,
$result->getResultData( [
'limits',
'foo' ] ) );
462 $result->getResultData( [
'limits',
'foo',
'bar' ] );
463 $this->fail(
'Expected exception not thrown' );
466 'Path limits.foo is not an array',
474 $obj = [
'attr' =>
'12345' ];
476 $this->assertTrue(
$result->addValue( null,
'foo', $obj ) );
477 $this->assertSame( 15,
$result->getSize() );
481 $result->setErrorFormatter( $formatter );
482 $this->assertFalse( $result->addValue( null,
'foo',
'12345678901' ) );
484 $this->assertSame( 0, $result->getSize() );
486 $this->assertTrue( $result->addValue( null,
'foo',
'1234567890' ) );
487 $this->assertFalse( $result->addValue( null,
'foo',
'1' ) );
488 $result->removeValue( null,
'foo' );
489 $this->assertTrue( $result->addValue( null,
'foo',
'1' ) );
493 $obj->foobar =
'foobaz';
494 $this->assertTrue( $result->addValue( null,
'foo', $obj ) );
495 $this->assertSame( 2, $result->getSize() );
499 $result2->addValue( null,
'foo',
'bar' );
500 $result->addValue( null,
'baz', $result2 );
507 ], $result->getResultData() );
510 $result->addValue( null,
'foo',
"foo\x80bar" );
511 $result->addValue( null,
'bar',
"a\xcc\x81" );
512 $result->addValue( null,
'baz', 74 );
513 $result->addValue( null, null,
"foo\x80bar" );
514 $result->addValue( null, null,
"a\xcc\x81" );
516 'foo' =>
"foo\xef\xbf\xbdbar",
519 0 =>
"foo\xef\xbf\xbdbar",
522 ], $result->getResultData() );
528 $result->addValue( $arr,
'foo', $obj );
542 $arr = [
'foo' => [
'bar' => [] ] ];
544 $result->addValue( null,
'foo', [
'bar' => [] ] );
571 $this->assertSame( $expect, $arr );
573 $result->addSubelementsList( null,
'foo' );
574 $result->addSubelementsList( null, [
'bar',
'baz' ] );
575 $result->removeSubelementsList( null,
'baz' );
576 $result->addIndexedTagNameRecursive( null,
'ritn' );
577 $result->addIndexedTagName( null,
'itn' );
578 $result->addPreserveKeysList( null,
'foo' );
579 $result->addPreserveKeysList( null, [
'bar',
'baz' ] );
580 $result->removePreserveKeysList( null,
'baz' );
581 $result->addArrayTypeRecursive( null,
'default' );
582 $result->addArrayType( null,
'array' );
583 $this->assertEquals( $expect,
$result->getResultData() );
585 $arr = [
'foo' => [
'bar' => [] ] ];
600 $this->assertSame( $expect, $arr );
609 'bar' => [
'_dummy' =>
'foobaz' ],
610 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
612 '_dummy' =>
'foobaz',
615 'bar' => [
'_dummy' =>
'foobaz' ],
616 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
618 '_dummy' =>
'foobaz',
624 '_dummy' =>
'foobaz',
625 '_dummy2' =>
'foobaz!',
627 $this->assertEquals( [
630 'bar2' => (
object)[],
635 'bar2' => (
object)[],
638 '_dummy2' =>
'foobaz!',
643 $this->assertEquals( [
645 'bar' => [
'_dummy' =>
'foobaz' ],
646 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
648 '_dummy' =>
'foobaz',
651 'bar' => [
'_dummy' =>
'foobaz' ],
652 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
654 '_dummy' =>
'foobaz',
656 '_dummy2' =>
'foobaz!',
657 ], $data,
'ApiResult::stripMetadataNonRecursive ($data)' );
658 $this->assertEquals( [
663 '_dummy' =>
'foobaz',
664 ], $metadata,
'ApiResult::stripMetadataNonRecursive ($metadata)' );
668 $this->assertEquals( (
object)[
670 'bar' => [
'_dummy' =>
'foobaz' ],
671 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
673 '_dummy' =>
'foobaz',
676 'bar' => [
'_dummy' =>
'foobaz' ],
677 'bar2' => (
object)[
'_dummy' =>
'foobaz' ],
679 '_dummy' =>
'foobaz',
681 '_dummy2' =>
'foobaz!',
682 ], $data,
'ApiResult::stripMetadataNonRecursive on object ($data)' );
683 $this->assertEquals( [
688 '_dummy' =>
'foobaz',
689 ], $metadata,
'ApiResult::stripMetadataNonRecursive on object ($metadata)' );
702 $result->addValue( null,
'test', $input );
707 $this->fail(
'Expected exception not thrown', $label );
708 }
catch ( Exception $ex ) {
709 $this->assertEquals( $ex, $expect, $label );
713 $this->assertEquals( $expect,
$output, $label );
718 $kvp =
function ( $keyKey, $key, $valKey,
$value ) {
728 'defaultArray' => [ 2 =>
'a', 0 =>
'b', 1 =>
'c' ],
729 'defaultAssoc' => [
'x' =>
'a', 1 =>
'b', 0 =>
'c' ],
730 'defaultAssoc2' => [ 2 =>
'a', 3 =>
'b', 0 =>
'c' ],
736 'BCkvp' => [
'x' =>
'a',
'y' =>
'b',
740 'kvpmerge' => [
'x' =>
'a',
'y' => [
'b' ],
'z' => [
'c' =>
'd' ],
744 'emptyDefault' => [
'_dummy' => 1 ],
751 'bar' => [
'_dummy' =>
'foobaz' ],
759 '_dummy' =>
'foobaz',
765 '_dummy' =>
'foobaz',
766 '_dummy2' =>
'foobaz!',
788 'BC: META_BC_SUBELEMENTS',
820 'foo' =>
'foo value',
821 'bar' =>
'bar value',
822 '_baz' =>
'baz value',
829 $kvp(
'key',
'foo',
'*',
'foo value' ),
830 $kvp(
'key',
'bar',
'*',
'bar value' ),
831 $kvp(
'key',
'_baz',
'*',
'baz value' ),
858 'BC: BCkvp exception',
864 'Type "BCkvp" used without setting ApiResult::META_KVP_KEY_NAME metadata item'
868 'BC: nobool, no*, nosub',
872 'content' =>
'content',
879 'foo' =>
'foo value',
880 'bar' =>
'bar value',
881 '_baz' =>
'baz value',
887 [
'BC' => [
'nobool',
'no*',
'nosub' ] ],
891 'content' =>
'content',
896 $kvp(
'key',
'foo',
'*',
'foo value' ),
897 $kvp(
'key',
'bar',
'*',
'bar value' ),
898 $kvp(
'key',
'_baz',
'*',
'baz value' ),
909 'Types: Normal transform',
920 'kvp' => [
'x' =>
'a',
'y' =>
'b',
924 'BCkvp' => [
'x' =>
'a',
'y' =>
'b',
925 ApiResult::META_TYPE =>
'assoc',
930 'y' => [
'b', ApiResult::META_TYPE =>
'array' ],
931 'z' => [
'c' =>
'd', ApiResult::META_TYPE =>
'assoc' ],
932 ApiResult::META_TYPE =>
'assoc',
935 'emptyDefault' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'array' ],
936 'emptyAssoc' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'assoc' ],
939 ApiResult::META_TYPE =>
'assoc',
943 'Types: AssocAsObject',
945 [
'Types' => [
'AssocAsObject' =>
true ] ],
947 'defaultArray' => [
'b',
'c',
'a', ApiResult::META_TYPE =>
'array' ],
948 'defaultAssoc' => (
object)[
'x' =>
'a',
949 1 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc'
951 'defaultAssoc2' => (
object)[ 2 =>
'a', 3 =>
'b',
952 0 =>
'c', ApiResult::META_TYPE =>
'assoc'
954 'array' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
955 'BCarray' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
956 'BCassoc' => (
object)[
'a',
'b',
'c', ApiResult::META_TYPE =>
'assoc' ],
957 'assoc' => (
object)[ 2 =>
'a', 0 =>
'b', 1 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
958 'kvp' => (
object)[
'x' =>
'a',
'y' =>
'b',
959 'z' => [
'c', ApiResult::META_TYPE =>
'array' ],
960 ApiResult::META_TYPE =>
'assoc'
962 'BCkvp' => (
object)[
'x' =>
'a',
'y' =>
'b',
963 ApiResult::META_TYPE =>
'assoc',
966 'kvpmerge' => (
object)[
968 'y' => [
'b', ApiResult::META_TYPE =>
'array' ],
969 'z' => (
object)[
'c' =>
'd', ApiResult::META_TYPE =>
'assoc' ],
970 ApiResult::META_TYPE =>
'assoc',
973 'emptyDefault' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'array' ],
974 'emptyAssoc' => (
object)[
'_dummy' => 1, ApiResult::META_TYPE =>
'assoc' ],
977 ApiResult::META_TYPE =>
'assoc',
983 [
'Types' => [
'ArmorKVP' =>
'name' ] ],
985 'defaultArray' => [
'b',
'c',
'a', ApiResult::META_TYPE =>
'array' ],
986 'defaultAssoc' => [
'x' =>
'a', 1 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
987 'defaultAssoc2' => [ 2 =>
'a', 3 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
988 'array' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
989 'BCarray' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
990 'BCassoc' => [
'a',
'b',
'c', ApiResult::META_TYPE =>
'assoc' ],
991 'assoc' => [ 2 =>
'a', 0 =>
'b', 1 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
993 $kvp(
'name',
'x',
'value',
'a' ),
994 $kvp(
'name',
'y',
'value',
'b' ),
995 $kvp(
'name',
'z',
'value', [
'c', ApiResult::META_TYPE =>
'array' ] ),
996 ApiResult::META_TYPE =>
'array'
999 $kvp(
'key',
'x',
'value',
'a' ),
1000 $kvp(
'key',
'y',
'value',
'b' ),
1001 ApiResult::META_TYPE =>
'array',
1005 $kvp(
'name',
'x',
'value',
'a' ),
1006 $kvp(
'name',
'y',
'value', [
'b', ApiResult::META_TYPE =>
'array' ] ),
1010 ApiResult::META_TYPE =>
'assoc',
1013 ApiResult::META_TYPE =>
'array',
1016 'emptyDefault' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'array' ],
1017 'emptyAssoc' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'assoc' ],
1020 ApiResult::META_TYPE =>
'assoc',
1024 'Types: ArmorKVP + BC',
1026 [
'BC' => [],
'Types' => [
'ArmorKVP' =>
'name' ] ],
1028 'defaultArray' => [
'b',
'c',
'a', ApiResult::META_TYPE =>
'array' ],
1029 'defaultAssoc' => [
'x' =>
'a', 1 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
1030 'defaultAssoc2' => [ 2 =>
'a', 3 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
1031 'array' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
1032 'BCarray' => [
'x' =>
'a', 1 =>
'b', 0 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
1033 'BCassoc' => [
'a',
'b',
'c', ApiResult::META_TYPE =>
'array' ],
1034 'assoc' => [ 2 =>
'a', 0 =>
'b', 1 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
1036 $kvp(
'name',
'x',
'*',
'a' ),
1037 $kvp(
'name',
'y',
'*',
'b' ),
1038 $kvp(
'name',
'z',
'*', [
'c', ApiResult::META_TYPE =>
'array' ] ),
1039 ApiResult::META_TYPE =>
'array'
1042 $kvp(
'key',
'x',
'*',
'a' ),
1043 $kvp(
'key',
'y',
'*',
'b' ),
1044 ApiResult::META_TYPE =>
'array',
1048 $kvp(
'name',
'x',
'*',
'a' ),
1049 $kvp(
'name',
'y',
'*', [
'b', ApiResult::META_TYPE =>
'array' ] ),
1053 ApiResult::META_TYPE =>
'assoc',
1055 ApiResult::META_TYPE =>
'array',
1058 'emptyDefault' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'array' ],
1059 'emptyAssoc' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'assoc' ],
1062 ApiResult::META_TYPE =>
'assoc',
1066 'Types: ArmorKVP + AssocAsObject',
1068 [
'Types' => [
'ArmorKVP' =>
'name',
'AssocAsObject' =>
true ] ],
1070 'defaultArray' => [
'b',
'c',
'a', ApiResult::META_TYPE =>
'array' ],
1071 'defaultAssoc' => (
object)[
'x' =>
'a', 1 =>
'b',
1072 0 =>
'c', ApiResult::META_TYPE =>
'assoc'
1074 'defaultAssoc2' => (
object)[ 2 =>
'a', 3 =>
'b',
1075 0 =>
'c', ApiResult::META_TYPE =>
'assoc'
1077 'array' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
1078 'BCarray' => [
'a',
'c',
'b', ApiResult::META_TYPE =>
'array' ],
1079 'BCassoc' => (
object)[
'a',
'b',
'c', ApiResult::META_TYPE =>
'assoc' ],
1080 'assoc' => (
object)[ 2 =>
'a', 0 =>
'b', 1 =>
'c', ApiResult::META_TYPE =>
'assoc' ],
1082 (
object)$kvp(
'name',
'x',
'value',
'a' ),
1083 (
object)$kvp(
'name',
'y',
'value',
'b' ),
1084 (
object)$kvp(
'name',
'z',
'value', [
'c', ApiResult::META_TYPE =>
'array' ] ),
1085 ApiResult::META_TYPE =>
'array'
1088 (
object)$kvp(
'key',
'x',
'value',
'a' ),
1089 (
object)$kvp(
'key',
'y',
'value',
'b' ),
1090 ApiResult::META_TYPE =>
'array',
1094 (
object)$kvp(
'name',
'x',
'value',
'a' ),
1095 (
object)$kvp(
'name',
'y',
'value', [
'b', ApiResult::META_TYPE =>
'array' ] ),
1099 ApiResult::META_TYPE =>
'assoc',
1102 ApiResult::META_TYPE =>
'array',
1105 'emptyDefault' => [
'_dummy' => 1, ApiResult::META_TYPE =>
'array' ],
1106 'emptyAssoc' => (
object)[
'_dummy' => 1, ApiResult::META_TYPE =>
'assoc' ],
1109 ApiResult::META_TYPE =>
'assoc',
1113 'Types: BCkvp exception',
1115 ApiResult::META_TYPE =>
'BCkvp',
1119 'Type "BCkvp" used without setting ApiResult::META_KVP_KEY_NAME metadata item'
1124 'Strip: With ArmorKVP + AssocAsObject transforms',
1126 [
'Types' => [
'ArmorKVP' =>
'name',
'AssocAsObject' =>
true ],
'Strip' =>
'all' ],
1128 'defaultArray' => [
'b',
'c',
'a' ],
1129 'defaultAssoc' => (
object)[
'x' =>
'a', 1 =>
'b', 0 =>
'c' ],
1130 'defaultAssoc2' => (
object)[ 2 =>
'a', 3 =>
'b', 0 =>
'c' ],
1131 'array' => [
'a',
'c',
'b' ],
1132 'BCarray' => [
'a',
'c',
'b' ],
1133 'BCassoc' => (
object)[
'a',
'b',
'c' ],
1134 'assoc' => (
object)[ 2 =>
'a', 0 =>
'b', 1 =>
'c' ],
1136 (
object)[
'name' =>
'x',
'value' =>
'a' ],
1137 (
object)[
'name' =>
'y',
'value' =>
'b' ],
1138 (
object)[
'name' =>
'z',
'value' => [
'c' ] ],
1141 (
object)[
'key' =>
'x',
'value' =>
'a' ],
1142 (
object)[
'key' =>
'y',
'value' =>
'b' ],
1145 (
object)[
'name' =>
'x',
'value' =>
'a' ],
1146 (
object)[
'name' =>
'y',
'value' => [
'b' ] ],
1147 (
object)[
'name' =>
'z',
'c' =>
'd' ],
1149 'emptyDefault' => [],
1150 'emptyAssoc' => (
object)[],
1158 [
'Strip' =>
'all' ],
1165 '_dummy2' =>
'foobaz!',
1171 [
'Strip' =>
'base' ],
1174 'bar' => [
'_dummy' =>
'foobaz' ],
1179 ApiResult::META_TYPE =>
'array',
1182 '_dummy' =>
'foobaz',
1184 '_dummy2' =>
'foobaz!',
1190 [
'Strip' =>
'bc' ],
1200 '_dummy2' =>
'foobaz!',
1218 'Custom' => [ $this,
'customTransform' ],
1226 'baz' => [
'a',
'b' ],
1227 '_dummy2' =>
'_DUMMY2',
1228 '_dummy3' =>
'_DUMMY3',
1243 if ( isset( $metadata[
'_added'] ) ) {
1248 foreach ( $data
as $k => $v ) {
1249 $data[$k] = strtoupper( $k );
1251 $data[
'baz'] = [
'_added' => 1,
'z' =>
'b',
'y' =>
'a' ];
1264 'sequential_numeric_keys' => [
'a',
'b',
'c' ],
1265 'non_sequential_numeric_keys' => [
'a',
'b', 4 =>
'c' ],
1270 'object_sequential_keys' => (
object)[
'a',
'b',
'c' ],
1271 '_type' =>
"should be overwritten in result",
1273 $this->assertSame( [
1278 'sequential_numeric_keys',
'non_sequential_numeric_keys',
1279 'string_keys',
'object_sequential_keys'
1286 'sequential_numeric_keys' => [
1294 'non_sequential_numeric_keys' => [
1313 'object_sequential_keys' => [
1329 $this->assertSame( [
1337 $this->assertSame(
'Ok', $arr[
'foo'] );
1341 $this->assertSame(
'Ok', $arr[
'foo'] );
1348 $this->fail(
'Expected exception not thrown' );
1351 'ApiResultTestSerializableObject::serializeForApiResult() ' .
1352 'returned an object of class ApiResultTestStringifiableObject',
1354 'Expected exception'
1361 $this->fail(
'Expected exception not thrown' );
1364 'ApiResultTestSerializableObject::serializeForApiResult() ' .
1365 'returned an invalid value: Cannot add non-finite floats to ApiResult',
1367 'Expected exception'
1378 $this->assertSame( [
testInstanceDataMethods()
ApiResult.
testUtilityFunctions()
ApiResult.
testStaticDataMethods()
ApiResult.
static unsetSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as attributes (when possible) rather than a...
testAddMetadataToResultVars()
ApiResult.
const META_TYPE
Key for the 'type' metadata item.
testTransformations($label, $input, $transforms, $expect)
ApiResult provideTransformations.
const META_PRESERVE_KEYS
Key for the 'preserve keys' metadata item.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
const ADD_ON_TOP
For addValue(), setValue() and similar functions, if the value does not exist, add it as the first el...
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
static unsetValue(array &$arr, $name)
Remove an output value to the array by name.
static stripMetadata($data)
Recursively remove metadata keys from a data array or object.
static setArrayTypeRecursive(array &$arr, $type, $kvpKeyName=null)
Set the array data type recursively.
static stripMetadataNonRecursive($data, &$metadata=null)
Remove metadata keys from a data array or object, non-recursive.
const META_KVP_MERGE
Key for the metadata item that indicates that the KVP key should be added into an assoc value...
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
namespace and then decline to actually register it file or subcat img or subcat $title
This class represents the result of the API operations.
customTransform(&$data, &$metadata)
Custom transformer for testTransformations.
const NO_VALIDATE
For addValue(), setValue() and similar functions, do not validate data.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes...
static setIndexedTagNameRecursive(array &$arr, $tag)
Set indexed tag name on $arr and all subarrays.
static unsetPreserveKeysList(array &$arr, $names)
Don't preserve specified keys.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
const META_INDEXED_TAG_NAME
Key for the 'indexed tag name' metadata item.
static addMetadataToResultVars($vars, $forceHash=true)
Add the correct metadata to an array of vars we want to export through the API.
static setValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name.
const META_SUBELEMENTS
Key for the 'subelements' metadata item.
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
static setPreserveKeysList(array &$arr, $names)
Preserve specified keys.
const META_CONTENT
Key for the 'content' metadata item.
testObjectSerialization()
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static factory($code)
Get a cached or new language object for a given language code.
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
const OVERRIDE
Override existing value in addValue(), setValue(), and similar functions.
const META_KVP_KEY_NAME
Key for the metadata item whose value specifies the name used for the kvp key in the alternative outp...