1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - class Sms |
4
|
|
|
* |
5
|
|
|
* @package fwolflib |
6
|
|
|
* @subpackage class.test |
7
|
|
|
* @copyright Copyright 2010, Fwolf |
8
|
|
|
* @author Fwolf <[email protected]> |
9
|
|
|
* @since 2010-11-23 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
14
|
|
|
// {{{ |
15
|
|
|
if (! defined('SIMPLE_TEST')) { |
16
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
17
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
18
|
|
|
} |
19
|
|
|
// Then set output encoding |
20
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
21
|
|
|
// }}} |
22
|
|
|
|
23
|
|
|
// Require library define file which need test |
24
|
|
|
require_once('../fwolflib.php'); |
25
|
|
|
require_once(FWOLFLIB . 'class/adodb.php'); |
26
|
|
|
require_once(FWOLFLIB . 'class/sms.php'); |
27
|
|
|
require_once(FWOLFLIB . 'func/request.php'); |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class TestClassSms extends UnitTestCase { |
31
|
|
|
|
32
|
|
|
function __construct() { |
|
|
|
|
33
|
|
|
$ar_db = array( |
34
|
|
|
'type' => 'mysqli', |
35
|
|
|
'host' => 'localhost', |
36
|
|
|
'user' => 't-sms', |
37
|
|
|
'pass' => '', |
38
|
|
|
'name' => 't-sms', |
39
|
|
|
'lang' => 'utf-8', |
40
|
|
|
); |
41
|
|
|
$o_db = new Adodb($ar_db); |
|
|
|
|
42
|
|
|
$o_db->Connect(); |
43
|
|
|
$this->oSms = new Sms($o_db); |
|
|
|
|
44
|
|
|
// Cat of debug sms |
45
|
|
|
$this->iCat = 1020000; |
46
|
|
|
} // end of func __construct |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
function TestCountPart () { |
|
|
|
|
50
|
|
|
$s_sms = ''; // 0 |
51
|
|
|
$this->assertEqual(0, $this->oSms->CountPart($s_sms)); |
52
|
|
|
$s_sms = '01234567890123456789012345678901234567890123456789' |
53
|
|
|
. '01234567890123456789012345678901234567890123456789' |
54
|
|
|
. '0123456789012345678901234567890123456789'; // 140 |
55
|
|
|
$this->assertEqual(1, $this->oSms->CountPart($s_sms)); |
56
|
|
|
$s_sms = '01234567890123456789012345678901234567890123456789' |
57
|
|
|
. '01234567890123456789012345678901234567890123456789 |
58
|
|
|
01234567890123456789012345678901234567890'; // 141 |
59
|
|
|
$this->assertEqual(2, $this->oSms->CountPart($s_sms)); |
60
|
|
|
|
61
|
|
|
$s_sms = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十' |
62
|
|
|
. '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 |
63
|
|
|
一二三四五六七八'; // 69 |
64
|
|
|
$this->assertEqual(1, $this->oSms->CountPart($s_sms)); |
65
|
|
|
$s_sms = '0123456789一二三四五六七八九十一二三四五六七八九十' |
66
|
|
|
. '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十' |
67
|
|
|
. '一二三四五六七八九十'; // 70 |
68
|
|
|
$this->assertEqual(1, $this->oSms->CountPart($s_sms)); |
69
|
|
|
$s_sms = '0123456789一二三四五六七八九十一二三四五六七八九十' |
70
|
|
|
. '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十' |
71
|
|
|
. '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十' |
72
|
|
|
. '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十' |
73
|
|
|
. '一二三四五六七八九十一二三四五六七八九十'; // 140 |
74
|
|
|
$this->assertEqual(2, $this->oSms->CountPart($s_sms)); |
75
|
|
|
} // end of func TestCountPart |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
function TestDestParse () { |
|
|
|
|
79
|
|
|
$s_dest = "13912345678 |
80
|
|
|
13912345678,; |
81
|
|
|
008613912345678 ,\t |
82
|
|
|
13921345678\r\n\t |
83
|
|
|
1392345678\r\n\t |
84
|
|
|
+8613912345678; |
85
|
|
|
+8613912345678,end |
86
|
|
|
"; |
87
|
|
|
$ar_dest = array('13912345678', '13921345678'); |
88
|
|
|
$this->assertEqual($ar_dest, $this->oSms->DestParse($s_dest)); |
89
|
|
|
|
90
|
|
|
$s_dest = "13012345678,13012345679"; |
91
|
|
|
$ar_dest = array('13012345678', '13012345679'); |
92
|
|
|
$this->assertEqual($ar_dest, $this->oSms->DestParse($s_dest)); |
93
|
|
|
} // end of func TestDestParse |
94
|
|
|
|
95
|
|
|
function TestSendUsingGammuSmsdInject () { |
|
|
|
|
96
|
|
|
$this->oSms->SendUsingGammuSmsdInject('1391234567' |
97
|
|
|
, '测试短信', $this->iCat); |
98
|
|
|
} // end of func TestSendUsingGammuSmsdInject |
99
|
|
|
|
100
|
|
|
} // end of class TestClassSms |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
// Change output charset in this way. |
104
|
|
|
// {{{ |
105
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
106
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
107
|
|
|
if ('sms.test.php' == $s_url) { |
108
|
|
|
$test = new TestClassSms(); |
109
|
|
|
$test->run(new HtmlReporter('utf-8')); |
110
|
|
|
} |
111
|
|
|
// }}} |
112
|
|
|
?> |
|
|
|
|
113
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.