Completed
Pull Request — master (#554)
by Jeroen De
03:35
created

ApiGeocodeTest::testResponseHasResultsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Tests\System\MediaWiki\Api;
6
7
use MediaWiki\MediaWikiServices;
8
use MediaWiki\Permissions\PermissionManager;
9
10
/**
11
 * @covers \Maps\MediaWiki\Api\ApiGeocode
12
 * @group medium
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class ApiGeocodeTest extends \ApiTestCase {
18
19
	public function testResponseHasResultsArray() {
20
		$result = $this->doApiRequest( [
21
			'action' => 'geocode',
22
			'locations' => ''
23
		 ] );
24
25
		$this->assertArrayHasKey( 'results', $result[0] );
26
		$this->assertTrue( is_array( $result[0]['results'] ) );
27
	}
28
29
	public function testUseCannotGeocodeWithoutGeocodePermission() {
30
		$this->revokeGeocodePermission();
31
32
		$this->expectException( \ApiUsageException::class );
33
		$this->expectExceptionMessage( 'is limited to users' );
34
35
		$this->doApiRequest( [
36
			'action' => 'geocode',
37
			'locations' => ''
38
		] );
39
	}
40
41
	private function revokeGeocodePermission() {
42
		$this->setMwGlobals( 'wgGroupPermissions', [
43
			'*' => [ 'read' => true, 'geocode' => false ],
44
		] );
45
46
		if ( class_exists( PermissionManager::class ) ) {
47
			MediaWikiServices::getInstance()->resetServiceForTesting( 'PermissionManager' );
48
		}
49
	}
50
51
}
52