2013-05-08 22:23:28 +00:00
|
|
|
<?php
|
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
namespace GeoIp2\Test\Model;
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
use GeoIp2\Model\Country;
|
2013-05-08 22:23:28 +00:00
|
|
|
|
|
|
|
class CountryTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
private $raw = array(
|
2013-05-09 14:29:29 +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-08 22:23:28 +00:00
|
|
|
),
|
|
|
|
'country' => array(
|
|
|
|
'geoname_id' => 1,
|
2013-10-21 13:18:12 +00:00
|
|
|
'iso_code' => 'US',
|
|
|
|
'names' => array('en' => 'United States of America'),
|
2013-05-08 22:23:28 +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-08 22:23:28 +00:00
|
|
|
),
|
|
|
|
'traits' => array(
|
|
|
|
'ip_address' => '1.2.3.4',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
private $model;
|
|
|
|
|
2013-10-21 13:18:12 +00:00
|
|
|
public function setUp()
|
2013-05-09 14:29:29 +00:00
|
|
|
{
|
2013-05-09 15:05:59 +00:00
|
|
|
$this->model = new Country($this->raw, array('en'));
|
2013-05-08 22:23:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 13:18:12 +00:00
|
|
|
public function testObjects()
|
2013-05-09 14:29:29 +00:00
|
|
|
{
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Model\Country',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model,
|
2013-07-10 22:24:40 +00:00
|
|
|
'minimal GeoIp2::Model::Country object'
|
2013-05-09 14:29:29 +00:00
|
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Continent',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->continent
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->country
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Country',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->registeredCountry
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\RepresentedCountry',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->representedCountry
|
|
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
2013-07-10 22:24:40 +00:00
|
|
|
'GeoIp2\Record\Traits',
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->traits
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
public function testValues()
|
|
|
|
{
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
42,
|
|
|
|
$this->model->continent->geonameId,
|
|
|
|
'continent geoname_id is 42'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'NA',
|
2013-05-21 20:28:37 +00:00
|
|
|
$this->model->continent->code,
|
|
|
|
'continent code is NA'
|
2013-05-09 14:29:29 +00:00
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
2013-10-21 13:18:12 +00:00
|
|
|
array('en' => 'North America'),
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->continent->names,
|
|
|
|
'continent names'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'North America',
|
|
|
|
$this->model->continent->name,
|
|
|
|
'continent name is North America'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
$this->model->country->geonameId,
|
|
|
|
'country geoname_id is 1'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'US',
|
|
|
|
$this->model->country->isoCode,
|
|
|
|
'country iso_code is US'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
2013-10-21 13:18:12 +00:00
|
|
|
array('en' => 'United States of America'),
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->country->names,
|
|
|
|
'country name'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$this->model->country->name,
|
|
|
|
'United States of America',
|
|
|
|
'country name is United States of America'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
null,
|
|
|
|
$this->model->country->confidence,
|
|
|
|
'country confidence is undef'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
2,
|
|
|
|
$this->model->registeredCountry->geonameId,
|
|
|
|
'registered_country geoname_id is 2'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'CA',
|
|
|
|
$this->model->registeredCountry->isoCode,
|
|
|
|
'registered_country iso_code is CA'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
2013-10-21 13:18:12 +00:00
|
|
|
array('en' => 'Canada'),
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->model->registeredCountry->names,
|
|
|
|
'registered_country names'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'Canada',
|
|
|
|
$this->model->registeredCountry->name,
|
|
|
|
'registered_country name is Canada'
|
2013-05-08 22:23:28 +00:00
|
|
|
);
|
|
|
|
|
2013-10-21 13:18:12 +00:00
|
|
|
foreach (array('isAnonymousProxy', 'isSatelliteProvider') as $meth) {
|
2013-05-09 14:29:29 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
$this->model->traits->$meth,
|
|
|
|
"traits $meth returns 0 by default"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->raw,
|
|
|
|
$this->model->raw,
|
|
|
|
'raw method returns raw input'
|
|
|
|
);
|
2013-05-08 22:23:28 +00:00
|
|
|
}
|
2013-10-26 21:13:56 +00:00
|
|
|
|
|
|
|
public function testJsonSerialize()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->raw,
|
|
|
|
$this->model->jsonSerialize(),
|
|
|
|
'jsonSerialize returns initial array'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->raw['country'],
|
|
|
|
$this->model->country->jsonSerialize(),
|
|
|
|
'jsonSerialize returns initial array for the record'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
|
|
|
|
$this->markTestSkipped('Requires PHP 5.4+.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
json_encode($this->raw),
|
|
|
|
json_encode($this->model),
|
|
|
|
'json_encode can be called on the model object directly'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
json_encode($this->raw['country']),
|
|
|
|
json_encode($this->model->country),
|
|
|
|
'json_encode can be called on the record object directly'
|
|
|
|
);
|
|
|
|
}
|
2013-05-08 22:23:28 +00:00
|
|
|
}
|