1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
<?php
/**
* Test class to test rcube_shared functions
*
* @package Tests
*/
class Framework_Shared extends PHPUnit_Framework_TestCase
{
/**
* rcube_shared.inc: in_array_nocase()
*/
function test_in_array_nocase()
{
$haystack = array('Test');
$needle = 'test';
$result = in_array_nocase($needle, $haystack);
$this->assertTrue($result, $title);
$result = in_array_nocase($needle, null);
$this->assertFalse($result, $title);
}
/**
* rcube_shared.inc: get_boolean()
*/
function test_get_boolean()
{
$input = array(
false, 'false', '0', 'no', 'off', 'nein', 'FALSE', '', null,
);
foreach ($input as $idx => $value) {
$this->assertFalse(get_boolean($value), "Invalid result for $idx test item");
}
$input = array(
true, 'true', '1', 1, 'yes', 'anything', 1000,
);
foreach ($input as $idx => $value) {
$this->assertTrue(get_boolean($value), "Invalid result for $idx test item");
}
}
/**
* rcube_shared.inc: parse_bytes()
*/
function test_parse_bytes()
{
$data = array(
'1' => 1,
'1024' => 1024,
'2k' => 2 * 1024,
'2 k' => 2 * 1024,
'2kb' => 2 * 1024,
'2kB' => 2 * 1024,
'2m' => 2 * 1048576,
'2 m' => 2 * 1048576,
'2mb' => 2 * 1048576,
'2mB' => 2 * 1048576,
'2g' => 2 * 1024 * 1048576,
'2 g' => 2 * 1024 * 1048576,
'2gb' => 2 * 1024 * 1048576,
'2gB' => 2 * 1024 * 1048576,
);
foreach ($data as $value => $expected) {
$result = parse_bytes($value);
$this->assertEquals($expected, $result, "Invalid parse_bytes() result for $value");
}
}
/**
* rcube_shared.inc: slashify()
*/
function test_slashify()
{
$data = array(
'test' => 'test/',
'test/' => 'test/',
'' => '/',
"\\" => "\\/",
);
foreach ($data as $value => $expected) {
$result = slashify($value);
$this->assertEquals($expected, $result, "Invalid slashify() result for $value");
}
}
/**
* rcube_shared.inc: unslashify()
*/
function test_unslashify()
{
$data = array(
'test' => 'test',
'test/' => 'test',
'/' => '',
"\\/" => "\\",
'test/test' => 'test/test',
'test//' => 'test',
);
foreach ($data as $value => $expected) {
$result = unslashify($value);
$this->assertEquals($expected, $result, "Invalid unslashify() result for $value");
}
}
/**
* rcube_shared.inc: get_offset_sec()
*/
function test_get_offset_sec()
{
$data = array(
'1s' => 1,
'1m' => 1 * 60,
'1h' => 1 * 60 * 60,
'1d' => 1 * 60 * 60 * 24,
'1w' => 1 * 60 * 60 * 24 * 7,
'1y' => (int) '1y',
100 => 100,
'100' => 100,
);
foreach ($data as $value => $expected) {
$result = get_offset_sec($value);
$this->assertEquals($expected, $result, "Invalid get_offset_sec() result for $value");
}
}
/**
* rcube_shared.inc: array_keys_recursive()
*/
function test_array_keys_recursive()
{
$input = array(
'one' => array(
'two' => array(
'three' => array(),
'four' => 'something',
),
),
'five' => 'test',
);
$result = array_keys_recursive($input);
$input_str = 'one,two,three,four,five';
$result_str = implode(',', $result);
$this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result");
}
}
|