TestFuncString   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 168
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A TestAddslashesRecursive() 0 25 1
A TestJsonEncodeHex() 0 34 1
A TestJsonEncodeUnicode() 0 7 1
A TestMatchWildcard() 0 8 1
A TestOrgCodeGen() 0 22 1
A TestPin15To18() 0 10 1
A TestRfc2047Decode() 0 10 1
A TestStrToArray() 0 15 1
A TestSubstrIgnHtml() 0 16 1
1
<?php
2
/**
3
 * Test - string func
4
 *
5
 * @package     fwolflib
6
 * @subpackage	func.test
7
 * @copyright   Copyright 2004-2012, Fwolf
8
 * @author      Fwolf <[email protected]>
9
 * @since		2008-05-08
10
 */
11
12
// Define like this, so test can run both under eclipse and web alone.
13
// {{{
14
if (! defined('SIMPLE_TEST')) {
15
	define('SIMPLE_TEST', 'simpletest/');
16
	require_once(SIMPLE_TEST . 'autorun.php');
17
}
18
// Then set output encoding
19
//header('Content-Type: text/html; charset=utf-8');
20
// }}}
21
22
// Require library define file which need test
23
require_once('fwolflib/func/ecl.php');
24
require_once('fwolflib/func/request.php');
25
require_once('fwolflib/func/string.php');
26
27
class TestFuncString extends UnitTestCase {
28
29
	function TestAddslashesRecursive () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
		$x = array(
31
			"It's 1.",
32
			"It's 2."	=> "It's 3.",
33
			2012,
34
			"It's 4."	=> array(
35
				"It's 5."	=> array(
36
					"It's 6."	=> "It's 7.",
37
				),
38
			'end',
39
			),
40
		);
41
		$y = array(
42
			"It\\'s 1.",
43
			"It\\'s 2."	=> "It\\'s 3.",
44
			2012,
45
			"It\\'s 4."	=> array(
46
				"It\\'s 5."	=> array(
47
					"It\\'s 6."	=> "It\\'s 7.",
48
				),
49
			"end",
50
			),
51
		);
52
		$this->assertEqual($y, AddslashesRecursive($x));
0 ignored issues
show
Deprecated Code introduced by
The function AddslashesRecursive() has been deprecated with message: Use Fwlib\Util\StringUtil::addSlashesRecursive()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
53
	} // end of func TestAddslashesRecursive
54
55
56
	function TestJsonEncodeHex () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
57
		$x = true;
58
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
59
		$this->assertEqual($x, json_decode($y, true));
60
61
		$x = 3.86;
62
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
63
		$this->assertEqual($x, json_decode($y, true));
64
65
		$x = array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
66
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
67
		$this->assertEqual($x, json_decode($y, true));
68
69
		$x = array(5 => 'a',4 => 'b', 3 => 'c');
70
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
71
		$this->assertEqual($x, json_decode($y, true));
72
73
		$x = array(1 => 'a',2 => 'b', 3 => 'c');
74
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
75
		$this->assertEqual($x, json_decode($y, true));
76
77
		$x = array('<foo>',"'bar'",'"baz"','&blong&', true);
78
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
79
		$this->assertEqual($x, json_decode($y, true));
80
81
		$x = array('<foo>' => "'bar'",'"baz"' => '&blong&', 3.86);
82
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
83
		$this->assertEqual($x, json_decode($y, true));
84
85
		$x = array('<foo>' => "'bar'",'"baz"' => '&blong&', 2 => 'a我d');
86
		$y = JsonEncodeHex($x);
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeHex() has been deprecated with message: Use Fwlib\Util\Json::encodeHex()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
87
		$this->assertEqual($x, json_decode($y, true));
88
89
	} // end of func TestJsonEncodeHex
90
91
92
	function TestJsonEncodeUnicode () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
93
		$x = array('中文', array('中' => '文'));
94
		$y = '["中文",{"中":"文"}]';
95
		$this->assertEqual($y, JsonEncodeUnicode($x));
0 ignored issues
show
Deprecated Code introduced by
The function JsonEncodeUnicode() has been deprecated with message: Use Fwlib\Util\Json::encodeUnicode()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
96
97
		$this->assertEqual($x, json_decode($y, true));
98
	} // end of func TestJsonEncodeUnicode
99
100
101
	function TestMatchWildcard () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
102
		$s = 'abcdefg';
103
		$this->assertEqual(true, MatchWildcard($s, 'a*e?g'));
0 ignored issues
show
Deprecated Code introduced by
The function MatchWildcard() has been deprecated with message: Use Fwlib\Util\StringUtil::matchWildcard()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
104
		$this->assertEqual(true, MatchWildcard($s, '?b*e*'));
0 ignored issues
show
Deprecated Code introduced by
The function MatchWildcard() has been deprecated with message: Use Fwlib\Util\StringUtil::matchWildcard()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
105
		$this->assertEqual(false, MatchWildcard($s, '?b*e?'));
0 ignored issues
show
Deprecated Code introduced by
The function MatchWildcard() has been deprecated with message: Use Fwlib\Util\StringUtil::matchWildcard()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
106
		$s = 'abc';
107
		$this->assertEqual(true, MatchWildcard($s, 'a*'));
0 ignored issues
show
Deprecated Code introduced by
The function MatchWildcard() has been deprecated with message: Use Fwlib\Util\StringUtil::matchWildcard()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
108
	} // end of func TestMatchWildcard
