~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/CharsetTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: CharsetTest.class,v $
4
4
 *
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
7
7
 *
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.
21
21
 */
22
22
/**
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>
27
27
 */
28
 
GalleryCoreApi::relativeRequireOnce('modules/core/classes/helpers/GalleryCharsetHelper_simple.class');
 
28
GalleryCoreApi::requireOnce('modules/core/classes/helpers/GalleryCharsetHelper_simple.class');
29
29
 
30
30
/**
31
31
 * Test character set helper
321
321
        $gallery->_phpVm = $phpVm;
322
322
        $this->assertEquals('Windows-1252', GalleryCharsetHelper_simple::detectSystemCharset());
323
323
 
 
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(),
 
329
                            'short format');
 
330
 
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());
329
 
 
 
336
        
 
337
        /* On windows boxes, we don't have the CODESET constant, so fake it */
 
338
        if (!defined('CODESET')) {
 
339
            define('CODESET', 'CODESET');
 
340
        }
 
341
        
330
342
        /*
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);
346
358
    }
347
359
 
 
360
    function testDetectSourceEncodingWithOpenBSDBug() {
 
361
        /* nl_langinfo(CODESET) on OpenBSD 3.7 returns the wrong value (D_T_FMT value instead) */
 
362
        global $gallery;
 
363
 
 
364
        /* On windows boxes, we don't have the CODESET constant, so fake it */
 
365
        if (!defined('CODESET')) {
 
366
            define('CODESET', 'CODESET');
 
367
        }
 
368
        if (!defined('D_T_FMT')) {
 
369
            define('D_T_FMT', 'D_T_FMT');
 
370
        }
 
371
 
 
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());
 
380
    }
 
381
 
348
382
    function testConvertToUtf8SystemCharset() {
349
383
        global $gallery;
350
384
 
418
452
    }
419
453
 
420
454
    function setReturn($function, $args, $return) {
421
 
        $this->_returns[$function] = array($args, $return);
 
455
        $this->_returns[$function][implode(',', $args)] = $return;
422
456
    }
423
457
 
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"];
427
461
        }
428
462
        return false;
429
463
    }
430
464
 
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"];
434
468
        }
435
469
    }
436
470
 
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"];
440
474
        }
441
475
    }
442
476
 
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];
446
480
        }
447
481
    }
448
482
 
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"];
452
486
        }
453
487
    }
454
488
}