Skip to content

Commit d3f10cf

Browse files
committed
add some tests to check error functionality
git-svn-id: http://svn.php.net/repository/pear/packages/Text_LanguageDetect/trunk@322330 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent d442fea commit d3f10cf

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Text/LanguageDetect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function _readdb($fname)
244244
);
245245
} elseif (!is_readable($fname)) {
246246
throw new Text_LanguageDetect_Exception(
247-
'Language database is not readable:' . $fname,
247+
'Language database is not readable: ' . $fname,
248248
Text_LanguageDetect_Exception::DB_NOT_READABLE
249249
);
250250
}

tests/Text_LanguageDetectTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Text_LanguageDetectTest extends PHPUnit_Framework_TestCase {
1616

1717
function setup ()
1818
{
19+
ini_set('magic_quotes_runtime', 0);
1920
$this->x = new Text_LanguageDetect();
2021
}
2122

@@ -24,6 +25,71 @@ function tearDown ()
2425
unset($this->x);
2526
}
2627

28+
function test_get_data_locAbsolute()
29+
{
30+
$this->assertEquals(
31+
'/path/to/file',
32+
$this->x->_get_data_loc('/path/to/file')
33+
);
34+
}
35+
36+
function test_get_data_locPearPath()
37+
{
38+
$this->x->_data_dir = '/path/to/pear/data';
39+
$this->assertEquals(
40+
'/path/to/pear/data/Text_LanguageDetect/file',
41+
$this->x->_get_data_loc('file')
42+
);
43+
}
44+
45+
/**
46+
* @expectedException Text_LanguageDetect_Exception
47+
* @expectedExceptionMessage Language database does not exist:
48+
*/
49+
function test_readdbNonexistingFile()
50+
{
51+
$this->x->_readdb('thisfiledoesnotexist');
52+
}
53+
54+
/**
55+
* @expectedException Text_LanguageDetect_Exception
56+
* @expectedExceptionMessage Language database is not readable:
57+
*/
58+
function test_readdbUnreadableFile()
59+
{
60+
$name = tempnam(sys_get_temp_dir(), 'unittest-Text_LanguageDetect-');
61+
chmod($name, 0000);
62+
$this->x->_readdb($name);
63+
}
64+
65+
/**
66+
* @expectedException Text_LanguageDetect_Exception
67+
* @expectedExceptionMessage Language database has no elements.
68+
*/
69+
function test_checkTrigramEmpty()
70+
{
71+
$this->x->_checkTrigram(array());
72+
}
73+
74+
/**
75+
* @expectedException Text_LanguageDetect_Exception
76+
* @expectedExceptionMessage Language database is not an array
77+
*/
78+
function test_checkTrigramNoArray()
79+
{
80+
$this->x->_checkTrigram('foo');
81+
}
82+
83+
/**
84+
* @expectedException Text_LanguageDetect_Exception
85+
* @expectedExceptionMessage Error loading database. Try turning magic_quotes_runtime off
86+
*/
87+
function test_checkTrigramNoArrayMagicQuotes()
88+
{
89+
ini_set('magic_quotes_runtime', 1);
90+
$this->x->_checkTrigram('foo');
91+
}
92+
2793
function test_splitter ()
2894
{
2995
$str = 'hello';

0 commit comments

Comments
 (0)