3
3
* $RCSfile: ShutterflyCartPluginTest.class,v $
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
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.
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>
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()) {
48
48
print $ret->getAsHtml();
49
49
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
51
51
$this->_markForCleanup($this->_album);
53
$ret = GalleryCoreApi::removeItemPermissions($this->_album->getId());
55
print $ret->getAsHtml();
56
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
58
$ret = GalleryCoreApi::addUserPermission(
59
$this->_album->getId(), $gallery->getActiveUserId(), 'core.all');
61
print $ret->getAsHtml();
62
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
53
65
for ($i = 0; $i < 3; $i++) {
54
66
list ($ret, $this->_items[$i]) =
55
67
$this->_createRandomDataItem($this->_album->getId(),
59
71
'GalleryPhotoItem');
60
if ($ret->isError()) {
61
73
print $ret->getAsHtml();
62
74
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
78
/* Print permission on all but one */
79
$ret = GalleryCoreApi::removeUserPermission(
80
$this->_items[1]->getId(), $gallery->getActiveUserId(), 'shutterfly.print');
82
print $ret->getAsHtml();
83
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
85
/* Public view permission on one */
86
list ($ret, $anonymousUserId) =
87
GalleryCoreApi::getPluginParameter('module', 'core', 'id.anonymousUser');
89
print $ret->getAsHtml();
90
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
92
$ret = GalleryCoreApi::addUserPermission(
93
$this->_items[2]->getId(), $anonymousUserId, 'core.viewAll');
95
print $ret->getAsHtml();
96
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
67
100
function testFulfillCart() {
72
105
$cartItemIds[$this->_items[$i]->getId()] = $i+1;
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()) {
81
114
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
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');
122
/* Render PrintPhotos view to test processing of cart items */
123
list ($ret, $view) = GalleryView::loadView('shutterfly.PrintPhotos');
125
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
127
GalleryUtilities::putRequestVariable('return', '/testUrl');
129
$view->renderImmediate(array(), array());
130
$form = ob_get_contents();
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');
144
$printCart = $session->get('shutterfly.cart');
145
$this->assertEquals(null, $printCart, 'cart');
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();