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

« back to all changes in this revision

Viewing changes to modules/thumbpage/test/phpunit/ThumbPageItemEditPluginTest.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
 
 * ItemEditThumbPage controller tests
23
 
 * @package ThumbPage
24
 
 * @subpackage PHPUnit
25
 
 * @author Alan Harder <alan.harder@sun.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class ThumbPageItemEditPluginTest extends ItemEditPluginTestCase {
29
 
 
30
 
    function ThumbPageItemEditPluginTest($methodName) {
31
 
        $this->ItemEditPluginTestCase($methodName, 'thumbpage', 'ItemEditThumbPage');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        parent::setUp();
36
 
 
37
 
        /* Register a dummy toolkit and property */
38
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
39
 
            'GalleryToolkit', 'ThumbPageTestToolkit', 'ThumbPageTestToolkit',
40
 
            'modules/thumbpage/test/phpunit/ThumbPageItemEditPluginTest.class',
41
 
            'thumbpageTest', null);
42
 
        if ($ret) {
43
 
            print $ret->getAsHtml();
44
 
            return $this->failWithStatus($ret);
45
 
        }
46
 
        $this->_markToolkitForCleanup('ThumbPageTestToolkit');
47
 
 
48
 
        $ret = GalleryCoreApi::registerToolkitProperty('ThumbPageTestToolkit',
49
 
            array('test/document'), 'page-count', 'int', 'desc');
50
 
        if ($ret) {
51
 
            print $ret->getAsHtml();
52
 
            return $this->failWithStatus($ret);
53
 
        }
54
 
 
55
 
        list ($ret, $this->_item) = $this->_createRandomDataItem(
56
 
            $this->_getRootId(), 'test/document', array(), __FILE__, 'GalleryPhotoItem');
57
 
        if ($ret) {
58
 
            print $ret->getAsHtml();
59
 
            return $this->failWithStatus($ret);
60
 
        }
61
 
 
62
 
        $this->_markForCleanup($this->_item);
63
 
 
64
 
        list ($ret, $this->_thumbnail) = $this->_createDerivative(
65
 
            $this->_item, $this->_item->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL);
66
 
        if ($ret) {
67
 
            print $ret->getAsHtml();
68
 
            return $this->failWithStatus($ret);
69
 
        }
70
 
    }
71
 
 
72
 
    function testReset() {
73
 
        GalleryUtilities::putRequestVariable('form[action][reset]', 1);
74
 
 
75
 
        $preferred = null;
76
 
        $results = $this->handleRequest($this->_item, $preferred);
77
 
        $this->assertEquals(array(array(), null), $results);
78
 
    }
79
 
 
80
 
    function testSave() {
81
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
82
 
        GalleryUtilities::putRequestVariable('form[page]', 2);
83
 
 
84
 
        $preferred = null;
85
 
        $results = $this->handleRequest($this->_item, $preferred);
86
 
        $this->assertEquals(array(array(), $this->_translate('Changes saved successfully')),
87
 
                            $results, 'page two result');
88
 
 
89
 
        list ($ret, $item) = $this->_thumbnail->refresh();
90
 
        if ($ret) {
91
 
            return $this->failWithStatus($ret);
92
 
        }
93
 
        $this->assertEquals('select-page|2;test-operation|100', $item->getDerivativeOperations(),
94
 
                            'page two');
95
 
 
96
 
        // Set back to page one, which removes select-page operation..
97
 
        GalleryUtilities::putRequestVariable('form[page]', 1);
98
 
 
99
 
        $results = $this->handleRequest($this->_item, $preferred);
100
 
        $this->assertEquals(array(array(), $this->_translate('Changes saved successfully')),
101
 
                            $results, 'page one result');
102
 
 
103
 
        list ($ret, $item) = $this->_thumbnail->refresh();
104
 
        if ($ret) {
105
 
            return $this->failWithStatus($ret);
106
 
        }
107
 
        $this->assertEquals('test-operation|100', $item->getDerivativeOperations(),
108
 
                            'page one');
109
 
    }
110
 
}
111
 
 
112
 
GalleryCoreApi::requireOnce('modules/core/classes/GalleryToolkit.class');
113
 
 
114
 
/**
115
 
 * Test toolkit
116
 
 * @package ThumbPage
117
 
 * @subpackage PHPUnit
118
 
 */
119
 
class ThumbPageTestToolkit extends GalleryToolkit {
120
 
    function getProperty($mimeType, $propertyName, $sourceFilename) {
121
 
        if ($propertyName != 'page-count') {
122
 
            return array(GalleryCoreApi::error(ERROR_UNSUPPORTED_OPERATION, __FILE__, __LINE__,
123
 
                                              "$propertyName $sourceFilename"), null);
124
 
        }
125
 
        return array(null, array(5));
126
 
    }
127
 
}
128
 
?>