~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/RepositoryTestStorage.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
 
/**
22
 
 * Test storage class used for testing functions that interact with the database.
23
 
 * Only the features required for testing the repository code are implemented.
24
 
 * @package GalleryCore
25
 
 * @subpackage PHPUnit
26
 
 * @author Jozef Selesi <selesi at gmail dot com>
27
 
 * @version $Revision: 15513 $
28
 
 */
29
 
class RepositoryTestStorage {
30
 
 
31
 
    var $_addedMapData;
32
 
    var $_updatedMapData;
33
 
    var $_searchResults;
34
 
    var $_searches;
35
 
    var $_removedMapData;
36
 
 
37
 
    function &getSingleton() {
38
 
        static $singleton;
39
 
        if (!isset($singleton)) {
40
 
            $singleton = new RepositoryTestStorage();
41
 
        }
42
 
 
43
 
        return $singleton;
44
 
    }
45
 
 
46
 
    function reset() {
47
 
        $singleton =& $this->getSingleton();
48
 
        $singleton->_searches = array();
49
 
        $singleton->_searchResults = array();
50
 
        $singleton->_addedMapData = array();
51
 
        $singleton->_updatedMapData = array();
52
 
        $singleton->_removedMapData = array();
53
 
    }
54
 
 
55
 
    function search($query, $args) {
56
 
        $singleton =& $this->getSingleton();
57
 
        $singleton->_searches[] = array('query' => $query, 'arguments' => $args);
58
 
 
59
 
        return array(null,
60
 
                     new RepositoryTestSearchResults($singleton->_searchResults));
61
 
    }
62
 
 
63
 
    function setSearchResults($results) {
64
 
        $singleton =& $this->getSingleton();
65
 
        $singleton->_searchResults = $results;
66
 
    }
67
 
 
68
 
    function getSearches() {
69
 
        $singleton =& $this->getSingleton();
70
 
        return $singleton->_searches;
71
 
    }
72
 
 
73
 
    function addMapEntry($map, $data) {
74
 
        $singleton =& $this->getSingleton();
75
 
        $singleton->_addedMapData[$map][] = $data;
76
 
        return null;
77
 
    }
78
 
 
79
 
    function getMapEntry($map, $data, $match) {
80
 
        $singleton =& $this->getSingleton();
81
 
        $singleton->_searches[] = array('map' => $map, 'select' => $data, 'where' => $match);
82
 
 
83
 
        return array(null,
84
 
                     new RepositoryTestSearchResults($singleton->_searchResults));
85
 
    }
86
 
 
87
 
    function getAddedMapData() {
88
 
        $singleton =& $this->getSingleton();
89
 
        return $singleton->_addedMapData;
90
 
    }
91
 
 
92
 
    function updateMapEntry($map, $match, $change) {
93
 
        $singleton =& $this->getSingleton();
94
 
        $singleton->_updatedMapData[$map][] = array('match' => $match, 'change' => $change);
95
 
        return null;
96
 
    }
97
 
 
98
 
    function removeMapEntry($map, $match) {
99
 
        $singleton =& $this->getSingleton();
100
 
        $singleton->_removedMapData[$map][] = array('match' => $match);
101
 
        return null;
102
 
    }
103
 
 
104
 
    function getUpdatedMapData() {
105
 
        $singleton =& $this->getSingleton();
106
 
        return $singleton->_updatedMapData;
107
 
    }
108
 
 
109
 
    function getRemovedMapData() {
110
 
        $singleton =& $this->getSingleton();
111
 
        return $singleton->_removedMapData;
112
 
    }
113
 
 
114
 
    function rollbackTransaction() {
115
 
    }
116
 
}
117
 
 
118
 
class RepositoryTestSearchResults {
119
 
 
120
 
    var $_results;
121
 
    var $_resultIndex;
122
 
 
123
 
    function RepositoryTestSearchResults($results) {
124
 
        $this->_results = $results;
125
 
        $this->_resultIndex = 0;
126
 
    }
127
 
 
128
 
    function resultCount() {
129
 
        return count($this->_results);
130
 
    }
131
 
 
132
 
    function nextResult() {
133
 
        $result = $this->_resultIndex < $this->resultCount() ? $this->_results[$this->_resultIndex]
134
 
                                                             : false;
135
 
        $this->_resultIndex++;
136
 
        return $result;
137
 
    }
138
 
}
139
 
?>