39
39
$this->GalleryTestCase($methodName);
50
list ($ret, $this->_item) = $this->_createRandomDataItem($this->_getRootId());
51
if ($ret->isError()) {
46
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
48
print $ret->getAsHtml();
52
49
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
51
$this->_markForCleanup($this->_album);
55
$this->_markForCleanup($this->_item);
53
list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId());
55
print $ret->getAsHtml();
56
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
57
59
/* Create a few comments */
58
60
for ($i = 0; $i < 3; $i++) {
59
61
list ($ret, $this->_comment[$i]) =
60
62
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryComment');
61
if ($ret->isError()) {
62
64
print $ret->getAsHtml();
63
65
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
91
93
function testFetchCommentCounts() {
92
list ($ret, $counts) = GalleryCommentHelper::fetchCommentCounts(array($this->_item->getId()));
93
if ($ret->isError()) {
94
list ($ret, $counts) =
95
GalleryCommentHelper::fetchCommentCounts(array($this->_item->getId()));
94
97
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
97
100
$this->assertEquals(3, $counts[$this->_item->getId()], 'Count is wrong');
103
function testFetchAllComments() {
105
list ($ret, $item2) = $this->_createRandomDataItem($this->_album->getId());
107
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
109
$ret = GalleryCoreApi::removeItemPermissions($item2->getId());
111
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
113
$ret = GalleryCoreApi::addUserPermission(
114
$item2->getId(), $gallery->getActiveUserId(), 'core.all');
116
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
118
list ($ret, $everybodyGroupId) =
119
GalleryCoreApi::getPluginParameter('module', 'core', 'id.everybodyGroup');
121
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
123
$ret = GalleryCoreApi::addGroupPermission(
124
$this->_item->getId(), $everybodyGroupId, 'comment.view');
126
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
129
list ($ret, $comment) =
130
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryComment');
132
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
134
$this->assert(isset($comment), 'Missing comment instance');
135
$comment->create($item2->getId());
136
$comment->setCommenterId($gallery->getActiveUserId());
137
$comment->setHost('127.0.0.1');
138
$comment->setComment('this is a test comment');
139
$comment->setDate(time()+5);
140
$ret = $comment->save();
142
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
145
list ($ret, $comments) = GalleryCommentHelper::fetchAllComments(
146
$this->_album->getId(), 3, null, ORDER_DESCENDING);
148
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
150
$this->assertEquals(array($comment, $this->_comment[2], $this->_comment[1]), $comments);
152
$this->_becomeGuestUser();
154
list ($ret, $comments) = GalleryCommentHelper::fetchAllComments($this->_album->getId());
156
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
158
$this->assertEquals(array($this->_comment[0], $this->_comment[1], $this->_comment[2]),
161
list ($ret, $comments) =
162
GalleryCommentHelper::fetchAllComments($this->_album->getId(), 2, 2, ORDER_DESCENDING);
164
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
166
$this->assertEquals(array($this->_comment[0]), $comments, 'guest/offset');
100
169
function testGetItemSummaries() {
101
170
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'comment');
102
if ($ret->isError()) {
103
172
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
105
174
$itemId = $this->_item->getId();
106
175
/* Verify we get a non empty item summary for the item */
107
176
$permissions[$itemId]['comment.view'] = 1;
108
177
list ($ret, $content) = $module->getItemSummaries(array($this->_item), $permissions);
109
if ($ret->isError()) {
110
179
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
112
181
$this->assert(isset($content[$itemId]) && !empty($content[$itemId]),
113
182
'did not get item summary');
115
184
/* Get the item summary again, but without having the permissions */
117
186
list ($ret, $content) = $module->getItemSummaries(array($this->_item),
118
187
array($itemId => array()));
119
if ($ret->isError()) {
120
189
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
122
191
$this->assert(!isset($content[$itemId]), 'got an item summary');
137
207
$comment->setComment('this is a test comment');
138
208
$comment->setDate(time());
139
209
$ret = $comment->save();
140
if ($ret->isError()) {
141
211
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
145
215
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($comment->getId());
146
if ($ret->isError()) {
147
217
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
150
220
$comment->setComment('foo bar');
151
221
$ret = $comment->save();
152
if ($ret->isError()) {
153
223
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
156
226
$ret = GalleryCoreApi::releaseLocks($lockId);
157
if ($ret->isError()) {
158
228
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
162
232
$ret = GalleryCoreApi::deleteEntityById($comment->getId());
163
if ($ret->isError()) {
164
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
234
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
238
/* Verify that the comments are deleted if the commenter is deleted */
239
function testDeleteCommentsOnDeleteUserEvent() {
242
/* Create a user that we can delete */
243
list ($ret, $user) = $this->_createRandomUser();
245
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
248
/* Create a few comments */
249
for ($i = 0; $i < 3; $i++) {
250
list ($ret, $myComment[$i]) =
251
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryComment');
253
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
256
$this->assert(isset($myComment[$i]), 'Missing comment instance');
257
$myComment[$i]->create($this->_item->getId());
258
$myComment[$i]->setCommenterId($user->getId());
259
$myComment[$i]->setHost('127.0.0.1');
260
$myComment[$i]->setComment('my comment #' . $i);
261
$myComment[$i]->setDate(time()+$i);
262
$ret =$myComment[$i]->save();
264
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
268
/* Assert that everything is as expected before executing the test */
269
list ($ret, $comments) = GalleryCommentHelper::fetchComments($this->_item->getId());
271
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
273
$otherCommentsCount = count($this->_comment);
274
$this->assertEquals($otherCommentsCount + 3, count($comments),
275
'nr of comments before the test');
276
foreach ($comments as $comment) {
277
$commentsById[$comment->getId()] = $comment;
279
foreach ($myComment as $comment) {
280
$this->assertEquals($commentsById[$comment->getId()]->getCommenterId(), $user->getId(),
281
'commenterId (user) wrong before the test');
283
foreach ($this->_comment as $comment) {
284
$this->assertEquals($commentsById[$comment->getId()]->getCommenterId(),
285
$this->_item->getOwnerId(),
286
'commenterId (admin) wrong before the test');
289
/* The event listener is deactivated during unit tests, register it */
290
$listener = new GalleryCommentHelper();
291
$this->_registerTestEventListener('GalleryEntity::delete', $listener);
293
/* Delete the user (execute the test) */
294
$ret = GalleryCoreApi::deleteEntityById($user->getId());
296
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
299
/* Verify that all comments by this user are gone */
300
list ($ret, $comments) = GalleryCommentHelper::fetchComments($this->_item->getId());
302
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
304
$this->assertEquals(3, count($comments), 'nr of comments after the test');
305
foreach ($comments as $comment) {
306
$this->assertEquals($this->_item->getOwnerId(), $comment->getCommenterId(),
307
'commenterId wrong after the test');