3
* $RCSfile: RatingCallbacksTest.class,v $
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2006 Bharat Mediratta
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.
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.
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.
23
* @version $Revision: 1.3 $ $Date: 2006/01/11 20:12:01 $
26
* @author Don Seiler <don@seiler.us>
29
GalleryCoreApi::requireOnce('modules/core/classes/GallerySmarty.class');
30
GalleryCoreApi::requireOnce('modules/rating/Callbacks.inc');
33
* Rating callback tests
37
class RatingCallbacksTest extends GalleryTestCase {
39
function RatingCallbacksTest($methodName) {
40
$this->GalleryTestCase($methodName);
44
* Create an album for testing
50
$ret = $this->_markPluginParametersForCleanup('module', 'rating');
52
print $ret->getAsHtml();
53
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
56
$this->_userId = $gallery->getActiveUserId();
58
list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'rating');
59
if ($ret || !isset($this->_module)) {
60
print $ret->getAsHtml();
61
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
64
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
66
print $ret->getAsHtml();
67
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
69
$this->_markForCleanup($this->_album);
71
list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(),
72
'image/test', array(), __FILE__, 'GalleryPhotoItem');
74
print $ret->getAsHtml();
75
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
80
function testRatingBlocks() {
81
$smarty = new GallerySmarty();
82
$callbacks = new RatingCallbacks();
83
$ret = $callbacks->callback(array('itemId' => $this->_item->getId()),
84
$smarty, 'LoadRating', $this->_userId);
86
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
89
$data = $smarty->_tpl_vars['block']['rating']['RatingData'];
90
$summary = $smarty->_tpl_vars['block']['rating']['RatingSummary'];
91
$this->assertEquals(array('ratingValues' => array(1,2,3,4,5), 'firstCall' => true),
92
$summary, 'Rating summary array does not match.');
93
$this->assert(isset($data['rating']), 'Missing rating');
94
$this->assert(isset($data['userRating']), 'Missing userRating');
95
$this->assert(isset($data['stars']), 'Missing stars');
96
$this->assert(isset($data['userStars']), 'Missing userStars');
97
$this->assert(isset($data['votes']), 'Missing votes');
98
$this->assert(isset($data['averagePercent']), 'Missing average percent');
103
function testAllowAlbumRating() {
104
$ret = GalleryCoreApi::setPluginParameter('module', 'rating', 'allowAlbumRating', 1);
106
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
109
$smarty = new GallerySmarty();
110
$callbacks = new RatingCallbacks();
111
$ret = $callbacks->callback(array('itemId' => $this->_album->getId()),
112
$smarty, 'LoadRating', $this->_userId);
114
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
117
$data = $smarty->_tpl_vars['block']['rating']['RatingData'];
118
$summary = $smarty->_tpl_vars['block']['rating']['RatingSummary'];
119
$this->assertEquals(array('ratingValues' => array(1,2,3,4,5), 'firstCall' => true),
120
$summary, 'Rating summary array does not match.');
121
$this->assert(isset($data['rating']), 'Missing rating');
122
$this->assert(isset($data['userRating']), 'Missing userRating');
123
$this->assert(isset($data['stars']), 'Missing stars');
124
$this->assert(isset($data['userStars']), 'Missing userStars');
125
$this->assert(isset($data['votes']), 'Missing votes');
126
$this->assert(isset($data['averagePercent']), 'Missing average percent');
129
function testDoNotAllowAlbumRating() {
130
$ret = GalleryCoreApi::setPluginParameter('module', 'rating', 'allowAlbumRating', 0);
132
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
135
$smarty = new GallerySmarty();
136
$callbacks = new RatingCallbacks();
137
$ret = $callbacks->callback(array('itemId' => $this->_album->getId()),
138
$smarty, 'LoadRating', $this->_userId);
140
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
143
$this->assert(!isset($smarty->_tpl_vars['block']), 'Received rating block.');
146
function testRatingPermissionNone() {
147
$ret = GalleryCoreApi::removeItemPermissions($this->_item->getId());
149
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
151
$smarty = new GallerySmarty();
152
$callbacks = new RatingCallbacks();
153
$ret = $callbacks->callback(array('itemId' => $this->_item->getId()),
154
$smarty, 'LoadRating', $this->_userId);
156
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
159
$this->assert(!isset($smarty->_tpl_vars['block']), 'Received rating block.');
162
function testRatingPermissionViewOnly() {
163
$ret = GalleryCoreApi::removeItemPermissions($this->_item->getId());
165
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
167
$ret = GalleryCoreApi::addUserPermission(
168
$this->_item->getId(), $this->_userId, 'rating.view');
170
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
172
$smarty = new GallerySmarty();
173
$callbacks = new RatingCallbacks();
174
$ret = $callbacks->callback(array('itemId' => $this->_item->getId()),
175
$smarty, 'LoadRating', $this->_userId);
177
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
180
$data = $smarty->_tpl_vars['block']['rating']['RatingData'];
181
$summary = $smarty->_tpl_vars['block']['rating']['RatingSummary'];
182
$this->assertEquals(array('ratingValues' => array(1,2,3,4,5), 'firstCall' => true),
183
$summary, 'Rating summary array does not match.');
184
$this->assert(isset($data['rating']), 'Missing rating');
185
$this->assert(isset($data['userRating']), 'Missing userRating');
186
$this->assert(isset($data['stars']), 'Missing stars');
187
$this->assert(isset($data['userStars']), 'Missing userStars');
188
$this->assert(isset($data['votes']), 'Missing votes');
189
$this->assert(isset($data['averagePercent']), 'Missing average percent');
190
$this->assertEquals(false, $data['canRate'], 'canRate is true.');
193
function testRatingPermissionFull() {
194
$ret = GalleryCoreApi::removeItemPermissions($this->_item->getId());
196
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
198
$ret = GalleryCoreApi::addUserPermission(
199
$this->_item->getId(), $this->_userId, 'rating.view');
201
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
203
$ret = GalleryCoreApi::addUserPermission(
204
$this->_item->getId(), $this->_userId, 'rating.add');
206
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
208
$smarty = new GallerySmarty();
209
$callbacks = new RatingCallbacks();
210
$ret = $callbacks->callback(array('itemId' => $this->_item->getId()),
211
$smarty, 'LoadRating', $this->_userId);
213
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
216
$data = $smarty->_tpl_vars['block']['rating']['RatingData'];
217
$summary = $smarty->_tpl_vars['block']['rating']['RatingSummary'];
218
$this->assertEquals(array('ratingValues' => array(1,2,3,4,5), 'firstCall' => true),
219
$summary, 'Rating summary array does not match.');
220
$this->assert(isset($data['rating']), 'Missing rating');
221
$this->assert(isset($data['userRating']), 'Missing userRating');
222
$this->assert(isset($data['stars']), 'Missing stars');
223
$this->assert(isset($data['userStars']), 'Missing userStars');
224
$this->assert(isset($data['votes']), 'Missing votes');
225
$this->assert(isset($data['averagePercent']), 'Missing average percent');
226
$this->assertEquals(true, $data['canRate'], 'canRate is false.');