|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests\Integration; |
|
4
|
|
|
|
|
5
|
|
|
use Clubdeuce\WPLib\Components\GoogleMaps\Geocoder; |
|
6
|
|
|
use Clubdeuce\WPLib\Components\GoogleMaps\Tests\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class TestGeocoder |
|
10
|
|
|
* @package Clubdeuce\WPLib\Components\GoogleMaps\Tests\Integration |
|
11
|
|
|
* @coversDefaultClass Clubdeuce\WPLib\Components\GoogleMaps\Geocoder |
|
12
|
|
|
*/ |
|
13
|
|
|
class TestGeocoder extends TestCase { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var Geocoder; |
|
17
|
|
|
*/ |
|
18
|
|
|
private $_geocoder; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() { |
|
21
|
|
|
$this->_geocoder = new Geocoder(['api_key' => '']); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @covers ::_make_request |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testMakeRequest() { |
|
28
|
|
|
$url = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_url', '1600 Amphitheatre Parkway, Mountain View, CA'); |
|
29
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_request', $url); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertInternalType('array', $response); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @covers ::_make_request |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testMakeRequestError404() { |
|
38
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_request', 'https://maps.googleapis.com/maps/api/geo'); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertInstanceOf('WP_Error', $response); |
|
41
|
|
|
$this->assertObjectHasAttribute('errors', $response); |
|
42
|
|
|
$this->assertArrayHasKey('404', $response->errors); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers ::_get_data |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testGetData() { |
|
49
|
|
|
$url = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_url', '1600 Amphitheatre Parkway, Mountain View, CA'); |
|
50
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_get_data', $url); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertInternalType('array', $response); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @covers ::geocode |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testGeocode() { |
|
59
|
|
|
$result = $this->_geocoder->geocode('1600 Amphitheatre Parkway, Mountain View, CA'); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertInternalType('array', $result); |
|
62
|
|
|
$this->assertArrayHasKey('lat', $result); |
|
63
|
|
|
$this->assertArrayHasKey('lng', $result); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|