~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/migrate/test/phpunit/MigrateEventHandlerTest.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/migrate/classes/G1MigrateHelper.class');
22
 
 
23
 
/**
24
 
 * ConfirmImport controller tests
25
 
 * @package Migrate
26
 
 * @subpackage PHPUnit
27
 
 * @author Jay Rossiter <cryptographite@users.sf.net>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class MigrateEventHandlerTest extends GalleryControllerTestCase {
31
 
    var $_temporaryAlbumId;
32
 
 
33
 
    function MigrateEventHandlerTest($methodName) {
34
 
        $this->GalleryTestCase($methodName, 'migrate.ConfirmImport');
35
 
    }
36
 
 
37
 
    function setUp() {
38
 
        global $gallery;
39
 
 
40
 
        parent::setUp();
41
 
 
42
 
        list ($ret, $this->_temporaryAlbum) = $this->_createRandomAlbum($this->_getRootId());
43
 
        if ($ret) {
44
 
            print $ret->getAsHtml();
45
 
            return $this->failWithStatus($ret);
46
 
        }
47
 
 
48
 
        $this->_markForCleanup($this->_temporaryAlbum);
49
 
 
50
 
        $this->_temporaryAlbumId = $this->_temporaryAlbum->getId();
51
 
 
52
 
        list ($ret, $this->_mapCount) = G1MigrateHelper::fetchMapCount();
53
 
        if ($ret) {
54
 
            return $this->failWithStatus($ret);
55
 
        }
56
 
    }
57
 
 
58
 
    function tearDown() {
59
 
        global $gallery;
60
 
 
61
 
        list ($ret, $mapCount) = G1MigrateHelper::fetchMapCount();
62
 
        if ($ret) {
63
 
            return $this->failWithStatus($ret);
64
 
        }
65
 
        $this->assertEquals($this->_mapCount, $mapCount, 'Test altered number of map entries!');
66
 
 
67
 
        parent::tearDown();
68
 
    }
69
 
 
70
 
    function testMigrateDeleteEventHandler() {
71
 
        // Create random album
72
 
        list ($ret, $g1MapHandlerAlbum) = $this->_createRandomAlbum($this->_temporaryAlbumId);
73
 
        if ($ret) {
74
 
            return $this->failWithStatus($ret);
75
 
        }
76
 
 
77
 
        // Add map entry for $g1MapHandlerAlbum
78
 
        $ret = GalleryCoreApi::addMapEntry(
79
 
            'G1MigrateMap',
80
 
            array('itemId' => $g1MapHandlerAlbum->getId(),
81
 
                  'g1album' => $g1MapHandlerAlbum->getPathComponent(),
82
 
                  'g1item' => NULL));
83
 
        if ($ret) {
84
 
            return $this->failWithStatus($ret);
85
 
        }
86
 
 
87
 
        // Create random data item
88
 
        list ($ret, $g1MapHandlerItem) = $this->_createRandomDataItem($g1MapHandlerAlbum->getId());
89
 
        if ($ret) {
90
 
            return $this->failWithStatus($ret);
91
 
        }
92
 
 
93
 
        // Add map entry for $g1MapHandlerItem
94
 
        $ret = GalleryCoreApi::addMapEntry(
95
 
            'G1MigrateMap',
96
 
            array('itemId' => $g1MapHandlerItem->getId(),
97
 
                  'g1album' => $g1MapHandlerAlbum->getPathComponent(),
98
 
                  'g1item' => $g1MapHandlerItem->getPathComponent()));
99
 
        if ($ret) {
100
 
            return $this->failWithStatus($ret);
101
 
        }
102
 
 
103
 
        // Verify album mapping
104
 
        list ($ret, $mapping) =
105
 
            G1MigrateHelper::fetchMapping($g1MapHandlerAlbum->getPathComponent());
106
 
        if ($ret) {
107
 
            return $this->failWithStatus($ret);
108
 
        }
109
 
        $this->assertEquals($g1MapHandlerAlbum->getId(),
110
 
                            $mapping, 'G1MigrateMap does not match Album Id');
111
 
 
112
 
        // Verify item mapping
113
 
        list ($ret, $mapping) = G1MigrateHelper::fetchMapping(
114
 
            $g1MapHandlerAlbum->getPathComponent(), $g1MapHandlerItem->getPathComponent());
115
 
        if ($ret) {
116
 
            return $this->failWithStatus($ret);
117
 
        }
118
 
        $this->assertEquals($g1MapHandlerItem->getId(), $mapping,
119
 
                            'G1MigrateMap does not match Item Id');
120
 
 
121
 
        $event = GalleryCoreApi::newEvent('GalleryEntity::delete');
122
 
        $event->setEntity($g1MapHandlerItem);
123
 
        list ($ret) = MigrateModule::handleEvent($event);
124
 
        if ($ret) {
125
 
            return $this->failWithStatus($ret);
126
 
        }
127
 
 
128
 
        $event = GalleryCoreApi::newEvent('GalleryEntity::delete');
129
 
        $event->setEntity($g1MapHandlerAlbum);
130
 
        list ($ret) = MigrateModule::handleEvent($event);
131
 
        if ($ret) {
132
 
            return $this->failWithStatus($ret);
133
 
        }
134
 
 
135
 
        // Verify album mapping deleted
136
 
        list ($ret, $mapping) =
137
 
            G1MigrateHelper::fetchMapping($g1MapHandlerAlbum->getPathComponent());
138
 
        if ($ret) {
139
 
            return $this->failWithStatus($ret);
140
 
        }
141
 
        $this->assertEquals(NULL, $mapping, 'G1MigrateMap does not match Album Id');
142
 
 
143
 
        // Verify item mapping
144
 
        list ($ret, $mapping) = G1MigrateHelper::fetchMapping(
145
 
            $g1MapHandlerAlbum->getPathComponent(), $g1MapHandlerItem->getPathComponent());
146
 
        if ($ret) {
147
 
            return $this->failWithStatus($ret);
148
 
        }
149
 
        $this->assertEquals(NULL, $mapping, 'G1MigrateMap does not match Item Id');
150
 
    }
151
 
}
152
 
?>