webservice MDL-20805 add missing exception string message
[moodle.git] / lib / simpletest / testmoodlelib.php
CommitLineData
8926f844 1<?php
d499142e 2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.org //
9// //
56a1a882 10// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
d499142e 11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
7c9d46c9 26/**
27 * Unit tests for (some of) ../moodlelib.php.
28 *
bb45fe62 29 * Note, tests for get_string are in the separate file testgetstring.php.
30 *
7c9d46c9 31 * @copyright &copy; 2006 The Open University
32 * @author T.J.Hunt@open.ac.uk
d499142e 33 * @author nicolas@moodle.com
7c9d46c9 34 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
35 * @package moodlecore
36 */
37
cdbbd26f 38if (!defined('MOODLE_INTERNAL')) {
39 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
40}
7c9d46c9 41
7c9d46c9 42require_once($CFG->libdir . '/moodlelib.php');
43
cc4245a3 44class moodlelib_test extends UnitTestCase {
b9c639d6 45
081a63a9 46 public static $includecoverage = array('lib/moodlelib.php');
db3a1eb8 47
a205dcdc 48 var $user_agents = array(
49 'MSIE' => array(
50 '5.5' => array('Windows 2000' => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'),
51 '6.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'),
ec012320 52 '7.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)'),
53 '8.0' => array('Windows Vista' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)'),
54
b9c639d6 55 ),
a205dcdc 56 'Firefox' => array(
57 '1.0.6' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6'),
58 '1.5' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
59 '1.5.0.1' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'),
60 '2.0' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
ec012320 61 'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)'),
62 '3.0.6' => array('SUSE' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6'),
a205dcdc 63 ),
64 'Safari' => array(
65 '312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'),
66 '2.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412')
67 ),
68 'Opera' => array(
69 '8.51' => array('Windows XP' => 'Opera/8.51 (Windows NT 5.1; U; en)'),
70 '9.0' => array('Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)',
71 'Debian Linux' => 'Opera/9.01 (X11; Linux i686; U; en)')
72 )
73 );
b9c639d6 74
65de6864 75 function test_cleanremoteaddr() {
76 //IPv4
77 $this->assertEqual(cleanremoteaddr('1023.121.234.1'), null);
78 $this->assertEqual(cleanremoteaddr('123.121.234.01 '), '123.121.234.1');
79
80 //IPv6
81 $this->assertEqual(cleanremoteaddr('0:0:0:0:0:0:0:0:0'), null);
82 $this->assertEqual(cleanremoteaddr('0:0:0:0:0:0:0:abh'), null);
83 $this->assertEqual(cleanremoteaddr('0:0:0:::0:0:1'), null);
84 $this->assertEqual(cleanremoteaddr('0:0:0:0:0:0:0:0', true), '::');
85 $this->assertEqual(cleanremoteaddr('0:0:0:0:0:0:1:1', true), '::1:1');
86 $this->assertEqual(cleanremoteaddr('abcd:00ef:0:0:0:0:0:0', true), 'abcd:ef::');
87 $this->assertEqual(cleanremoteaddr('1:0:0:0:0:0:0:1', true), '1::1');
88 $this->assertEqual(cleanremoteaddr('::10:1', false), '0:0:0:0:0:0:10:1');
89 $this->assertEqual(cleanremoteaddr('01:1::', false), '1:1:0:0:0:0:0:0');
90 $this->assertEqual(cleanremoteaddr('10::10', false), '10:0:0:0:0:0:0:10');
91 $this->assertEqual(cleanremoteaddr('::ffff:192.168.1.1', true), '::ffff:c0a8:11');
92 }
93
7c9d46c9 94 function test_address_in_subnet() {
e70da470 95 /// 1: xxx.xxx.xxx.xxx/nn or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/nnn (number of bits in net mask)
96 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.1/32'));
97 $this->assertFalse(address_in_subnet('123.121.23.1', '123.121.23.0/32'));
98 $this->assertTrue(address_in_subnet('10.10.10.100', '123.121.23.45/0'));
99 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.0/24'));
100 $this->assertFalse(address_in_subnet('123.121.34.1', '123.121.234.0/24'));
101 $this->assertTrue(address_in_subnet('123.121.234.1', '123.121.234.0/30'));
102 $this->assertFalse(address_in_subnet('123.121.23.8', '123.121.23.0/30'));
103 $this->assertTrue(address_in_subnet('baba:baba::baba', 'baba:baba::baba/128'));
104 $this->assertFalse(address_in_subnet('bab:baba::baba', 'bab:baba::cece/128'));
105 $this->assertTrue(address_in_subnet('baba:baba::baba', 'cece:cece::cece/0'));
106 $this->assertTrue(address_in_subnet('baba:baba::baba', 'baba:baba::baba/128'));
107 $this->assertTrue(address_in_subnet('baba:baba::00ba', 'baba:baba::/120'));
108 $this->assertFalse(address_in_subnet('baba:baba::aba', 'baba:baba::/120'));
109 $this->assertTrue(address_in_subnet('baba::baba:00ba', 'baba::baba:0/112'));
110 $this->assertFalse(address_in_subnet('baba::aba:00ba', 'baba::baba:0/112'));
111 $this->assertFalse(address_in_subnet('aba::baba:0000', 'baba::baba:0/112'));
112
113 // fixed input
114 $this->assertTrue(address_in_subnet('123.121.23.1 ', ' 123.121.23.0 / 24'));
115 $this->assertTrue(address_in_subnet('::ffff:10.1.1.1', ' 0:0:0:000:0:ffff:a1:10 / 126'));
116
117 // incorrect input
118 $this->assertFalse(address_in_subnet('123.121.234.1', '123.121.234.1/-2'));
119 $this->assertFalse(address_in_subnet('123.121.234.1', '123.121.234.1/64'));
120 $this->assertFalse(address_in_subnet('123.121.234.x', '123.121.234.1/24'));
121 $this->assertFalse(address_in_subnet('123.121.234.0', '123.121.234.xx/24'));
122 $this->assertFalse(address_in_subnet('123.121.234.1', '123.121.234.1/xx0'));
123 $this->assertFalse(address_in_subnet('::1', '::aa:0/xx0'));
124 $this->assertFalse(address_in_subnet('::1', '::aa:0/-5'));
125 $this->assertFalse(address_in_subnet('::1', '::aa:0/130'));
126 $this->assertFalse(address_in_subnet('x:1', '::aa:0/130'));
127 $this->assertFalse(address_in_subnet('::1', '::ax:0/130'));
128
129
130 /// 2: xxx.xxx.xxx.xxx-yyy or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::xxxx-yyyy (a range of IP addresses in the last group)
131 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121.234.12-14'));
132 $this->assertTrue(address_in_subnet('123.121.234.13', '123.121.234.12-14'));
133 $this->assertTrue(address_in_subnet('123.121.234.14', '123.121.234.12-14'));
134 $this->assertFalse(address_in_subnet('123.121.234.1', '123.121.234.12-14'));
135 $this->assertFalse(address_in_subnet('123.121.234.20', '123.121.234.12-14'));
136 $this->assertFalse(address_in_subnet('123.121.23.12', '123.121.234.12-14'));
137 $this->assertFalse(address_in_subnet('123.12.234.12', '123.121.234.12-14'));
138 $this->assertTrue(address_in_subnet('baba:baba::baba', 'baba:baba::baba-babe'));
139 $this->assertTrue(address_in_subnet('baba:baba::babc', 'baba:baba::baba-babe'));
140 $this->assertTrue(address_in_subnet('baba:baba::babe', 'baba:baba::baba-babe'));
141 $this->assertFalse(address_in_subnet('bab:baba::bab0', 'bab:baba::baba-babe'));
142 $this->assertFalse(address_in_subnet('bab:baba::babf', 'bab:baba::baba-babe'));
143 $this->assertFalse(address_in_subnet('bab:baba::bfbe', 'bab:baba::baba-babe'));
144 $this->assertFalse(address_in_subnet('bfb:baba::babe', 'bab:baba::baba-babe'));
145
146 // fixed input
147 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121.234.12 - 14 '));
148 $this->assertTrue(address_in_subnet('bab:baba::babe', 'bab:baba::baba - babe '));
149
150 // incorrect input
151 $this->assertFalse(address_in_subnet('123.121.234.12', '123.121.234.12-234.14'));
152 $this->assertFalse(address_in_subnet('123.121.234.12', '123.121.234.12-256'));
153 $this->assertFalse(address_in_subnet('123.121.234.12', '123.121.234.12--256'));
154
155
156 /// 3: xxx.xxx or xxx.xxx. or xxx:xxx:xxxx or xxx:xxx:xxxx. (incomplete address, a bit non-technical ;-)
157 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121.234.12'));
158 $this->assertFalse(address_in_subnet('123.121.23.12', '123.121.23.13'));
159 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121.234.'));
160 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121.234'));
161 $this->assertTrue(address_in_subnet('123.121.234.12', '123.121'));
162 $this->assertTrue(address_in_subnet('123.121.234.12', '123'));
163 $this->assertFalse(address_in_subnet('123.121.234.1', '12.121.234.'));
164 $this->assertFalse(address_in_subnet('123.121.234.1', '12.121.234'));
165 $this->assertTrue(address_in_subnet('baba:baba::bab', 'baba:baba::bab'));
166 $this->assertFalse(address_in_subnet('baba:baba::ba', 'baba:baba::bc'));
167 $this->assertTrue(address_in_subnet('baba:baba::bab', 'baba:baba'));
168 $this->assertTrue(address_in_subnet('baba:baba::bab', 'baba:'));
169 $this->assertFalse(address_in_subnet('bab:baba::bab', 'baba:'));
170
171
172 /// multiple subnets
173 $this->assertTrue(address_in_subnet('123.121.234.12', '::1/64, 124., 123.121.234.10-30'));
174 $this->assertTrue(address_in_subnet('124.121.234.12', '::1/64, 124., 123.121.234.10-30'));
175 $this->assertTrue(address_in_subnet('::2', '::1/64, 124., 123.121.234.10-30'));
176 $this->assertFalse(address_in_subnet('12.121.234.12', '::1/64, 124., 123.121.234.10-30'));
177
178
179 /// other incorrect input
180 $this->assertFalse(address_in_subnet('123.123.123.123', ''));
7c9d46c9 181 }
b9c639d6 182
239c1576 183 /**
b9c639d6 184 * Modifies $_SERVER['HTTP_USER_AGENT'] manually to check if check_browser_version
239c1576 185 * works as expected.
186 */
187 function test_check_browser_version()
188 {
a205dcdc 189 global $CFG;
b9c639d6 190
191 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
239c1576 192 $this->assertTrue(check_browser_version('Safari', '312'));
193 $this->assertFalse(check_browser_version('Safari', '500'));
b9c639d6 194
a205dcdc 195 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
239c1576 196 $this->assertTrue(check_browser_version('Opera', '8.0'));
197 $this->assertFalse(check_browser_version('Opera', '10.0'));
b9c639d6 198
a205dcdc 199 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2'];
239c1576 200 $this->assertTrue(check_browser_version('MSIE', '5.0'));
201 $this->assertFalse(check_browser_version('MSIE', '7.0'));
b9c639d6 202
a205dcdc 203 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
239c1576 204 $this->assertTrue(check_browser_version('Firefox', '1.5'));
b9c639d6 205 $this->assertFalse(check_browser_version('Firefox', '3.0'));
d499142e 206 }
b9c639d6 207
ec012320 208 function test_get_browser_version_classes() {
209 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
89fbdca3 210 $this->assertEqual(array('safari'), get_browser_version_classes());
ec012320 211
212 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
89fbdca3 213 $this->assertEqual(array('opera'), get_browser_version_classes());
ec012320 214
215 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2'];
89fbdca3 216 $this->assertEqual(array('ie', 'ie6'), get_browser_version_classes());
ec012320 217
218 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2'];
89fbdca3 219 $this->assertEqual(array('ie', 'ie7'), get_browser_version_classes());
ec012320 220
221 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['8.0']['Windows Vista'];
89fbdca3 222 $this->assertEqual(array('ie', 'ie8'), get_browser_version_classes());
ec012320 223
224 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
89fbdca3 225 $this->assertEqual(array('gecko', 'gecko18'), get_browser_version_classes());
ec012320 226
227 $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['3.0.6']['SUSE'];
89fbdca3 228 $this->assertEqual(array('gecko', 'gecko19'), get_browser_version_classes());
ec012320 229 }
230
a3f7cbf6 231 function test_optional_param() {
b9c639d6 232 $_POST['username'] = 'post_user';
facb512c 233 $_GET['username'] = 'get_user';
622365d2 234 $this->assertEqual(optional_param('username', 'default_user', PARAM_CLEAN), 'post_user');
b9c639d6 235
facb512c 236 unset($_POST['username']);
622365d2 237 $this->assertEqual(optional_param('username', 'default_user', PARAM_CLEAN), 'get_user');
b9c639d6 238
facb512c 239 unset($_GET['username']);
622365d2 240 $this->assertEqual(optional_param('username', 'default_user', PARAM_CLEAN), 'default_user');
facb512c 241 }
b9c639d6 242
facb512c 243 /**
244 * Used by {@link optional_param()} and {@link required_param()} to
245 * clean the variables and/or cast to specific types, based on
246 * an options field.
247 * <code>
248 * $course->format = clean_param($course->format, PARAM_ALPHA);
249 * $selectedgrade_item = clean_param($selectedgrade_item, PARAM_CLEAN);
250 * </code>
251 *
252 * @uses $CFG
253 * @uses PARAM_CLEAN
254 * @uses PARAM_INT
255 * @uses PARAM_INTEGER
256 * @uses PARAM_ALPHA
257 * @uses PARAM_ALPHANUM
258 * @uses PARAM_NOTAGS
259 * @uses PARAM_ALPHAEXT
260 * @uses PARAM_BOOL
261 * @uses PARAM_SAFEDIR
facb512c 262 * @uses PARAM_FILE
263 * @uses PARAM_PATH
264 * @uses PARAM_HOST
265 * @uses PARAM_URL
266 * @uses PARAM_LOCALURL
267 * @uses PARAM_CLEANHTML
268 * @uses PARAM_SEQUENCE
269 * @param mixed $param the variable we are cleaning
270 * @param int $type expected format of param after cleaning.
271 * @return mixed
272 */
a3f7cbf6 273 function test_clean_param() {
c7fd861b 274 global $CFG;
facb512c 275 // Test unknown parameter type
b9c639d6 276
facb512c 277 // Test Raw param
b9c639d6 278 $this->assertEqual(clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_RAW),
facb512c 279 '#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)');
b9c639d6 280
281 $this->assertEqual(clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_CLEAN),
65de6864 282 '#()*#,9789\'".,');
c7fd861b 283
284 // Test PARAM_URL and PARAM_LOCALURL a bit
285 $this->assertEqual(clean_param('http://google.com/', PARAM_URL), 'http://google.com/');
286 $this->assertEqual(clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_URL), 'http://some.very.long.and.silly.domain/with/a/path/');
287 $this->assertEqual(clean_param('http://localhost/', PARAM_URL), 'http://localhost/');
288 $this->assertEqual(clean_param('http://0.255.1.1/numericip.php', PARAM_URL), 'http://0.255.1.1/numericip.php');
289 $this->assertEqual(clean_param('/just/a/path', PARAM_URL), '/just/a/path');
290 $this->assertEqual(clean_param('funny:thing', PARAM_URL), '');
291
292 $this->assertEqual(clean_param('http://google.com/', PARAM_LOCALURL), '');
293 $this->assertEqual(clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_LOCALURL), '');
294 $this->assertEqual(clean_param($CFG->wwwroot, PARAM_LOCALURL), $CFG->wwwroot);
295 $this->assertEqual(clean_param('/just/a/path', PARAM_LOCALURL), '/just/a/path');
296 $this->assertEqual(clean_param('funny:thing', PARAM_LOCALURL), '');
4bea5e85 297 $this->assertEqual(clean_param('course/view.php?id=3', PARAM_LOCALURL), 'course/view.php?id=3');
facb512c 298 }
56a1a882 299
a3f7cbf6 300 function test_validate_param() {
301 try {
302 $param = validate_param('11a', PARAM_INT);
303 $this->fail('invalid_parameter_exception expected');
304 } catch (invalid_parameter_exception $ex) {
305 $this->assertTrue(true);
306 }
307 try {
308 $param = validate_param('11', PARAM_INT);
309 $this->assertEqual($param, 11);
310 } catch (invalid_parameter_exception $ex) {
311 $this->fail('invalid_parameter_exception not expected');
312 }
313 try {
314 $param = validate_param(null, PARAM_INT, false);
315 $this->fail('invalid_parameter_exception expected');
316 } catch (invalid_parameter_exception $ex) {
317 $this->assertTrue(true);
318 }
319 try {
320 $param = validate_param(null, PARAM_INT, true);
321 $this->assertTrue($param===null);
322 } catch (invalid_parameter_exception $ex) {
323 $this->fail('invalid_parameter_exception expected');
324 }
325 try {
326 $param = validate_param(array(), PARAM_INT);
327 $this->fail('invalid_parameter_exception expected');
328 } catch (invalid_parameter_exception $ex) {
329 $this->assertTrue(true);
330 }
331 try {
332 $param = validate_param(new stdClass, PARAM_INT);
333 $this->fail('invalid_parameter_exception expected');
334 } catch (invalid_parameter_exception $ex) {
335 $this->assertTrue(true);
336 }
337 }
338
56a1a882 339 function test_make_user_directory() {
340 global $CFG;
341
342 // Test success conditions
343 $this->assertEqual("$CFG->dataroot/user/0/0", make_user_directory(0, true));
344 $this->assertEqual("$CFG->dataroot/user/0/1", make_user_directory(1, true));
345 $this->assertEqual("$CFG->dataroot/user/0/999", make_user_directory(999, true));
346 $this->assertEqual("$CFG->dataroot/user/1000/1000", make_user_directory(1000, true));
347 $this->assertEqual("$CFG->dataroot/user/2147483000/2147483647", make_user_directory(2147483647, true)); // Largest int possible
348
349 // Test fail conditions
350 $this->assertFalse(make_user_directory(2147483648, true)); // outside int boundary
351 $this->assertFalse(make_user_directory(-1, true));
352 $this->assertFalse(make_user_directory('string', true));
353 $this->assertFalse(make_user_directory(false, true));
354 $this->assertFalse(make_user_directory(true, true));
b9c639d6 355
56a1a882 356 }
9467db39 357
358 function test_shorten_text() {
359 $text = "short text already no tags";
360 $this->assertEqual($text, shorten_text($text));
361
362 $text = "<p>short <b>text</b> already</p><p>with tags</p>";
363 $this->assertEqual($text, shorten_text($text));
364
365 $text = "long text without any tags blah de blah blah blah what";
366 $this->assertEqual('long text without any tags ...', shorten_text($text));
367
368 $text = "<div class='frog'><p><blockquote>Long text with tags that will ".
369 "be chopped off but <b>should be added back again</b></blockquote></p></div>";
370 $this->assertEqual("<div class='frog'><p><blockquote>Long text with " .
371 "tags that ...</blockquote></p></div>", shorten_text($text));
372
373 $text = "some text which shouldn't &nbsp; break there";
8926f844 374 $this->assertEqual("some text which shouldn't &nbsp; ...",
9467db39 375 shorten_text($text, 31));
8926f844 376 $this->assertEqual("some text which shouldn't ...",
9467db39 377 shorten_text($text, 30));
8926f844 378
9467db39 379 // This case caused a bug up to 1.9.5
380 $text = "<h3>standard 'break-out' sub groups in TGs?</h3>&nbsp;&lt;&lt;There are several";
381 $this->assertEqual("<h3>standard 'break-out' sub groups in ...</h3>",
382 shorten_text($text, 43));
1fca8fa5
AD
383
384 $text = "<h1>123456789</h1>";//a string with no convenient breaks
385 $this->assertEqual("<h1>12345...</h1>",
386 shorten_text($text, 8));
9467db39 387 }
388
24d38a6e
AD
389 function test_usergetdate() {
390 $ts = 1261540267; //the time this function was created
391
392 $arr = usergetdate($ts,1);
393 $arr = array_values($arr);
394
395 list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
396 $this->assertEqual($seconds,7);
397 $this->assertEqual($minutes,51);
398 $this->assertEqual($hours,4);
399 $this->assertEqual($mday,23);
400 $this->assertEqual($wday,3);
401 $this->assertEqual($mon,12);
402 $this->assertEqual($year,2009);
403 $this->assertEqual($yday,357);
404 $this->assertEqual($weekday,'Wednesday');
405 $this->assertEqual($month,'December');
406
407 $arr = usergetdate($ts);
408 $arr = array_values($arr);
409
410 list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
411 $this->assertEqual($seconds,7);
412 $this->assertEqual($minutes,51);
413 $this->assertEqual($hours,11);
414 $this->assertEqual($mday,23);
415 $this->assertEqual($wday,3);
416 $this->assertEqual($mon,12);
417 $this->assertEqual($year,2009);
418 $this->assertEqual($yday,356);
419 $this->assertEqual($weekday,'Wednesday');
420 $this->assertEqual($month,'December');
421 }
7c9d46c9 422}