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->assertSame(
37 '北美洲',
38 $model->continent->name,
39 'continent name is in Chinese (no Russian available)'
40 );
41
42 $this->assertTrue(
43 isset($model->continent->name),
44 'continent name is set'
45 );
46
47 $this->assertFalse(
48 empty($model->continent->name),
49 'continent name is not empty'
50 );
51
52 $this->assertSame(
53 'объединяет государства',
54 $model->country->name,
55 'country name is in Russian'
56 );
57 }
58
59 public function testTwoFallbacks()
60 {
61 $model = new Country($this->raw, array('ru', 'ja'));
62
63 $this->assertSame(
64 null,
65 $model->continent->name,
66 'continent name is undef (no Russian or Japanese available)'
67 );
68
69 $this->assertFalse(
70 isset($model->continent->name),
71 'continent name is not set'
72 );
73
74 $this->assertTrue(
75 empty($model->continent->name),
76 'continent name is empty'
77 );
78
79 $this->assertSame(
80 'объединяет государства',
81 $model->country->name,
82 'country name is in Russian'
83 );
84 }
85
86 public function testNoFallbacks()
87 {
88 $model = new Country($this->raw, array('ja'));
89
90 $this->assertSame(
91 null,
92 $model->continent->name,
93 'continent name is undef (no Japanese available) '
94 );
95
96 $this->assertSame(
97 null,
98 $model->country->name,
99 'country name is undef (no Japanese available) '
100 );
101 }
102 }
103