25 $config = new \HashConfig( [
26 'PageImagesAPIDefaultLicense' =>
'free'
29 $context = $this->getMockBuilder(
'IContextSource' )
30 ->disableOriginalConstructor()
34 ->method(
'getConfig' )
35 ->willReturn( $config );
37 $main = $this->getMockBuilder(
'ApiMain' )
38 ->disableOriginalConstructor()
40 $main->expects( $this->once() )
41 ->method(
'getContext' )
42 ->will( $this->returnValue(
$context ) );
44 $query = $this->getMockBuilder(
'ApiQuery' )
45 ->disableOriginalConstructor()
47 $query->expects( $this->once() )
49 ->will( $this->returnValue( $main ) );
66 $params = $instance->getAllowedParams();
67 $this->assertInternalType(
'array', $params );
68 $this->assertNotEmpty( $params );
69 $this->assertContainsOnly(
'array', $params );
70 $this->assertArrayHasKey(
'limit', $params );
71 $this->assertEquals( $params[
'limit'][\ApiBase::PARAM_DFLT], 50 );
72 $this->assertEquals( $params[
'limit'][\ApiBase::PARAM_TYPE],
'limit' );
73 $this->assertEquals( $params[
'limit'][\ApiBase::PARAM_MIN], 1 );
74 $this->assertEquals( $params[
'limit'][\ApiBase::PARAM_MAX], 50 );
75 $this->assertEquals( $params[
'limit'][\ApiBase::PARAM_MAX2], 100 );
76 $this->assertArrayHasKey(
'license', $params );
77 $this->assertEquals( $params[
'license'][\ApiBase::PARAM_TYPE], [
'free',
'any' ] );
78 $this->assertEquals( $params[
'license'][\ApiBase::PARAM_DFLT],
'free' );
79 $this->assertEquals( $params[
'license'][\ApiBase::PARAM_ISMULTI],
false );
85 public function testGetTitles( $titles, $missingTitlesByNamespace, $expected ) {
86 $pageSet = $this->getMockBuilder(
'ApiPageSet' )
87 ->disableOriginalConstructor()
89 $pageSet->expects( $this->any() )
90 ->method(
'getGoodTitles' )
91 ->will( $this->returnValue( $titles ) );
92 $pageSet->expects( $this->any() )
93 ->method(
'getMissingTitlesByNamespace' )
94 ->will( $this->returnValue( $missingTitlesByNamespace ) );
97 $this->assertEquals( $expected, $queryPageImages->getTitles() );
139 public function testExecute( $requestParams, $titles, $queryPageIds,
140 $queryResults, $setResultValueCount
142 $mock = TestingAccessWrapper::newFromObject(
143 $this->getMockBuilder( ApiQueryPageImages::class )
144 ->disableOriginalConstructor()
145 ->setMethods( [
'extractRequestParams',
'getTitles',
'setContinueParameter',
'dieUsage',
146 'addTables',
'addFields',
'addWhere',
'select',
'setResultValues' ] )
149 $mock->expects( $this->any() )
150 ->method(
'extractRequestParams' )
151 ->willReturn( $requestParams );
152 $mock->expects( $this->any() )
153 ->method(
'getTitles' )
154 ->willReturn( $titles );
155 $mock->expects( $this->any() )
160 if ( isset( $requestParams[
'continue'] )
161 && $requestParams[
'continue'] > count( $titles )
163 $mock->expects( $this->exactly( 1 ) )
164 ->method(
'dieUsage' );
167 $originalRequested = in_array(
'original', $requestParams[
'prop'] );
170 $license = isset( $requestParams[
'license'] ) ? $requestParams[
'license'] :
'free';
171 if ( $license == ApiQueryPageImages::PARAM_LICENSE_ANY ) {
172 $propName = [ PageImages::getPropName(
true ), PageImages::getPropName(
false ) ];
174 $propName = PageImages::getPropName(
true );
176 $mock->expects( $this->exactly( count( $queryPageIds ) > 0 ? 1 : 0 ) )
177 ->method(
'addWhere' )
178 ->with( [
'pp_page' => $queryPageIds,
'pp_propname' => $propName ] );
180 $mock->expects( $this->exactly( $setResultValueCount ) )
181 ->method(
'setResultValues' );
189 [
'prop' => [
'thumbnail' ],
'thumbsize' => 100,
'limit' => 10,
'license' =>
'any' ],
190 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
193 (object)[
'pp_page' => 0,
'pp_value' =>
'A_Free.jpg',
194 'pp_propname' => PageImages::PROP_NAME_FREE ],
195 (
object)[
'pp_page' => 0,
'pp_value' =>
'A.jpg',
196 'pp_propname' => PageImages::PROP_NAME ],
197 (object)[
'pp_page' => 1,
'pp_value' =>
'B.jpg',
198 'pp_propname' => PageImages::PROP_NAME ],
203 [
'prop' => [
'thumbnail' ],
'thumbsize' => 200,
'limit' => 10 ],
210 [
'prop' => [
'thumbnail' ],
'continue' => 1,
'thumbsize' => 400,
211 'limit' => 10,
'license' =>
'any' ],
212 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
215 (object)[
'pp_page' => 1,
'pp_value' =>
'B_Free.jpg',
216 'pp_propname' => PageImages::PROP_NAME_FREE ],
217 (
object)[
'pp_page' => 1,
'pp_value' =>
'B.jpg',
218 'pp_propname' => PageImages::PROP_NAME ],
223 [
'prop' => [
'thumbnail' ],
'thumbsize' => 500,
'limit' => 10,
'license' =>
'any' ],
224 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
227 (object)[
'pp_page' => 1,
'pp_value' =>
'B_Free.jpg',
228 'pp_propname' => PageImages::PROP_NAME ],
233 [
'prop' => [
'thumbnail' ],
'continue' => 1,
'thumbsize' => 500,
234 'limit' => 10,
'license' =>
'any' ],
235 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
238 (object)[
'pp_page' => 1,
'pp_value' =>
'B_Free.jpg',
239 'pp_propname' => PageImages::PROP_NAME_FREE ],
244 [
'prop' => [
'thumbnail' ],
'thumbsize' => 510,
'limit' => 10,
'license' =>
'free' ],
245 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
251 [
'prop' => [
'thumbnail' ],
'thumbsize' => 510,
'limit' => 10,
'license' =>
'free' ],
252 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
255 (object)[
'pp_page' => 0,
'pp_value' =>
'A_Free.jpg',
256 'pp_propname' => PageImages::PROP_NAME_FREE ],
257 (
object)[
'pp_page' => 1,
'pp_value' =>
'B_Free.jpg',
258 'pp_propname' => PageImages::PROP_NAME_FREE ],
263 [
'prop' => [
'thumbnail',
'original' ],
'thumbsize' => 510,
264 'limit' => 10,
'license' =>
'free' ],
265 [ Title::newFromText(
'Page 1' ), Title::newFromText(
'Page 2' ) ],
269 'pp_page' => 0,
'pp_value' =>
'A_Free.jpg',
270 'pp_value_original' =>
'A_Free_original.jpg',
'pp_original_width' => 80,
271 'pp_original_height' => 80,
'pp_propname' => PageImages::PROP_NAME_FREE
274 'pp_page' => 1,
'pp_value' =>
'B_Free.jpg',
275 'pp_value_original' =>
'B_Free_original.jpg',
'pp_original_width' => 80,
276 'pp_original_height' => 80,
'pp_propname' => PageImages::PROP_NAME_FREE