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