Merge pull request #3805 from nextcloud/backport/3682/stable23

[stable23] Increase file count after sharing
This commit is contained in:
Julius Härtl
2022-05-12 09:57:43 +02:00
committed by GitHub
7 changed files with 125 additions and 39 deletions

View File

@@ -0,0 +1,52 @@
<?php
/*
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
declare(strict_types=1);
namespace OCA\Deck\Cache;
use OCP\ICache;
use OCP\ICacheFactory;
class AttachmentCacheHelper {
/** @var ICache */
private $cache;
public function __construct(ICacheFactory $cacheFactory) {
$this->cache = $cacheFactory->createDistributed('deck-attachments');
}
public function getAttachmentCount(int $cardId): ?int {
return $this->cache->get('count-' . $cardId);
}
public function setAttachmentCount(int $cardId, int $count): void {
$this->cache->set('count-' . $cardId, $count);
}
public function clearAttachmentCount(int $cardId): void {
$this->cache->remove('count-' . $cardId);
}
}

View File

@@ -34,11 +34,10 @@ use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
use OCA\Deck\Cache\AttachmentCacheHelper;
use OCA\Deck\StatusException; use OCA\Deck\StatusException;
use OCP\AppFramework\Db\IMapperException; use OCP\AppFramework\Db\IMapperException;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IL10N; use OCP\IL10N;
class AttachmentService { class AttachmentService {
@@ -49,9 +48,10 @@ class AttachmentService {
/** @var IAttachmentService[] */ /** @var IAttachmentService[] */
private $services = []; private $services = [];
/** @var Application */
private $application; private $application;
/** @var ICache */ /** @var AttachmentCacheHelper */
private $cache; private $attachmentCacheHelper;
/** @var IL10N */ /** @var IL10N */
private $l10n; private $l10n;
/** @var ActivityManager */ /** @var ActivityManager */
@@ -59,13 +59,13 @@ class AttachmentService {
/** @var ChangeHelper */ /** @var ChangeHelper */
private $changeHelper; private $changeHelper;
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId, IL10N $l10n, ActivityManager $activityManager) { public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, AttachmentCacheHelper $attachmentCacheHelper, $userId, IL10N $l10n, ActivityManager $activityManager) {
$this->attachmentMapper = $attachmentMapper; $this->attachmentMapper = $attachmentMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->userId = $userId; $this->userId = $userId;
$this->application = $application; $this->application = $application;
$this->cache = $cacheFactory->createDistributed('deck-card-attachments-'); $this->attachmentCacheHelper = $attachmentCacheHelper;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->changeHelper = $changeHelper; $this->changeHelper = $changeHelper;
@@ -139,14 +139,16 @@ class AttachmentService {
* @param $cardId * @param $cardId
* @return int|mixed * @return int|mixed
* @throws BadRequestException * @throws BadRequestException
* @throws InvalidAttachmentType
* @throws \OCP\DB\Exception
*/ */
public function count($cardId) { public function count($cardId) {
if (is_numeric($cardId) === false) { if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number'); throw new BadRequestException('card id must be a number');
} }
$count = $this->cache->get('card-' . $cardId); $count = $this->attachmentCacheHelper->getAttachmentCount((int)$cardId);
if (!$count) { if ($count === null) {
$count = count($this->attachmentMapper->findAll($cardId)); $count = count($this->attachmentMapper->findAll($cardId));
foreach (array_keys($this->services) as $attachmentType) { foreach (array_keys($this->services) as $attachmentType) {
@@ -156,7 +158,7 @@ class AttachmentService {
} }
} }
$this->cache->set('card-' . $cardId, $count); $this->attachmentCacheHelper->setAttachmentCount((int)$cardId, $count);
} }
return $count; return $count;
@@ -186,7 +188,7 @@ class AttachmentService {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId); $this->attachmentCacheHelper->clearAttachmentCount((int)$cardId);
$attachment = new Attachment(); $attachment = new Attachment();
$attachment->setCardId($cardId); $attachment->setCardId($cardId);
$attachment->setType($type); $attachment->setType($type);
@@ -298,7 +300,7 @@ class AttachmentService {
} }
$this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $attachment->getCardId()); $this->attachmentCacheHelper->clearAttachmentCount($cardId);
$attachment->setData($data); $attachment->setData($data);
try { try {
@@ -356,7 +358,7 @@ class AttachmentService {
} }
} }
$this->cache->clear('card-' . $attachment->getCardId()); $this->attachmentCacheHelper->clearAttachmentCount($cardId);
$this->changeHelper->cardChanged($attachment->getCardId()); $this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE);
return $attachment; return $attachment;
@@ -370,7 +372,7 @@ class AttachmentService {
} }
$this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $attachment->getCardId()); $this->attachmentCacheHelper->clearAttachmentCount($cardId);
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());

