~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/linkitem/test/phpunit/LinkItemOptionTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * $RCSfile: LinkItemOptionTest.class,v $
 
4
 *
 
5
 * Gallery - a web based photo album viewer and editor
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or (at
 
11
 * your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 
21
 */
 
22
/**
 
23
 * @version $Revision: 1.2 $ $Date: 2006/01/10 04:40:36 $
 
24
 * @package LinkItem
 
25
 * @subpackage PHPUnit
 
26
 * @author Alan Harder <alan.harder@sun.com>
 
27
 */
 
28
 
 
29
GalleryCoreApi::requireOnce('lib/tools/phpunit/ItemEditOptionTestCase.class');
 
30
 
 
31
/**
 
32
 * LinkItemOption tests
 
33
 * @package LinkItem
 
34
 * @subpackage PHPUnit
 
35
 */
 
36
class LinkItemOptionTest extends ItemEditOptionTestCase {
 
37
 
 
38
    function LinkItemOptionTest($methodName) {
 
39
        $this->ItemEditOptionTestCase($methodName, 'linkitem', 'LinkItemOption');
 
40
    }
 
41
 
 
42
    function setUp() {
 
43
        parent::setUp();
 
44
 
 
45
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
 
46
        if ($ret) {
 
47
            print $ret->getAsHtml();
 
48
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
49
        }
 
50
        $this->_markForCleanup($this->_album);
 
51
 
 
52
        list ($ret, $lockId) = GalleryCoreApi::acquireReadLock(array($this->_album->getId()));
 
53
        if ($ret) {
 
54
            print $ret->getAsHtml();
 
55
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
56
        }
 
57
 
 
58
        list ($ret, $this->_link) =
 
59
            GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryLinkItem');
 
60
        if ($ret) {
 
61
            print $ret->getAsHtml();
 
62
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
63
        }
 
64
        if (empty($this->_link)) {
 
65
            return $this->failWithStatus(
 
66
                GalleryCoreApi::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__));
 
67
        }
 
68
        $ret = $this->_link->create($this->_album->getId(), 'http://test.com/test.html');
 
69
        if ($ret) {
 
70
            print $ret->getAsHtml();
 
71
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
72
        }
 
73
        $ret = $this->_link->save();
 
74
        if ($ret) {
 
75
            print $ret->getAsHtml();
 
76
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
77
        }
 
78
 
 
79
        $ret = GalleryCoreApi::releaseLocks($lockId);
 
80
        if ($ret) {
 
81
            print $ret->getAsHtml();
 
82
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
83
        }
 
84
    }
 
85
 
 
86
    function testSetUrl() {
 
87
        $form = array('LinkItemOption' => array('link' => 'http://test.net/'));
 
88
 
 
89
        list ($error, $warning) = $this->_handleRequestAfterEdit($form, $this->_link);
 
90
        $this->assertEquals(array(), $error);
 
91
        $this->assertEquals(array(), $warning);
 
92
 
 
93
        list ($ret, $link) = $this->_link->refresh();
 
94
        if ($ret) {
 
95
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
96
        }
 
97
        $this->assertEquals('http://test.net/', $link->getLink());
 
98
    }
 
99
 
 
100
    function testMissingUrl() {
 
101
        $form = array('LinkItemOption' => array('link' => ''));
 
102
 
 
103
        list ($error, $warning) = $this->_handleRequestAfterEdit($form, $this->_link);
 
104
        $this->assertEquals(array('form[LinkItemOption][error][link][missing]'), $error);
 
105
        $this->assertEquals(array(), $warning);
 
106
    }
 
107
}
 
108
?>