3
3
* $RCSfile: CharsetTest.class,v $
5
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2005 Bharat Mediratta
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
8
* This program is free software; you can redistribute it and/or modify
9
9
* it under the terms of the GNU General Public License as published by
20
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
23
* @version $Revision: 1.12 $ $Date: 2005/08/23 03:49:33 $
23
* @version $Revision: 1.15 $ $Date: 2006/03/02 01:09:33 $
24
24
* @package GalleryCore
25
25
* @subpackage PHPUnit
26
26
* @author Bharat Mediratta <bharat@menalto.com>
28
GalleryCoreApi::relativeRequireOnce('modules/core/classes/helpers/GalleryCharsetHelper_simple.class');
28
GalleryCoreApi::requireOnce('modules/core/classes/helpers/GalleryCharsetHelper_simple.class');
31
31
* Test character set helper
321
321
$gallery->_phpVm = $phpVm;
322
322
$this->assertEquals('Windows-1252', GalleryCharsetHelper_simple::detectSystemCharset());
324
/* Sometimes we just get French_France.1252 instead of LC_CTYPE=... */
325
GalleryDataCache::reset();
326
$phpVm->setReturn('setlocale', array(LC_ALL, '0'), 'German_Switzerland.1252');
327
$gallery->_phpVm = $phpVm;
328
$this->assertEquals('Windows-1252', GalleryCharsetHelper_simple::detectSystemCharset(),
324
331
GalleryDataCache::reset();
325
332
$phpVm->setReturn('setlocale', array(LC_ALL, '0'),
326
333
'LC_CTYPE=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=C');
327
334
$gallery->_phpVm = $phpVm;
328
335
$this->assertEquals('CP1251', GalleryCharsetHelper_simple::detectSystemCharset());
337
/* On windows boxes, we don't have the CODESET constant, so fake it */
338
if (!defined('CODESET')) {
339
define('CODESET', 'CODESET');
331
343
* Windows may return true for function_exists('nl_langinfo') and then print
332
344
* a warning message when the function is called:
345
357
GalleryCapabilities::set('systemCharset', null);
360
function testDetectSourceEncodingWithOpenBSDBug() {
361
/* nl_langinfo(CODESET) on OpenBSD 3.7 returns the wrong value (D_T_FMT value instead) */
364
/* On windows boxes, we don't have the CODESET constant, so fake it */
365
if (!defined('CODESET')) {
366
define('CODESET', 'CODESET');
368
if (!defined('D_T_FMT')) {
369
define('D_T_FMT', 'D_T_FMT');
372
$phpVm = new CharsetTestPhpVm();
373
$phpVm->setFunctionExists('nl_langinfo', true);
374
$phpVm->setReturn('nl_langinfo', array(CODESET), '%a %b %d %H:%M:%S %Y');
375
$phpVm->setReturn('nl_langinfo', array(D_T_FMT), '%a %b %d %H:%M:%S %Y');
376
$phpVm->setReturn('setlocale', array(LC_ALL, '0'),
377
'LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C');
378
$gallery->_phpVm = $phpVm;
379
$this->assertEquals('UTF-8', GalleryCharsetHelper_simple::detectSystemCharset());
348
382
function testConvertToUtf8SystemCharset() {
420
454
function setReturn($function, $args, $return) {
421
$this->_returns[$function] = array($args, $return);
455
$this->_returns[$function][implode(',', $args)] = $return;
424
458
function iconv($arg1, $arg2, $arg3) {
425
if ($this->_returns['iconv'][0] == array($arg1, $arg2, $arg3)) {
426
return $this->_returns['iconv'][1];
459
if (isset($this->_returns['iconv']["$arg1,$arg2,$arg3"])) {
460
return $this->_returns['iconv']["$arg1,$arg2,$arg3"];
431
465
function mb_convert_encoding($arg1, $arg2, $arg3) {
432
if ($this->_returns['mb_convert_encoding'][0] == array($arg1, $arg2, $arg3)) {
433
return $this->_returns['mb_convert_encoding'][1];
466
if (isset($this->_returns['mb_convert_encoding']["$arg1,$arg2,$arg3"])) {
467
return $this->_returns['mb_convert_encoding']["$arg1,$arg2,$arg3"];
437
471
function recode_string($arg1, $arg2) {
438
if ($this->_returns['recode_string'][0] == array($arg1, $arg2)) {
439
return $this->_returns['recode_string'][1];
472
if (isset($this->_returns['recode_string']["$arg1,$arg2"])) {
473
return $this->_returns['recode_string']["$arg1,$arg2"];
443
477
function nl_langinfo($item) {
444
if ($this->_returns['nl_langinfo'][0] == array($item)) {
445
return $this->_returns['nl_langinfo'][1];
478
if (isset($this->_returns['nl_langinfo'][$item])) {
479
return $this->_returns['nl_langinfo'][$item];
449
483
function setlocale($category, $locale) {
450
if ($this->_returns['setlocale'][0] == array($category, $locale)) {
451
return $this->_returns['setlocale'][1];
484
if (isset($this->_returns['setlocale']["$category,$locale"])) {
485
return $this->_returns['setlocale']["$category,$locale"];