1: <?php
2:
3: namespace GeoIp2\Test\Model;
4:
5: use GeoIp2\Model\Country;
6:
7: class NameTest extends \PHPUnit_Framework_TestCase
8: {
9: public $raw = array(
10: 'continent' => array(
11: 'code' => 'NA',
12: 'geoname_id' => 42,
13: 'names' => array(
14: 'en' => 'North America',
15: 'zh-CN' => '北美洲',
16: ),
17: ),
18: 'country' => array(
19: 'geoname_id' => 1,
20: 'iso_code' => 'US',
21: 'names' => array(
22: 'en' => 'United States of America',
23: 'ru' => 'объединяет государства',
24: 'zh-CN' => '美国',
25: ),
26: ),
27: 'traits' => array(
28: 'ip_address' => '1.2.3.4',
29: ),
30: );
31:
32: public function testFallback()
33: {
34: $model = new Country($this->raw, array('ru', 'zh-CN', 'en'));
35:
36: $this->assertEquals(
37: '北美洲',
38: $model->continent->name,
39: 'continent name is in Chinese (no Russian available)'
40: );
41:
42: $this->assertEquals(
43: 'объединяет государства',
44: $model->country->name,
45: 'country name is in Russian'
46: );
47: }
48:
49: public function testTwoFallbacks()
50: {
51: $model = new Country($this->raw, array('ru', 'ja'));
52:
53: $this->assertEquals(
54: null,
55: $model->continent->name,
56: 'continent name is undef (no Russian or Japanese available)'
57: );
58:
59: $this->assertEquals(
60: 'объединяет государства',
61: $model->country->name,
62: 'country name is in Russian'
63: );
64: }
65:
66: public function testNoFallbacks()
67: {
68: $model = new Country($this->raw, array('ja'));
69:
70: $this->assertEquals(
71: null,
72: $model->continent->name,
73: 'continent name is undef (no Japanese available) '
74: );
75:
76: $this->assertEquals(
77: null,
78: $model->country->name,
79: 'country name is undef (no Japanese available) '
80: );
81: }
82: }
83: