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

« back to all changes in this revision

Viewing changes to modules/panorama/test/phpunit/PanoramaOptionTest.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/panorama/classes/PanoramaHelper.class');
22
 
GalleryCoreApi::requireOnce('modules/panorama/classes/PanoramaRenderer.class');
23
 
 
24
 
/**
25
 
 * PanoramaOption tests
26
 
 * Also tests PanoramaHelper::fetchViewableImages
27
 
 * @package Panorama
28
 
 * @subpackage PHPUnit
29
 
 * @author Alan Harder <alan.harder@sun.com>
30
 
 * @version $Revision: 15513 $
31
 
 */
32
 
class PanoramaOptionTest extends ItemEditOptionTestCase {
33
 
 
34
 
    function PanoramaOptionTest($methodName) {
35
 
        $this->ItemEditOptionTestCase($methodName, 'panorama', 'PanoramaOption');
36
 
    }
37
 
 
38
 
    function setUp() {
39
 
        parent::setUp();
40
 
 
41
 
        list ($ret, $this->_item) =
42
 
            $this->_createRandomDataItem($this->_getRootId(), 'image/test',
43
 
                    array('width' => 10000, 'height' => 100), __FILE__, 'GalleryPhotoItem');
44
 
        if ($ret) {
45
 
            print $ret->getAsHtml();
46
 
            return $this->failWithStatus($ret);
47
 
        }
48
 
        $this->_markForCleanup($this->_item);
49
 
 
50
 
        list ($ret, $this->_derivative) = $this->_createDerivative(
51
 
                $this->_item, $this->_item->getId(), DERIVATIVE_TYPE_IMAGE_PREFERRED,
52
 
                'test-operation|80', 'image/test', array('width' => 8000, 'height' => 80));
53
 
        if ($ret) {
54
 
            print $ret->getAsHtml();
55
 
            return $this->failWithStatus($ret);
56
 
        }
57
 
 
58
 
        $this->_renderer = new PanoramaRenderer();
59
 
    }
60
 
 
61
 
    function _makePanoramas() {
62
 
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($this->_item->getId());
63
 
        if ($ret) {
64
 
            return $this->failWithStatus($ret);
65
 
        }
66
 
 
67
 
        list ($ret, $this->_item) = $this->_item->refresh();
68
 
        if ($ret) {
69
 
            return $this->failWithStatus($ret);
70
 
        }
71
 
 
72
 
        $this->_item->setRenderer('PanoramaRenderer');
73
 
        $ret = $this->_item->save();
74
 
        if ($ret) {
75
 
            return $this->failWithStatus($ret);
76
 
        }
77
 
 
78
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
79
 
        if ($ret) {
80
 
            return $this->failWithStatus($ret);
81
 
        }
82
 
 
83
 
        return null;
84
 
    }
85
 
 
86
 
    function testPanoramaOn() {
87
 
        $form['PanoramaOption']['isPanorama'] = 1;
88
 
 
89
 
        $result = $this->_handleRequestAfterEdit($form, $this->_item);
90
 
        $this->assertEquals(array(array(), array()), $result);
91
 
 
92
 
        list ($ret, $item) = $this->_item->refresh();
93
 
        if ($ret) {
94
 
            return $this->failWithStatus($ret);
95
 
        }
96
 
        $this->assertEquals('PanoramaRenderer', $item->getRenderer());
97
 
    }
98
 
 
99
 
    function testPanoramaOff() {
100
 
        $ret = $this->_makePanoramas();
101
 
        if ($ret) {
102
 
            return $this->failWithStatus($ret);
103
 
        }
104
 
 
105
 
        $result = $this->_handleRequestAfterEdit(array(), $this->_item);
106
 
        $this->assertEquals(array(array(), array()), $result, 'controller results');
107
 
 
108
 
        list ($ret, $item) = $this->_item->refresh();
109
 
        if ($ret) {
110
 
            return $this->failWithStatus($ret);
111
 
        }
112
 
        /* For Oracle, null is replaced with '' when loading data from the database */
113
 
        $this->assert(in_array($item->getRenderer(), array(null, '')), 'renderer not empty');
114
 
    }
115
 
 
116
 
    function testHelper() {
117
 
        list ($ret, $images) = PanoramaHelper::fetchViewableImages(array($this->_item));
118
 
        if ($ret) {
119
 
            return $this->failWithStatus($ret);
120
 
        }
121
 
        $this->assert(isset($images[$this->_item->getId()]), 'Missing result');
122
 
        $this->assertEquals($this->_derivative->getId(),
123
 
                            $images[$this->_item->getId()]->getId(), 'Id');
124
 
    }
125
 
 
126
 
    function testRender() {
127
 
        /* Make sure we use full urls in applet parameters, and sessionid in image url */
128
 
        $ret = $this->_makePanoramas();
129
 
        if ($ret) {
130
 
            return $this->failWithStatus($ret);
131
 
        }
132
 
 
133
 
        $html = $this->_renderer->render('HTML', $this->_item, $this->_item, array());
134
 
        $this->assert(
135
 
            preg_match('{<param name="archive" value="http}', $html),
136
 
            'item: jar full url: ' . htmlentities($html));
137
 
        $this->assert(preg_match('{<param[^>]*name="ScrollerThumb"[^>]*value="http}', $html),
138
 
                      'item: slider full url: ' . htmlentities($html));
139
 
        $this->assert(preg_match('{<param[^>]*name="PanoramaTile"[^>]*value="http[^"]*'
140
 
                                 . SESSION_ID_PARAMETER . '}', $html),
141
 
                      'item: image full url: ' . htmlentities($html));
142
 
 
143
 
        $html = $this->_renderer->render('HTML', $this->_derivative, $this->_item, array());
144
 
        $this->assert(preg_match('{<param name="archive" value="http}', $html),
145
 
                      'deriv: jar full url: ' . htmlentities($html));
146
 
        $this->assert(preg_match('{<param[^>]*name="ScrollerThumb"[^>]*value="http}', $html),
147
 
                      'deriv: slider full url: ' . htmlentities($html));
148
 
        $this->assert(preg_match('{<param[^>]*name="PanoramaTile"[^>]*value="http[^"]*'
149
 
                                 . SESSION_ID_PARAMETER . '}', $html),
150
 
                      'deriv: image full url: ' . htmlentities($html));
151
 
 
152
 
        /* Accept forceRawImage parameter to bypass applet display */
153
 
        $html = $this->_renderer->render(
154
 
            'HTML', $this->_item, $this->_item, array('forceRawImage' => true));
155
 
        $this->assertEquals(null, $html, 'item: raw image');
156
 
 
157
 
        $html = $this->_renderer->render(
158
 
            'HTML', $this->_derivative, $this->_item, array('forceRawImage' => true));
159
 
        $this->assertEquals(null, $html, 'deriv: raw image');
160
 
    }
161
 
}
162
 
?>