~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/exif/test/phpunit/ExifExtractorTest.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 ExifExtractor functionality
23
 
 *
24
 
 * @package Exif
25
 
 * @subpackage PHPUnit
26
 
 * @author Alan Harder <alan.harder@sun.com>
27
 
 * @author Georg Rehfeld <rehfeld@georg-rehfeld.de>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class ExifExtractorTest extends GalleryTestCase {
31
 
 
32
 
    function ExifExtractorTest($methodName) {
33
 
        $this->GalleryTestCase($methodName);
34
 
    }
35
 
 
36
 
    /**
37
 
     * Create an album for testing
38
 
     */
39
 
    function setUp() {
40
 
        parent::setUp();
41
 
        global $gallery;
42
 
 
43
 
        /* Create a new subalbum and add some jpegs */
44
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
45
 
        if ($ret) {
46
 
            $this->failWithStatus($ret);
47
 
        }
48
 
 
49
 
        $this->_markForCleanup($this->_album);
50
 
 
51
 
        list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
52
 
        if ($ret) {
53
 
            $this->failWithStatus($ret);
54
 
        }
55
 
        $photoIds = array();
56
 
        $corePrefix = GalleryCoreApi::getPluginBaseDir('module', 'core');
57
 
        $exifPrefix = GalleryCoreApi::getPluginBaseDir('module', 'exif');
58
 
        $imagePaths = array($exifPrefix . 'modules/exif/test/data/CanonS30.small.jpg',
59
 
                            $corePrefix . 'modules/core/test/data/test2.gif',
60
 
                            $exifPrefix . 'modules/exif/test/data/CanonS30.small.jpg',
61
 
                            $exifPrefix . 'modules/exif/test/data/iptc-irfanview.jpg',
62
 
                            $corePrefix . 'modules/core/test/data/test1.jpg');
63
 
 
64
 
        for ($i = 0; $i < count($imagePaths); $i++) {
65
 
            list ($ret, $photoId) = $this->_addPhoto(
66
 
                  $this->_album->getId(), $imagePaths[$i], $i + 1);
67
 
            if ($ret) {
68
 
                $this->failWithStatus($ret);
69
 
            }
70
 
            $photoIds[] = $photoId;
71
 
        }
72
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
73
 
        if ($ret) {
74
 
            $this->failWithStatus($ret);
75
 
        }
76
 
 
77
 
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'exif');
78
 
        if ($ret || !isset($module)) {
79
 
            $this->failWithStatus($ret);
80
 
        }
81
 
        list ($ret, $exif) =
82
 
            GalleryCoreApi::newFactoryInstance('ExifInterface_1_0', 'ExifExtractor');
83
 
        if ($ret || !isset($exif)) {
84
 
            $this->failWithStatus($ret);
85
 
        }
86
 
 
87
 
        $this->_photoIds = $photoIds;
88
 
        $this->_exif = $exif;
89
 
    }
90
 
 
91
 
    function _addPhoto($parentId, $imagePath, $index) {
92
 
        list ($ret, $photo) =
93
 
            GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryPhotoItem');
94
 
        if ($ret) {
95
 
            return array($ret, null);
96
 
        }
97
 
        list ($ret, $mimeType) = GalleryCoreApi::getMimeType($imagePath);
98
 
        if ($ret) {
99
 
            return array($ret, null);
100
 
        }
101
 
        $ret = $photo->create($parentId, $imagePath, $mimeType,
102
 
                              'testitem_' . time() . substr($imagePath, -4));
103
 
        if ($ret) {
104
 
            return array($ret, null);
105
 
        }
106
 
        $photo->setTitle("Item #$index");
107
 
        $photo->setSummary("Summary $index");
108
 
        $photo->setDescription("Description $index");
109
 
        $ret = $photo->save();
110
 
        if ($ret) {
111
 
            return array($ret, null);
112
 
        }
113
 
        /* add thumbnail */
114
 
        list ($ret, $thumbId) = $this->_addDerivative($photo,
115
 
            'thumbnail', DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'thumbnail|150');
116
 
        if ($ret) {
117
 
            return array($ret, null);
118
 
        }
119
 
        return array(null, $photo->getId());
120
 
    }
