|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace libphonenumber\Tests\prefixmapper; |
|
4
|
|
|
|
|
5
|
|
|
use libphonenumber\PhoneNumber; |
|
6
|
|
|
use libphonenumber\prefixmapper\PrefixFileReader; |
|
7
|
|
|
|
|
8
|
|
|
class PrefixFileReaderTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
const TEST_META_DATA_FILE_PREFIX = "/data/"; |
|
11
|
|
|
private static $KO_NUMBER; |
|
12
|
|
|
private static $US_NUMBER1; |
|
13
|
|
|
private static $US_NUMBER2; |
|
14
|
|
|
private static $US_NUMBER3; |
|
15
|
|
|
private static $SE_NUMBER; |
|
16
|
|
|
/** |
|
17
|
|
|
* @var PrefixFileReader |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $reader; |
|
20
|
|
|
|
|
21
|
|
|
public static function setUpBeforeClass() |
|
22
|
|
|
{ |
|
23
|
|
|
self::$KO_NUMBER = new PhoneNumber(); |
|
24
|
|
|
self::$KO_NUMBER->setCountryCode(82)->setNationalNumber(22123456); |
|
25
|
|
|
|
|
26
|
|
|
self::$US_NUMBER1 = new PhoneNumber(); |
|
27
|
|
|
self::$US_NUMBER1->setCountryCode(1)->setNationalNumber(6502530000); |
|
28
|
|
|
|
|
29
|
|
|
self::$US_NUMBER2 = new PhoneNumber(); |
|
30
|
|
|
self::$US_NUMBER2->setCountryCode(1)->setNationalNumber(2128120000); |
|
31
|
|
|
|
|
32
|
|
|
self::$US_NUMBER3 = new PhoneNumber(); |
|
33
|
|
|
self::$US_NUMBER3->setCountryCode(1)->setNationalNumber(6174240000); |
|
34
|
|
|
|
|
35
|
|
|
self::$SE_NUMBER = new PhoneNumber(); |
|
36
|
|
|
self::$SE_NUMBER->setCountryCode(46)->setNationalNumber(81234567); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function setUp() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->reader = new PrefixFileReader(__DIR__ . DIRECTORY_SEPARATOR . self::TEST_META_DATA_FILE_PREFIX); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGetDescriptionForNumberWithMapping() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertEquals("Kalifornien", $this->reader->getDescriptionForNumber(self::$US_NUMBER1, "de", "", "CH")); |
|
47
|
|
|
$this->assertEquals("CA", $this->reader->getDescriptionForNumber(self::$US_NUMBER1, "en", "", "AU")); |
|
48
|
|
|
$this->assertEquals( |
|
49
|
|
|
pack('H*', 'ec849c') . pack('H*', 'ec9ab8'), |
|
50
|
|
|
$this->reader->getDescriptionForNumber(self::$KO_NUMBER, "ko", "", "") |
|
51
|
|
|
); |
|
52
|
|
|
$this->assertEquals("Seoul", $this->reader->getDescriptionForNumber(self::$KO_NUMBER, "en", "", "")); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGetDescriptionForNumberWithMissingMapping() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertEquals("", $this->reader->getDescriptionForNumber(self::$US_NUMBER3, "en", "", "")); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testGetDescriptionUsingFallbackLanguage() |
|
61
|
|
|
{ |
|
62
|
|
|
// Mapping file exists but the number isn't present, causing it to fallback. |
|
63
|
|
|
$this->assertEquals("New York, NY", $this->reader->getDescriptionForNumber(self::$US_NUMBER2, "de", "", "CH")); |
|
64
|
|
|
// No mapping file exists, causing it to fallback. |
|
65
|
|
|
$this->assertEquals("New York, NY", $this->reader->getDescriptionForNumber(self::$US_NUMBER2, "sv", "", "")); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testGetDescriptionForNonFallbackLanguage() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->assertEquals("", $this->reader->getDescriptionForNumber(self::$US_NUMBER2, "ko", "", "")); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGetDescriptionForNumberWithoutMappingFile() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->assertEquals("", $this->reader->getDescriptionForNumber(self::$SE_NUMBER, "sv", "", "")); |
|
76
|
|
|
$this->assertEquals("", $this->reader->getDescriptionForNumber(self::$SE_NUMBER, "en", "", "")); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|