GeoIP2-php/tests/GeoIP2/Test/Model/CountryTest.php

163 lines
4.1 KiB
PHP
Raw Normal View History

2013-05-08 22:23:28 +00:00
<?php
2013-05-09 14:45:23 +00:00
namespace GeoIP2\Test\Model;
2013-05-08 22:23:28 +00:00
use GeoIP2\Model\Country;
class CountryTest extends \PHPUnit_Framework_TestCase
{
private $raw = array(
'continent' => array(
2013-05-08 22:23:28 +00:00
'continent_code' => 'NA',
'geoname_id' => 42,
'names' => array( 'en' => 'North America' ),
),
'country' => array(
'geoname_id' => 1,
'iso_code' => 'US',
'names' => array( 'en' => 'United States of America' ),
),
'registered_country' => array(
'geoname_id' => 2,
'iso_code' => 'CA',
'names' => array( 'en' => 'Canada' ),
),
'traits' => array(
'ip_address' => '1.2.3.4',
),
);
private $model;
public function setUp ()
{
2013-05-09 15:05:59 +00:00
$this->model = new Country($this->raw, array('en'));
2013-05-08 22:23:28 +00:00
}
public function testObjects ()
{
$this->assertInstanceOf(
'GeoIP2\Model\Country',
$this->model,
'minimal GeoIP2::Model::Country object'
);
$this->assertInstanceOf(
'GeoIP2\Record\Continent',
$this->model->continent
);
$this->assertInstanceOf(
'GeoIP2\Record\Country',
$this->model->country
);
$this->assertInstanceOf(
'GeoIP2\Record\Country',
$this->model->registeredCountry
);
$this->assertInstanceOf(
'GeoIP2\Record\RepresentedCountry',
$this->model->representedCountry
);
$this->assertInstanceOf(
'GeoIP2\Record\Traits',
$this->model->traits
);
2013-05-08 22:23:28 +00:00
}
public function testValues()
{
2013-05-08 22:23:28 +00:00
$this->assertEquals(
42,
$this->model->continent->geonameId,
'continent geoname_id is 42'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
'NA',
$this->model->continent->continentCode,
'continent continent_code is NA'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
array( 'en' => 'North America' ),
$this->model->continent->names,
'continent names'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
'North America',
$this->model->continent->name,
'continent name is North America'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
1,
$this->model->country->geonameId,
'country geoname_id is 1'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
'US',
$this->model->country->isoCode,
'country iso_code is US'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
array( 'en' => 'United States of America' ),
$this->model->country->names,
'country name'
);
2013-05-08 22:23:28 +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
$this->assertEquals(
null,
$this->model->country->confidence,
'country confidence is undef'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
2,
$this->model->registeredCountry->geonameId,
'registered_country geoname_id is 2'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
'CA',
$this->model->registeredCountry->isoCode,
'registered_country iso_code is CA'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
array( 'en' => 'Canada' ),
$this->model->registeredCountry->names,
'registered_country names'
);
2013-05-08 22:23:28 +00:00
$this->assertEquals(
'Canada',
$this->model->registeredCountry->name,
'registered_country name is Canada'
2013-05-08 22:23:28 +00:00
);
foreach (array( 'isAnonymousProxy', 'isSatelliteProvider' ) as $meth) {
$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
}
}