1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2015 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CoreBundle\Tests\Unit\IpLookup; |
||
13 | |||
14 | use Mautic\CoreBundle\IpLookup\ExtremeIpLookup; |
||
15 | |||
16 | /** |
||
17 | * Class ExtremeIpLookupTest. |
||
18 | */ |
||
19 | class ExtemeIpLookupTest extends \PHPUnit\Framework\TestCase |
||
20 | { |
||
21 | private $cacheDir = __DIR__.'/../../../../../../var/cache/test'; |
||
22 | |||
23 | public function testIpLookupSuccessful() |
||
24 | { |
||
25 | // Mock http connector |
||
26 | $mockHttp = $this->getMockBuilder('Joomla\Http\Http') |
||
27 | ->disableOriginalConstructor() |
||
28 | ->getMock(); |
||
29 | |||
30 | // Mock a successful response |
||
31 | $mockResponse = $this->getMockBuilder('Joomla\Http\Response') |
||
32 | ->getMock(); |
||
33 | $mockResponse->code = 200; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
34 | $mockResponse->body = '{"businessName" : "Sandhills Publishing Company","businessWebsite" : "www.sandhills.com","city" : "Lincoln","continent" : "North America","country" : "United States","countryCode" : "US","ipName" : "proxy.sandhills.com","ipType" : "Business","isp" : "Sandhills Publishing Company","lat" : "40.8615","lon" : "-96.7119","org" : "Sandhills Publishing Company","query" : "63.70.164.200","region" : "Nebraska","status" : "success"}'; |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | $mockHttp->expects($this->once()) |
||
37 | ->method('get') |
||
38 | ->willReturn($mockResponse); |
||
39 | |||
40 | $ipService = new ExtremeIpLookup(null, null, $this->cacheDir, null, $mockHttp); |
||
41 | |||
42 | $details = $ipService->setIpAddress('63.70.164.200')->getDetails(); |
||
43 | |||
44 | $this->assertEquals('Lincoln', $details['city']); |
||
45 | $this->assertEquals('Nebraska', $details['region']); |
||
46 | $this->assertEquals('United States', $details['country']); |
||
47 | } |
||
48 | } |
||
49 |