Skip to content

Commit 2ee13b2

Browse files
committed
part of #19221: Unittest for ISO 639 conversion
git-svn-id: http://svn.php.net/repository/pear/packages/Text_LanguageDetect/trunk@322187 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent b1f2782 commit 2ee13b2

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

Text/LanguageDetect/ISO639.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Text_LanguageDetect_ISO639
255255
'pol' => 'polish',
256256
'por' => 'portuguese',
257257
'pus' => 'pashto',
258-
'ron' => 'romanian',
258+
'rom' => 'romanian',
259259
'rus' => 'russian',
260260
'slk' => 'slovak',
261261
'slv' => 'slovene',
@@ -299,10 +299,10 @@ public static function nameToCode2($lang)
299299
public static function nameToCode3($lang)
300300
{
301301
$lang = strtolower($lang);
302-
if (!isset(self::$nameToCode2[$lang])) {
302+
if (!isset(self::$nameToCode3[$lang])) {
303303
return null;
304304
}
305-
return self::$nameToCode2[$lang];
305+
return self::$nameToCode3[$lang];
306306
}
307307

308308
/**
@@ -314,11 +314,11 @@ public static function nameToCode3($lang)
314314
*/
315315
public static function code2ToName($code)
316316
{
317-
$lang = strtolower($lang);
318-
if (!isset(self::$code2ToName[$lang])) {
317+
$lang = strtolower($code);
318+
if (!isset(self::$code2ToName[$code])) {
319319
return null;
320320
}
321-
return self::$code2ToName[$lang];
321+
return self::$code2ToName[$code];
322322
}
323323

324324
/**
@@ -330,11 +330,11 @@ public static function code2ToName($code)
330330
*/
331331
public static function code3ToName($code)
332332
{
333-
$lang = strtolower($lang);
334-
if (!isset(self::$code3ToName[$lang])) {
333+
$lang = strtolower($code);
334+
if (!isset(self::$code3ToName[$code])) {
335335
return null;
336336
}
337-
return self::$code3ToName[$lang];
337+
return self::$code3ToName[$code];
338338
}
339339
}
340340

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
set_include_path(
3+
__DIR__ . '/../' . PATH_SEPARATOR . get_include_path()
4+
);
5+
6+
require_once 'Text/LanguageDetect/ISO639.php';
7+
8+
class Text_LanguageDetect_ISO639Test extends PHPUnit_Framework_TestCase
9+
{
10+
public function testNameToCode2()
11+
{
12+
$this->assertEquals(
13+
'de',
14+
Text_LanguageDetect_ISO639::nameToCode2('german')
15+
);
16+
}
17+
18+
public function testNameToCode2Fail()
19+
{
20+
$this->assertNull(
21+
Text_LanguageDetect_ISO639::nameToCode2('doesnotexist')
22+
);
23+
}
24+
25+
public function testNameToCode3()
26+
{
27+
$this->assertEquals(
28+
'fra',
29+
Text_LanguageDetect_ISO639::nameToCode3('french')
30+
);
31+
}
32+
33+
public function testNameToCode3Fail()
34+
{
35+
$this->assertNull(
36+
Text_LanguageDetect_ISO639::nameToCode3('doesnotexist')
37+
);
38+
}
39+
40+
public function testCode2ToName()
41+
{
42+
$this->assertEquals(
43+
'english',
44+
Text_LanguageDetect_ISO639::code2ToName('en')
45+
);
46+
}
47+
48+
public function testCode2ToNameFail()
49+
{
50+
$this->assertNull(
51+
Text_LanguageDetect_ISO639::code2ToName('nx')
52+
);
53+
}
54+
55+
public function testCode3ToName()
56+
{
57+
$this->assertEquals(
58+
'romanian',
59+
Text_LanguageDetect_ISO639::code3ToName('rom')
60+
);
61+
}
62+
63+
public function testCode3ToNameFail()
64+
{
65+
$this->assertNull(
66+
Text_LanguageDetect_ISO639::code3ToName('nxx')
67+
);
68+
}
69+
70+
}
71+
72+
?>

0 commit comments

Comments
 (0)