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

« back to all changes in this revision

Viewing changes to modules/shutterfly/test/phpunit/ShutterflyCartPluginTest.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: ShutterflyCartPluginTest.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.3 $ $Date: 2005/08/23 03:49:54 $
 
23
 * @version $Revision: 1.6 $ $Date: 2006/01/10 04:42:36 $
24
24
 * @package Shutterfly
25
25
 * @subpackage PHPUnit
26
26
 * @author Alan Harder <alan.harder@sun.com>
44
44
 
45
45
        /* Create some random photo items that we can print */
46
46
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
47
 
        if ($ret->isError()) {
 
47
        if ($ret) {
48
48
            print $ret->getAsHtml();
49
49
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
50
50
        }
51
51
        $this->_markForCleanup($this->_album);
52
52
 
 
53
        $ret = GalleryCoreApi::removeItemPermissions($this->_album->getId());
 
54
        if ($ret) {
 
55
            print $ret->getAsHtml();
 
56
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
57
        }
 
58
        $ret = GalleryCoreApi::addUserPermission(
 
59
            $this->_album->getId(), $gallery->getActiveUserId(), 'core.all');
 
60
        if ($ret) {
 
61
            print $ret->getAsHtml();
 
62
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
63
        }
 
64
 
53
65
        for ($i = 0; $i < 3; $i++) {
54
66
            list ($ret, $this->_items[$i]) =
55
67
                $this->_createRandomDataItem($this->_album->getId(),
57
69
                                             array(),
58
70
                                             __FILE__,
59
71
                                             'GalleryPhotoItem');
60
 
            if ($ret->isError()) {
 
72
            if ($ret) {
61
73
                print $ret->getAsHtml();
62
74
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
63
75
            }
64
76
        }
 
77
 
 
78
        /* Print permission on all but one */
 
79
        $ret = GalleryCoreApi::removeUserPermission(
 
80
            $this->_items[1]->getId(), $gallery->getActiveUserId(), 'shutterfly.print');
 
81
        if ($ret) {
 
82
            print $ret->getAsHtml();
 
83
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
84
        }
 
85
        /* Public view permission on one */
 
86
        list ($ret, $anonymousUserId) =
 
87
            GalleryCoreApi::getPluginParameter('module', 'core', 'id.anonymousUser');
 
88
        if ($ret) {
 
89
            print $ret->getAsHtml();
 
90
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
91
        }
 
92
        $ret = GalleryCoreApi::addUserPermission(
 
93
            $this->_items[2]->getId(), $anonymousUserId, 'core.viewAll');
 
94
        if ($ret) {
 
95
            print $ret->getAsHtml();
 
96
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
97
        }
65
98
    }
66
99
 
67
100
    function testFulfillCart() {
72
105
            $cartItemIds[$this->_items[$i]->getId()] = $i+1;
73
106
        }
74
107
 
75
 
        GalleryCoreApi::relativeRequireOnce('modules/cart/classes/CartPluginInterface_1_0.class');
76
 
        GalleryCoreApi::relativeRequireOnce(
 
108
        GalleryCoreApi::requireOnce('modules/cart/classes/CartPluginInterface_1_0.class');
 
109
        GalleryCoreApi::requireOnce(
77
110
            'modules/shutterfly/classes/ShutterflyCartPlugin.class');
78
111
        $cartPlugin = new ShutterflyCartPlugin();
79
112
        list ($ret, $urlParams) = $cartPlugin->fulfillCart($cartItemIds);
80
 
        if ($ret->isError()) {
 
113
        if ($ret) {
81
114
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
82
115
        }
83
116
        $this->assertEquals(array('view' => 'shutterfly.PrintPhotos', 'return' => 1), $urlParams);
85
118
        $session =& $gallery->getSession();
86
119
        $printCart = $session->get('shutterfly.cart');
87
120
        $this->assertEquals($cartItemIds, $printCart, 'cart');
 
121
 
 
122
        /* Render PrintPhotos view to test processing of cart items */
 
123
        list ($ret, $view) = GalleryView::loadView('shutterfly.PrintPhotos');
 
124
        if ($ret) {
 
125
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
126
        } else {
 
127
            GalleryUtilities::putRequestVariable('return', '/testUrl');
 
128
            ob_start();
 
129
            $view->renderImmediate(array(), array());
 
130
            $form = ob_get_contents();
 
131
            ob_end_clean();
 
132
            $this->assert(strpos($form, '"returl" value="/testUrl"'), 'return url');
 
133
            $this->assert(strpos($form, '"imnum" value="4"'),
 
134
                'form should include 4 photos: qty 1 of item 0, none of item 1 ' .
 
135
                '(no print permission), qty 3 of item 2');
 
136
            preg_match_all('/' . GalleryUtilities::prefixFormVariable($session->getKey()) .
 
137
                '=([A-Za-z0-9]+)/', $form, $matches);
 
138
            /* Only first photo should add sessionid; the other is viewable to guests */
 
139
            $this->assert(!empty($matches[1]), 'missing sessionid for shutterfly access');
 
140
            $this->assert(1, count($matches[1]), 'number of urls with sessionid');
 
141
            $this->assert($matches[1][0] != $session->getId(), 'wrong sessionid in form');
 
142
        }
 
143
 
 
144
        $printCart = $session->get('shutterfly.cart');
 
145
        $this->assertEquals(null, $printCart, 'cart');
 
146
 
 
147
        /* Clean up */
88
148
        $session->remove('shutterfly.cart');
 
149
        if (!empty($matches[1]) && $matches[1][0] != $session->getId()) {
 
150
            $testSession = new GallerySession();
 
151
            $testSession->_sessionId = $matches[1][0];
 
152
            $testSession->reset();
 
153
        }
89
154
    }
90
155
}
91
156
?>