View File

@@ -28,6 +28,7 @@ namespace OCA\Deck\Sharing;
use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform;
use OC\Files\Cache\Cache; use OC\Files\Cache\Cache;
use OCA\Deck\Cache\AttachmentCacheHelper;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Board; use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
@@ -46,7 +47,6 @@ use OCP\Files\IMimeTypeLoader;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\Security\ISecureRandom;
use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager; use OCP\Share\IManager;
@@ -70,6 +70,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
private $dbConnection; private $dbConnection;
/** @var IManager */ /** @var IManager */
private $shareManager; private $shareManager;
/** @var AttachmentCacheHelper */
private $attachmentCacheHelper;
/** @var BoardMapper */ /** @var BoardMapper */
private $boardMapper; private $boardMapper;
/** @var CardMapper */ /** @var CardMapper */
@@ -78,14 +80,25 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
private $permissionService; private $permissionService;
/** @var ITimeFactory */ /** @var ITimeFactory */
private $timeFactory; private $timeFactory;
/** @var IL10N */
private $l; private $l;
public function __construct(IDBConnection $connection, IManager $shareManager, ISecureRandom $secureRandom, BoardMapper $boardMapper, CardMapper $cardMapper, PermissionService $permissionService, IL10N $l) { public function __construct(
IDBConnection $connection,
IManager $shareManager,
BoardMapper $boardMapper,
CardMapper $cardMapper,
PermissionService $permissionService,
AttachmentCacheHelper $attachmentCacheHelper,
IL10N $l
) {
$this->dbConnection = $connection; $this->dbConnection = $connection;
$this->shareManager = $shareManager; $this->shareManager = $shareManager;
$this->boardMapper = $boardMapper; $this->boardMapper = $boardMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->attachmentCacheHelper = $attachmentCacheHelper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->l = $l; $this->l = $l;
$this->timeFactory = \OC::$server->get(ITimeFactory::class); $this->timeFactory = \OC::$server->get(ITimeFactory::class);
} }
@@ -153,6 +166,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
); );
$data = $this->getRawShare($shareId); $data = $this->getRawShare($shareId);
$this->attachmentCacheHelper->clearAttachmentCount((int)$cardId);
return $this->createShareObject($data); return $this->createShareObject($data);
} }
@@ -340,6 +355,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
$qb->execute(); $qb->execute();
$this->attachmentCacheHelper->clearAttachmentCount((int)$share->getSharedWith());
} }
/** /**

View File

@@ -109,7 +109,7 @@ import relativeDate from '../../mixins/relativeDate'
import { formatFileSize } from '@nextcloud/files' import { formatFileSize } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth' import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router' import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router'
import { mapState } from 'vuex' import { mapState, mapActions } from 'vuex'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import attachmentUpload from '../../mixins/attachmentUpload' import attachmentUpload from '../../mixins/attachmentUpload'
import { getFilePickerBuilder } from '@nextcloud/dialogs' import { getFilePickerBuilder } from '@nextcloud/dialogs'
@@ -205,11 +205,14 @@ export default {
cardId: { cardId: {
immediate: true, immediate: true,
handler() { handler() {
this.$store.dispatch('fetchAttachments', this.cardId) this.fetchAttachments(this.cardId)
}, },
}, },
}, },
methods: { methods: {
...mapActions([
'fetchAttachments',
]),
handleUploadFile(event) { handleUploadFile(event) {
const files = event.target.files ?? [] const files = event.target.files ?? []
for (const file of files) { for (const file of files) {
@@ -233,7 +236,7 @@ export default {
shareType: 12, shareType: 12,
shareWith: '' + this.cardId, shareWith: '' + this.cardId,
}).then(() => { }).then(() => {
this.$store.dispatch('fetchAttachments', this.cardId) this.fetchAttachments(this.cardId)
}) })
}) })
}, },

View File

@@ -84,6 +84,7 @@ export default {
async fetchAttachments({ commit }, cardId) { async fetchAttachments({ commit }, cardId) {
const attachments = await apiClient.fetchAttachments(cardId) const attachments = await apiClient.fetchAttachments(cardId)
commit('createAttachments', { cardId, attachments }) commit('createAttachments', { cardId, attachments })
commit('cardSetAttachmentCount', { cardId, count: attachments.length })
}, },
async createAttachment({ commit }, { cardId, formData, onUploadProgress }) { async createAttachment({ commit }, { cardId, formData, onUploadProgress }) {

View File

@@ -252,6 +252,12 @@ export default {
} }
Vue.set(state.cards[existingIndex], 'lastModified', Date.now() / 1000) Vue.set(state.cards[existingIndex], 'lastModified', Date.now() / 1000)
}, },
cardSetAttachmentCount(state, { cardId, count }) {
const existingIndex = state.cards.findIndex(_card => _card.id === cardId)
if (existingIndex !== -1) {
Vue.set(state.cards[existingIndex], 'attachmentCount', count)
}
},
cardIncreaseAttachmentCount(state, cardId) { cardIncreaseAttachmentCount(state, cardId) {
const existingIndex = state.cards.findIndex(_card => _card.id === cardId) const existingIndex = state.cards.findIndex(_card => _card.id === cardId)
if (existingIndex !== -1) { if (existingIndex !== -1) {

View File

@@ -25,6 +25,7 @@ namespace OCA\Deck\Service;
use OCA\Deck\Activity\ActivityManager; use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\AppInfo\Application; use OCA\Deck\AppInfo\Application;
use OCA\Deck\Cache\AttachmentCacheHelper;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Attachment; use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\Db\AttachmentMapper;
@@ -35,8 +36,6 @@ use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\AppFramework\IAppContainer; use OCP\AppFramework\IAppContainer;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IL10N; use OCP\IL10N;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
@@ -67,10 +66,11 @@ class AttachmentServiceTest extends TestCase {
private $cardMapper; private $cardMapper;
/** @var PermissionService|MockObject */ /** @var PermissionService|MockObject */
private $permissionService; private $permissionService;
/** @var string */
private $userId = 'admin'; private $userId = 'admin';
/** @var Application|MockObject */ /** @var Application|MockObject */
private $application; private $application;
private $cacheFactory; private $attachmentCacheHelper;
/** @var AttachmentService */ /** @var AttachmentService */
private $attachmentService; private $attachmentService;
/** @var MockObject */ /** @var MockObject */
@@ -78,8 +78,6 @@ class AttachmentServiceTest extends TestCase {
/** @var ActivityManager */ /** @var ActivityManager */
private $activityManager; private $activityManager;
private $appContainer; private $appContainer;
/** ICache */
private $cache;
/** @var IL10N */ /** @var IL10N */
private $l10n; private $l10n;
/** @var ChangeHelper */ /** @var ChangeHelper */
@@ -104,12 +102,9 @@ class AttachmentServiceTest extends TestCase {
$this->cardMapper = $this->createMock(CardMapper::class); $this->cardMapper = $this->createMock(CardMapper::class);
$this->permissionService = $this->createMock(PermissionService::class); $this->permissionService = $this->createMock(PermissionService::class);
$this->application = $this->createMock(Application::class); $this->application = $this->createMock(Application::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class); $this->attachmentCacheHelper = $this->createMock(AttachmentCacheHelper::class);
$this->activityManager = $this->createMock(ActivityManager::class); $this->activityManager = $this->createMock(ActivityManager::class);
$this->cache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->any())->method('createDistributed')->willReturn($this->cache);
$this->appContainer->expects($this->exactly(2)) $this->appContainer->expects($this->exactly(2))
->method('query') ->method('query')
->withConsecutive( ->withConsecutive(
@@ -128,7 +123,17 @@ class AttachmentServiceTest extends TestCase {
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->changeHelper = $this->createMock(ChangeHelper::class); $this->changeHelper = $this->createMock(ChangeHelper::class);
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $this->attachmentService = new AttachmentService(
$this->attachmentMapper,
$this->cardMapper,
$this->changeHelper,
$this->permissionService,
$this->application,
$this->attachmentCacheHelper,
$this->userId,
$this->l10n,
$this->activityManager
);
} }
public function testRegisterAttachmentService() { public function testRegisterAttachmentService() {
@@ -153,7 +158,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file')); $this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom'))); $this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
@@ -183,7 +188,7 @@ class AttachmentServiceTest extends TestCase {
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$attachmentService->getService('deck_file_invalid'); $attachmentService->getService('deck_file_invalid');
} }
@@ -262,14 +267,14 @@ class AttachmentServiceTest extends TestCase {
} }
public function testCount() { public function testCount() {
$this->cache->expects($this->once())->method('get')->with('card-123')->willReturn(null); $this->attachmentCacheHelper->expects($this->once())->method('getAttachmentCount')->with(123)->willReturn(null);
$this->attachmentMapper->expects($this->once())->method('findAll')->willReturn([1,2,3,4]); $this->attachmentMapper->expects($this->once())->method('findAll')->willReturn([1,2,3,4]);
$this->cache->expects($this->once())->method('set')->with('card-123', 4)->willReturn(null); $this->attachmentCacheHelper->expects($this->once())->method('setAttachmentCount')->with(123, 4);
$this->assertEquals(4, $this->attachmentService->count(123)); $this->assertEquals(4, $this->attachmentService->count(123));
} }
public function testCountCacheHit() { public function testCountCacheHit() {
$this->cache->expects($this->once())->method('get')->with('card-123')->willReturn(4); $this->attachmentCacheHelper->expects($this->once())->method('getAttachmentCount')->with(123)->willReturn(4);
$this->assertEquals(4, $this->attachmentService->count(123)); $this->assertEquals(4, $this->attachmentService->count(123));
} }
@@ -277,7 +282,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(123);
$this->attachmentServiceImpl->expects($this->once()) $this->attachmentServiceImpl->expects($this->once())
->method('create'); ->method('create');
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
@@ -330,7 +335,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(1);
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('find') ->method('find')
->with(1) ->with(1)
@@ -357,7 +362,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(1);
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('find') ->method('find')
->with(1) ->with(1)
@@ -378,7 +383,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(1);
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('find') ->method('find')
->with(1) ->with(1)
@@ -403,7 +408,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(1);
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('find') ->method('find')
->with(1) ->with(1)
@@ -424,7 +429,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
$expected = $this->createAttachment('deck_file', 'file_name.jpg'); $expected = $this->createAttachment('deck_file', 'file_name.jpg');
$this->mockPermission(Acl::PERMISSION_EDIT); $this->mockPermission(Acl::PERMISSION_EDIT);
$this->cache->expects($this->once())->method('clear')->with('card-123'); $this->attachmentCacheHelper->expects($this->once())->method('clearAttachmentCount')->with(1);
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('find') ->method('find')
->with(1) ->with(1)