109
110
111
    function TestOrgCodeGen () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
112
		$x = 'D2143569';
113
		$y = 'D2143569-X';
114
		$this->assertEqual(OrgCodeGen($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
115
116
		$x = 'd2143569';
117
		$y = 'D2143569-X';
118
		$this->assertEqual(OrgCodeGen($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
119
120
		$y = OrgCodeGen($x);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
121
		$x = substr($x, 0, 8);
122
		$this->assertEqual(OrgCodeGen($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
123
124
		$x = 'D214356';
125
		$y = '';
126
		$this->assertEqual(OrgCodeGen($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
127
128
		$x = 'D214356-';
129
		$y = '';
130
		$this->assertEqual(OrgCodeGen($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function OrgCodeGen() has been deprecated with message: Use Fwlib\Mis\OrgCode::gen()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
131
132
    } // end of func TestOrgCodeGen
133
134
135
    function TestPin15To18() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
136
		$x = '340524800101001';
137
		$y = '34052419800101001X';
138
		$this->assertEqual(Pin15To18($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function Pin15To18() has been deprecated with message: Use Fwlib\Mis\CinCode::to18()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
139
140
		$x = '410881790605552';
141
		$y = '410881197906055527';
142
		$this->assertEqual(Pin15To18($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function Pin15To18() has been deprecated with message: Use Fwlib\Mis\CinCode::to18()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
143
144
    } // end of func TestPin15To18
145
146
147
    function TestRfc2047Decode() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
148
    	$x = 'Re: =?utf-8?B?5aiB5Y6/55Sz5oql5Yi25bqm?=';
149
    	$y = 'Re: 威县申报制度';
150
    	$this->assertEqual(Rfc2047Decode($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function Rfc2047Decode() has been deprecated with message: Use Fwlib\Util\Rfc2047::decode()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
151
152
    	$x = '=?gbk?B?wLTX1HNqemxiekBzaW5hLmNvbbXE19S2r7vYuLQg?=';
153
    	$y = '来自[email protected]的自动回复 ';	// Without tailing ' ', will error.
154
    	$this->assertEqual(Rfc2047Decode($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function Rfc2047Decode() has been deprecated with message: Use Fwlib\Util\Rfc2047::decode()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
155
156
    } // end of func TestRfc2047Decode
157
158
159
	function TestStrToArray () {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
160
		$x = ' blah ';
161
		$y = array('blah');
162
		$y2 = array(' blah ');
163
		$this->assertEqual(StrToArray($x), $y);
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
164
		$this->assertEqual(StrToArray($x, '|', false), $y2);
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
165
166
		$x = ', a, b, c  , d  , ';
167
		$this->assertEqual(StrToArray($x, ','), array('a', 'b', 'c', 'd'));
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
168
		$this->assertEqual(StrToArray($x, ' '), array(',', 'a,', 'b,', 'c', ',', 'd', ','));
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
169
		$this->assertEqual(StrToArray($x, ',', true, false),
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
170
			array('', 'a', 'b', 'c',  'd', ''));
171
		$this->assertEqual(StrToArray($x, ',', false, true),
0 ignored issues
show
Deprecated Code introduced by
The function StrToArray() has been deprecated with message: Use Fwlib\Util\StringUtil::toArray()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
172
			array(' a', ' b', ' c  ',  ' d  ', ' '));
173
	} // end of func TestStrToArray
174
175
176
    function TestSubstrIgnHtml() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
177
    	$x = '测试12&lt;4测试';
178
    	$x = SubstrIgnHtml($x, 11, '...');
0 ignored issues
show
Deprecated Code introduced by
The function SubstrIgnHtml() has been deprecated with message: Use Fwlib\Util\StringUtil::substrIgnHtml()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
179
		$y = '测试12&lt;4...';
180
    	$this->assertEqual($x, $y);
181
182
    	$x = '测<b><i><br / >试</i></b>&quot;<b>234测试</b>';
183
    	$x = SubstrIgnHtml($x, 9, '...');
0 ignored issues
show
Deprecated Code introduced by
The function SubstrIgnHtml() has been deprecated with message: Use Fwlib\Util\StringUtil::substrIgnHtml()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
184
		$y = '测<b><i><br / >试</i></b>&quot;<b>2...</b>';
185
    	$this->assertEqual($x, $y);
186
187
		$x = '`reStructuredText 中文示例 <?f=20101113-restructuredtext-example.rst>`_';
188
		$y = SubstrIgnHtml($x, 71, '');
0 ignored issues
show
Deprecated Code introduced by
The function SubstrIgnHtml() has been deprecated with message: Use Fwlib\Util\StringUtil::substrIgnHtml()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
189
		$this->assertEqual($x, $y);
190
191
    } // end of func TestSubstrIgnHtml
192
193
194
} // end of class TestFuncString
195
196
197
// Change output charset in this way.
198
// {{{
199
$s_url = GetSelfUrl(false);
0 ignored issues
show
Deprecated Code introduced by
The function GetSelfUrl() has been deprecated with message: Use Fwlib\Util\HttpUtil::getSelfUrl()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
200
$s_url = substr($s_url, strrpos($s_url, '/') + 1);
201
if ('string.test.php' == $s_url) {
202
	$test = new TestFuncString();
203
	$test->run(new HtmlReporter('utf-8'));
204
}
205
// }}}
206
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
207