2013-05-09 14:45:23 +00:00
|
|
|
<?php
|
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
namespace GeoIp2\Test\Model;
|
2013-05-09 14:45:23 +00:00
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
use GeoIp2\Model\Country;
|
2013-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
class NameTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public $raw = array(
|
|
|
|
'continent' => array(
|
2013-05-21 20:28:37 +00:00
|
|
|
'code' => 'NA',
|
|
|
|
'geoname_id' => 42,
|
|
|
|
'names' => array(
|
2013-05-09 14:45:23 +00:00
|
|
|
'en' => 'North America',
|
|
|
|
'zh-CN' => '北美洲',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'country' => array(
|
|
|
|
'geoname_id' => 1,
|
|
|
|
'iso_code' => 'US',
|
|
|
|
'names' => array(
|
|
|
|
'en' => 'United States of America',
|
|
|
|
'ru' => 'объединяет государства',
|
|
|
|
'zh-CN' => '美国',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'traits' => array(
|
|
|
|
'ip_address' => '1.2.3.4',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
public function testFallback()
|
|
|
|
{
|
|
|
|
$model = new Country($this->raw, array( 'ru', 'zh-CN', 'en' ));
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'北美洲',
|
|
|
|
$model->continent->name,
|
|
|
|
'continent name is in Chinese (no Russian available)'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'объединяет государства',
|
|
|
|
$model->country->name,
|
|
|
|
'country name is in Russian'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-10 22:24:40 +00:00
|
|
|
public function testTwoFallbacks()
|
|
|
|
{
|
2013-05-09 14:45:23 +00:00
|
|
|
$model = new Country($this->raw, array('ru', 'ja'));
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
null,
|
|
|
|
$model->continent->name,
|
|
|
|
'continent name is undef (no Russian or Japanese available)'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'объединяет государства',
|
|
|
|
$model->country->name,
|
|
|
|
'country name is in Russian'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoFallbacks()
|
|
|
|
{
|
|
|
|
$model = new Country($this->raw, array('ja'));
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
null,
|
|
|
|
$model->continent->name,
|
|
|
|
'continent name is undef (no Japanese available) '
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
null,
|
|
|
|
$model->country->name,
|
|
|
|
'country name is undef (no Japanese available) '
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|