121
 
 
122
 
    function _addDerivative($photo, $toolkitType,
123
 
                            $derivativeType, $derivativeOperation) {
124
 
        list ($ret, $toolkit, $outputMimeType) =
125
 
            GalleryCoreApi::getToolkitByOperation($photo->getMimeType(), $toolkitType);
126
 
        if ($ret || !isset($toolkit)) {
127
 
            return array($ret, null);
128
 
        }
129
 
        list ($ret, $derivative) =
130
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $photo->getEntityType());
131
 
        if ($ret) {
132
 
            return array($ret, null);
133
 
        }
134
 
        if (!isset($derivative)) {
135
 
            return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT), null);
136
 
        }
137
 
 
138
 
        $ret = $derivative->create($photo->getId(), $derivativeType);
139
 
        if ($ret) {
140
 
            return array($ret, null);
141
 
        }
142
 
        $derivative->setDerivativeSourceId($photo->getId());
143
 
        $derivative->setDerivativeOperations($derivativeOperation);
144
 
        $derivative->setMimeType($outputMimeType);
145
 
        $ret = $derivative->save();
146
 
        if ($ret) {
147
 
            return array($ret, null);
148
 
        }
149
 
        return array(null, $derivative->getId());
150
 
    }
151
 
 
152
 
    function testOneItemAllDataExif() {
153
 
        list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds[0]);
154
 
        $this->assert(!$ret && isset($data[$this->_photoIds[0]]));
155
 
        $this->assertEquals('1/60 sec',
156
 
            $data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
157
 
    }
158
 
 
159
 
    function testOneItemAllDataIptc() {
160
 
        list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds[3]);
161
 
        $this->assert(!$ret && isset($data[$this->_photoIds[3]]));
162
 
        $this->assertEquals('Caption: IPTC/Caption',
163
 
            $data[$this->_photoIds[3]]['IPTC/Caption']['value']);
164
 
    }
165
 
 
166
 
    function testMultiItemAllData() {
167
 
        list ($ret, $data) = $this->_exif->getMetaData(
168
 
            array($this->_photoIds[0], $this->_photoIds[2], $this->_photoIds[3]));
169
 
        $this->assert(!$ret && isset($data));
170
 
        $this->assertEquals(3, count($data), 'Data size');
171
 
        $this->assertEquals('1/60 sec',
172
 
            $data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
173
 
        $this->assertEquals(sprintf('%.2f mm', 21.31),
174
 
            $data[$this->_photoIds[2]]['FocalLength']['value']);
175
 
        $this->assertEquals('Caption: IPTC/Caption',
176
 
            $data[$this->_photoIds[3]]['IPTC/Caption']['value']);
177
 
    }
178
 
 
179
 
    function testMultiItemMixedTypeAllData() {
180
 
        list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds);
181
 
        $this->assert(!$ret && isset($data));
182
 
        $this->assertEquals(4, count($data), 'Data size');
183
 
        $this->assertEquals('1/60 sec',
184
 
            $data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
185
 
        $this->assertEquals(sprintf('%.2f mm', 21.31),
186
 
            $data[$this->_photoIds[2]]['FocalLength']['value']);
187
 
        $this->assertEquals('Caption: IPTC/Caption',
188
 
            $data[$this->_photoIds[3]]['IPTC/Caption']['value']);
189
 
    }
190
 
 
191
 
    function testMultiItemSomeData() {
192
 
        list ($ret, $data) = $this->_exif->getMetaData(
193
 
            $this->_photoIds, array('DateTime', 'ShutterSpeedValue', 'IPTC/Byline'));
194
 
        $this->assert(!$ret && isset($data));
195
 
        $this->assertEquals(4, count($data), 'Data size');
196
 
        $this->assertEquals('1/60 sec',
197
 
            $data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
198
 
        $this->assert(!isset($data[$this->_photoIds[2]]['FocalLength']));
199
 
        $this->assert(!isset($data[$this->_photoIds[2]]['IPTC/Byline']));
200
 
        $this->assertEquals('Byline: IPTC/Byline',
201
 
            $data[$this->_photoIds[3]]['IPTC/Byline']['value']);
202
 
        $this->assert(!isset($data[$this->_photoIds[3]]['FocalLength']));
203
 
    }
204
 
}
205
 
?>