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

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/EventTest.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:
3
3
 * $RCSfile: EventTest.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.10 $ $Date: 2005/08/23 03:49:33 $
 
23
 * @version $Revision: 1.12 $ $Date: 2006/01/13 18:34:03 $
24
24
 * @package GalleryCore
25
25
 * @subpackage PHPUnit
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
29
29
/**
30
30
 * Required classes
31
31
 */
32
 
GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryEventListener.class');
 
32
GalleryCoreApi::requireOnce('modules/core/classes/GalleryEventListener.class');
33
33
 
34
34
/**
35
35
 * Test Event functionality
52
52
        $event->setEntity("bogus entity");
53
53
        $event->setData('some data');
54
54
        list ($ret, $result) = GalleryCoreApi::postEvent($event);
55
 
        if ($ret->isError()) {
 
55
        if ($ret) {
56
56
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
57
57
        }
58
58
 
70
70
        $event->setEntity("bogus entity");
71
71
        $event->setData('send result');
72
72
        list ($ret, $result) = GalleryCoreApi::postEvent($event);
73
 
        if ($ret->isError()) {
 
73
        if ($ret) {
74
74
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
75
75
        }
76
76
 
77
77
        $this->assertEquals($event, $listener->getEvent());
78
78
        $this->assertEquals(array('result'), $result);
79
79
    }
 
80
 
 
81
    function testChangePermissions() {
 
82
        /* Verify that a GalleryEntity::save event handler can modify permissions of a new item */
 
83
        global $gallery;
 
84
 
 
85
        $listener = new EventTestEventListener($this);
 
86
        $this->_registerTestEventListener('GalleryEntity::save', $listener);
 
87
 
 
88
        list ($ret, $item) = $this->_createRandomDataItem($this->_getRootId());
 
89
        if ($ret) {
 
90
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
91
        }
 
92
        $this->_markForCleanup($item);
 
93
 
 
94
        $event = $listener->getEvent();
 
95
        $this->assertEquals('GalleryEntity::save', $event ? $event->getEventName() : 'unset');
 
96
 
 
97
        list ($ret, $permissions) = GalleryCoreApi::fetchAllPermissionsForItem($item->getId());
 
98
        if ($ret) {
 
99
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
100
        }
 
101
        $this->assertEquals(array(array('userId' => $gallery->getActiveUserId(),
 
102
                                        'permission' => 'core.delete')),
 
103
                            $permissions);
 
104
    }
80
105
}
81
106
 
82
107
/**
92
117
        $data = $event->getData();
93
118
        $result = ($data == 'send result') ? 'result' : null;
94
119
 
95
 
        return array(GalleryStatus::success(), $result);
 
120
        if ($event->getEventName() == 'GalleryEntity::save') {
 
121
            global $gallery;
 
122
            $item = $event->getEntity();
 
123
            $ret = GalleryCoreApi::removeItemPermissions($item->getId());
 
124
            if ($ret) {
 
125
                return array($ret->wrap(__FILE__, __LINE__), null);
 
126
            }
 
127
            $ret = GalleryCoreApi::addUserPermission(
 
128
                    $item->getId(), $gallery->getActiveUserId(), 'core.delete');
 
129
            if ($ret) {
 
130
                return array($ret->wrap(__FILE__, __LINE__), null);
 
131
            }
 
132
        }
 
133
 
 
134
        return array(null, $result);
96
135
    }
97
136
 
98
137
    function getEvent() {