|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests\UnitTests; |
|
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\UnitTests |
|
11
|
|
|
* @coversDefaultClass Clubdeuce\WPLib\Components\GoogleMaps\Geocoder |
|
12
|
|
|
*/ |
|
13
|
|
|
class TestGeocoder extends TestCase { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var Geocoder |
|
17
|
|
|
*/ |
|
18
|
|
|
private $_geocoder; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_api_key = '12345'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
public function setUp() { |
|
29
|
|
|
$this->_geocoder = new Geocoder(['api_key' => $this->_api_key]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @covers ::__construct |
|
34
|
|
|
* @covers ::api_key |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testConstructorWithAPIKey() { |
|
37
|
|
|
$this->assertEquals($this->_api_key, $this->_geocoder->api_key()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @covers ::_make_url |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testMakeUrl() { |
|
44
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_url', '123 Anywhere Street New York 10001'); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertInternalType('string', $response); |
|
47
|
|
|
$this->assertRegExp('/address\=123\+Anywhere\+Street\+New\+York\+10001/', $response); |
|
48
|
|
|
$this->assertRegExp("/key={$this->_api_key}/", $response); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @covers ::_get_data |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testGetDataCache() { |
|
55
|
|
|
wp_cache_add( md5(serialize('foo.bar')), 'foobar'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals('foobar', $this->reflectionMethodInvokeArgs($this->_geocoder, '_get_data', 'foo.bar')); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers ::_parse_response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testParseResponse() { |
|
64
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_parse_response', json_decode(file_get_contents(INCLUDES_DIR . '/geocoder-response.json'), true)); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertInternalType('array', $response); |
|
67
|
|
|
$this->assertArrayHasKey('lat', $response); |
|
68
|
|
|
$this->assertArrayHasKey('lng', $response); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @covers ::_make_request |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testMakeRequestInvalidURL() { |
|
75
|
|
|
$response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_request', 'foo.bar'); |
|
76
|
|
|
$this->assertInstanceOf('WP_Error', $response); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |