2013-05-09 14:28:01 +00:00
|
|
|
<?php
|
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
namespace GeoIp2\Test\Model;
|
2013-05-09 14:28:01 +00:00
|
|
|
|
2014-07-15 21:19:30 +00:00
|
|
|
use GeoIp2\Model\Insights;
|
2013-05-09 14:28:01 +00:00
|
|
|
|
2014-07-15 21:19:30 +00:00
|
|
|
class InsightsTest extends \PHPUnit_Framework_TestCase
|
2013-05-09 14:28:01 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public function testFull()
|
|
|
|
{
|
|
|
|
|
|
|
|
$raw = array(
|
|
|
|
'city' => array(
|
|
|
|
'confidence' => 76,
|
|
|
|
'geoname_id' => 9876,
|
2013-10-21 13:18:12 +00:00
|
|
|
'names' => array('en' => 'Minneapolis'),
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
'continent' => array(
|
2013-10-21 13:18:12 +00:00
|
|
|
'code' => 'NA',
|
2013-05-21 20:28:37 +00:00
|
|
|
'geoname_id' => 42,
|
2013-10-21 13:18:12 +00:00
|
|
|
'names' => array('en' => 'North America'),
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
'country' => array(
|
|
|
|
'confidence' => 99,
|
|
|
|
'geoname_id' => 1,
|
2013-10-21 13:18:12 +00:00
|
|
|
'iso_code' => 'US',
|
|
|
|
'names' => array('en' => 'United States of America'),
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
'location' => array(
|
2013-10-21 13:18:12 +00:00
|
|
|
'accuracy_radius' => 1500,
|
|
|
|
'latitude' => 44.98,
|
|
|
|
'longitude' => 93.2636,
|
|
|
|
'metro_code' => 765,
|
|
|
|
'postal_code' => '55401',
|
2013-05-09 14:28:01 +00:00
|
|
|
'postal_confidence' => 33,
|
2013-10-21 13:18:12 +00:00
|
|
|
'time_zone' => 'America/Chicago',
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
2013-05-21 20:46:11 +00:00
|
|
|
'maxmind' => array(
|
|
|
|
'queries_remaining' => 22,
|
|
|
|
),
|
2013-05-09 14:28:01 +00:00
|
|
|
'registered_country' => array(
|
|
|
|
'geoname_id' => 2,
|
2013-10-21 13:18:12 +00:00
|
|
|
'iso_code' => 'CA',
|
|
|
|
'names' => array('en' => 'Canada'),
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
'represented_country' => array(
|
|
|
|
'geoname_id' => 3,
|
2013-10-21 13:18:12 +00:00
|
|
|
'iso_code' => 'GB',
|
|
|
|
'names' => array('en' => 'United Kingdom'),
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
'subdivisions' => array(
|
|
|
|
array(
|
|
|
|
'confidence' => 88,
|
|
|
|
'geoname_id' => 574635,
|
2013-10-21 13:18:12 +00:00
|
|
|
'iso_code' => 'MN',
|
|
|
|
'names' => array('en' => 'Minnesota'),
|
2013-05-09 14:28:01 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'traits' => array(
|
2013-10-21 13:18:12 +00:00
|
|
|
'autonomous_system_number' => 1234,
|
2013-05-09 14:28:01 +00:00
|
|
|
'autonomous_system_organization' => 'AS Organization',
|
2013-10-21 13:18:12 +00:00
|
|
|
'domain' => 'example.com',
|
|
|
|
'ip_address' => '1.2.3.4',
|
2014-10-28 15:27:18 +00:00
|
|
|
'is_satellite_provider' => true,
|
2013-10-21 13:18:12 +00:00
|
|
|
'isp' => 'Comcast',
|
|
|
|
'organization' => 'Blorg',
|
|
|
|
'user_type' => 'college',
|
2013-05-09 14:28:01 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2014-07-15 21:19:30 +00:00
|
|
|
$model = new Insights($raw, array('en'));
|
2013-05-09 14:28:01 +00:00
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2014-07-15 21:19:30 +00:00
|
|
|
'GeoIp2\Model\Insights',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model,
|
2014-07-15 21:19:30 +00:00
|
|
|
'GeoIp2\Model\Insights object'
|
2013-05-09 14:28:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\City',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->city,
|
|
|
|
'$model->city'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Continent',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->continent,
|
|
|
|
'$model->continent'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->country,
|
|
|
|
'$model->country'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Location',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->location,
|
|
|
|
'$model->location'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->registeredCountry,
|
|
|
|
'$model->registeredCountry'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\RepresentedCountry',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->representedCountry,
|
|
|
|
'$model->representedCountry'
|
|
|
|
);
|
|
|
|
|
|
|
|
$subdivisions = $model->subdivisions;
|
|
|
|
foreach ($subdivisions as $subdiv) {
|
2013-07-10 22:24:40 +00:00
|
|
|
$this->assertInstanceOf('GeoIp2\Record\Subdivision', $subdiv);
|
2013-05-09 14:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Subdivision',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->mostSpecificSubdivision,
|
|
|
|
'$model->mostSpecificSubdivision'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Traits',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->traits,
|
|
|
|
'$model->traits'
|
|
|
|
);
|
|
|
|
|
2014-10-28 15:27:18 +00:00
|
|
|
$this->assertSame(
|
|
|
|
true,
|
|
|
|
$model->traits->isSatelliteProvider,
|
|
|
|
'$model->traits->isSatelliteProvider is true'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
false,
|
|
|
|
$model->traits->isAnonymousProxy,
|
|
|
|
'$model->traits->isAnonymousProxy is false'
|
|
|
|
);
|
|
|
|
|
2013-05-21 20:46:11 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
22,
|
|
|
|
$model->maxmind->queriesRemaining,
|
|
|
|
'queriesRemaining is correct'
|
|
|
|
);
|
|
|
|
|
2013-05-09 14:28:01 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$raw,
|
|
|
|
$model->raw,
|
|
|
|
'raw method returns raw input'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmptyObjects()
|
|
|
|
{
|
2013-10-21 13:18:12 +00:00
|
|
|
$raw = array('traits' => array('ip_address' => '5.6.7.8'));
|
2013-05-09 14:28:01 +00:00
|
|
|
|
2014-07-15 21:19:30 +00:00
|
|
|
$model = new Insights($raw, array('en'));
|
2013-05-09 14:28:01 +00:00
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2014-07-15 21:19:30 +00:00
|
|
|
'GeoIp2\Model\Insights',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model,
|
2014-07-15 21:19:30 +00:00
|
|
|
'GeoIp2\Model\Insights object with no data except traits.ipAddress'
|
2013-05-09 14:28:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\City',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->city,
|
|
|
|
'$model->city'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Continent',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->continent,
|
|
|
|
'$model->continent'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->country,
|
|
|
|
'$model->country'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Location',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->location,
|
|
|
|
'$model->location'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->registeredCountry,
|
|
|
|
'$model->registeredCountry'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\RepresentedCountry',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->representedCountry,
|
|
|
|
'$model->representedCountry'
|
|
|
|
);
|
2013-05-21 20:28:37 +00:00
|
|
|
|
2013-05-09 14:28:01 +00:00
|
|
|
$this->assertCount(
|
|
|
|
0,
|
|
|
|
$model->subdivisions,
|
|
|
|
'$model->subdivisions returns an empty list'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Subdivision',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->mostSpecificSubdivision,
|
|
|
|
'$model->mostSpecificSubdivision'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Traits',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model->traits,
|
|
|
|
'$model->traits'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$raw,
|
|
|
|
$model->raw,
|
|
|
|
'raw method returns raw input with no added empty values'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testUnknown()
|
|
|
|
{
|
|
|
|
$raw = array(
|
2013-10-21 13:18:12 +00:00
|
|
|
'new_top_level' => array('foo' => 42),
|
|
|
|
'city' => array(
|
2013-05-09 14:28:01 +00:00
|
|
|
'confidence' => 76,
|
2013-10-21 13:18:12 +00:00
|
|
|
'geoname_id_id' => 9876,
|
|
|
|
'names' => array('en' => 'Minneapolis'),
|
2013-05-09 14:28:01 +00:00
|
|
|
'population' => 50,
|
|
|
|
),
|
2013-10-21 13:18:12 +00:00
|
|
|
'traits' => array('ip_address' => '5.6.7.8')
|
2013-05-09 14:28:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// checking whether there are exceptions with unknown keys
|
2014-07-15 21:19:30 +00:00
|
|
|
$model = new Insights($raw, array('en'));
|
2013-05-09 14:28:01 +00:00
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
2014-07-15 21:19:30 +00:00
|
|
|
'GeoIp2\Model\Insights',
|
2013-05-09 14:28:01 +00:00
|
|
|
$model,
|
2014-07-15 21:19:30 +00:00
|
|
|
'no exception when Insights model gets raw data with unknown keys'
|
2013-05-09 14:28:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$raw,
|
|
|
|
$model->raw,
|
|
|
|
'raw method returns raw input'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|