~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/captcha/test/phpunit/CaptchaHelperTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or (at
9
 
 * your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful, but
12
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
19
 
 */
20
 
 
21
 
GalleryCoreApi::requireOnce('modules/captcha/classes/CaptchaHelper.class');
22
 
 
23
 
/**
24
 
 * Test Captcha Helper
25
 
 * @package Captcha
26
 
 * @subpackage PHPUnit
27
 
 * @author Bharat Mediratta <bharat@menalto.com>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class CaptchaHelperTest extends GalleryTestCase {
31
 
    function CaptchaHelperTest($methodName) {
32
 
        $this->GalleryTestCase($methodName);
33
 
    }
34
 
 
35
 
    function testTestRequiredGdFunctionsAllPresent() {
36
 
        global $gallery;
37
 
 
38
 
        $phpVm = new CaptchaHelperTestPhpVm();
39
 
        $phpVm->setFunctionExists('ImageCreateFromJPEG', true);
40
 
        $phpVm->setFunctionExists('ImageColorAllocate', true);
41
 
        $phpVm->setFunctionExists('ImageString', true);
42
 
        $phpVm->setFunctionExists('ImageJPEG', true);
43
 
        $phpVm->setFunctionExists('ImageDestroy', true);
44
 
        $phpVm->setFunctionExists('imagesx', true);
45
 
        $gallery->_phpVm = $phpVm;
46
 
 
47
 
        $report = CaptchaHelper::testRequiredGdFunctions();
48
 
        $this->assertEquals(array('success' => array('ImageCreateFromJPEG',
49
 
                                                     'ImageColorAllocate',
50
 
                                                     'ImageString',
51
 
                                                     'ImageJPEG',
52
 
                                                     'ImageDestroy',
53
 
                                                     'imagesx'),
54
 
                                  'fail' => array()),
55
 
                            $report);
56
 
    }
57
 
 
58
 
    function testTestRequiredGdFunctionsSomeMissing() {
59
 
        global $gallery;
60
 
 
61
 
        $phpVm = new CaptchaHelperTestPhpVm();
62
 
        $phpVm->setFunctionExists('ImageCreateFromJPEG', true);
63
 
        $phpVm->setFunctionExists('ImageColorAllocate', true);
64
 
        $phpVm->setFunctionExists('ImageString', false);
65
 
        $phpVm->setFunctionExists('ImageJPEG', true);
66
 
        $phpVm->setFunctionExists('ImageDestroy', true);
67
 
        $phpVm->setFunctionExists('imagesx', false);
68
 
        $gallery->_phpVm = $phpVm;
69
 
 
70
 
        $report = CaptchaHelper::testRequiredGdFunctions();
71
 
        $this->assertEquals(array('success' => array('ImageCreateFromJPEG',
72
 
                                                     'ImageColorAllocate',
73
 
                                                     'ImageJPEG',
74
 
                                                     'ImageDestroy'),
75
 
                                  'fail' => array('ImageString',
76
 
                                                  'imagesx')),
77
 
                            $report);
78
 
    }
79
 
 
80
 
    function testTestRequiredGdFunctionsAllMissing() {
81
 
        global $gallery;
82
 
        $phpVm = new CaptchaHelperTestPhpVm();
83
 
        $phpVm->setFunctionExists('ImageCreateFromJPEG', false);
84
 
        $phpVm->setFunctionExists('ImageColorAllocate', false);
85
 
        $phpVm->setFunctionExists('ImageString', false);
86
 
        $phpVm->setFunctionExists('ImageJPEG', false);
87
 
        $phpVm->setFunctionExists('ImageDestroy', false);
88
 
        $phpVm->setFunctionExists('imagesx', false);
89
 
        $gallery->_phpVm = $phpVm;
90
 
 
91
 
        $report = CaptchaHelper::testRequiredGdFunctions();
92
 
        $this->assertEquals(array('success' => array(),
93
 
                                  'fail' => array('ImageCreateFromJPEG',
94
 
                                                  'ImageColorAllocate',
95
 
                                                  'ImageString',
96
 
                                                  'ImageJPEG',
97
 
                                                  'ImageDestroy',
98
 
                                                  'imagesx')),
99
 
                            $report);
100
 
    }
101
 
}
102
 
 
103
 
class CaptchaHelperTestPhpVm {
104
 
    function setFunctionExists($functionName, $bool) {
105
 
        $this->_function_exists[$functionName] = $bool;
106
 
    }
107
 
 
108
 
    function function_exists($functionName) {
109
 
        return $this->_function_exists[$functionName];
110
 
    }
111
 
}
112
 
?>