38 protected function checkC( $expected,
$params, $expectedCount, $id, $continue =
true ) {
39 $result = $this->
query(
$params, $expectedCount, $id, $continue );
52 protected function query(
$params, $expectedCount, $id, $useContinue =
true ) {
53 if ( isset(
$params[
'action'] ) ) {
54 $this->assertEquals(
'query',
$params[
'action'],
'Invalid query action' );
63 uksort(
$request,
function ( $a, $b ) {
65 $a = strpos( $a,
'continue' ) !==
false ?
'zzz ' . $a : $a;
66 $b = strpos( $b,
'continue' ) !==
false ?
'zzz ' . $b : $b;
68 return strcmp( $a, $b );
70 $reqStr = http_build_query(
$request );
72 $this->assertLessThan( $expectedCount, $count,
"$id more data: $reqStr" );
73 if ( $this->mVerbose ) {
74 print "$id (#$count): $reqStr\n";
78 }
catch ( Exception
$e ) {
79 throw new Exception(
"$id on $count", 0,
$e );
82 if ( isset( $data[
'warnings'] ) ) {
83 $warnings = json_encode( $data[
'warnings'] );
84 $this->fail(
"$id Warnings on #$count in $reqStr\n$warnings" );
86 $this->assertArrayHasKey(
'query', $data,
"$id no 'query' on #$count in $reqStr" );
87 if ( isset( $data[
'continue'] ) ) {
88 $continue = $data[
'continue'];
89 unset( $data[
'continue'] );
93 if ( $this->mVerbose ) {
98 if ( empty( $continue ) ) {
99 $this->assertEquals( $expectedCount, $count,
"$id finished early" );
102 } elseif ( !$useContinue ) {
103 $this->assertFalse(
'Non-smart query must be requested all at once' );
114 if ( isset( $q[
'pages'] ) ) {
115 foreach ( $q[
'pages'] as $p ) {
117 if ( isset( $p[
'links'] ) ) {
118 $m .=
'/[' . implode(
',', array_map(
122 $p[
'links'] ) ) .
']';
124 if ( isset( $p[
'categories'] ) ) {
125 $m .=
'/(' . implode(
',', array_map(
127 return str_replace(
'Category:',
'', $v[
'title'] );
129 $p[
'categories'] ) ) .
')';
134 if ( isset( $q[
'allcategories'] ) ) {
135 $print[] =
'*Cats/(' . implode(
',', array_map(
139 $q[
'allcategories'] ) ) .
')';
144 print ' ' . implode(
' ', $print ) .
"\n";
147 private static function GetItems( $q, $moduleName, $name, &$print ) {
148 if ( isset( $q[$moduleName] ) ) {
149 $print[] =
"*$name/[" . implode(
',',
154 $q[$moduleName] ) ) .
']';
164 protected function mergeResult( &$results, $newResult, $numericIds =
false ) {
166 is_array( $results ),
167 is_array( $newResult ),
168 'Type of result and data do not match'
170 if ( !is_array( $results ) ) {
171 $this->assertEquals( $results, $newResult,
'Repeated result must be the same as before' );
174 foreach ( $newResult as $key =>
$value ) {
175 if ( !$numericIds &&
$sort ===
null ) {
176 if ( !is_array(
$value ) ) {
178 } elseif ( array_key_exists(
'title',
$value ) ) {
179 $sort =
function ( $a, $b ) {
180 return strcmp( $a[
'title'], $b[
'title'] );
186 $keyExists = array_key_exists( $key, $results );
187 if ( is_numeric( $key ) ) {
197 } elseif ( !$keyExists ) {
204 ksort( $results, SORT_NUMERIC );
205 } elseif (
$sort !==
null &&
$sort !==
false ) {
206 usort( $results,
$sort );
query( $params, $expectedCount, $id, $useContinue=true)
Run query in a loop until no more values are available.
static GetItems( $q, $moduleName, $name, &$print)
mergeResult(&$results, $newResult, $numericIds=false)
Recursively merge the new result returned from the query to the previous results.
$mVerbose
Enable to print in-depth debugging info during the test run.
checkC( $expected, $params, $expectedCount, $id, $continue=true)
Run query() and compare against expected values.
This class has some common functionality for testing query module.
assertResult( $exp, $result, $message='')
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
namespace being checked & $result
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
returning false will NOT prevent logging $e
while(( $__line=Maintenance::readconsole()) !==false) print