@@ -16,6 +16,7 @@ class Text_LanguageDetectTest extends PHPUnit_Framework_TestCase {
16
16
17
17
function setup ()
18
18
{
19
+ ini_set ('magic_quotes_runtime ' , 0 );
19
20
$ this ->x = new Text_LanguageDetect ();
20
21
}
21
22
@@ -24,6 +25,71 @@ function tearDown ()
24
25
unset($ this ->x );
25
26
}
26
27
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
+
27
93
function test_splitter ()
28
94
{
29
95
$ str = 'hello ' ;
0 commit comments