feat: add validators to check values in services
Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
committed by
Julius Härtl
parent
357f30464d
commit
ff77c45a50
@@ -32,6 +32,7 @@ use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\NotFoundException;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\Validators\AssignmentServiceValidator;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@@ -76,6 +77,11 @@ class AssignmentServiceTest extends TestCase {
|
||||
* @var AssignmentService
|
||||
*/
|
||||
private $assignmentService;
|
||||
/**
|
||||
* @var AssignmentServiceValidator
|
||||
*/
|
||||
private $assignmentServiceValidator;
|
||||
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -87,6 +93,7 @@ class AssignmentServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->assignmentServiceValidator = $this->createMock(AssignmentServiceValidator::class);
|
||||
$this->assignmentService = new AssignmentService(
|
||||
$this->permissionService,
|
||||
$this->cardMapper,
|
||||
@@ -96,6 +103,7 @@ class AssignmentServiceTest extends TestCase {
|
||||
$this->activityManager,
|
||||
$this->changeHelper,
|
||||
$this->eventDispatcher,
|
||||
$this->assignmentServiceValidator,
|
||||
'admin'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\InvalidAttachmentType;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\NotFoundException;
|
||||
use OCA\Deck\Validators\AttachmentServiceValidator;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use OCP\IL10N;
|
||||
@@ -86,6 +87,10 @@ class AttachmentServiceTest extends TestCase {
|
||||
* @var IAttachmentService|MockObject
|
||||
*/
|
||||
private $filesAppServiceImpl;
|
||||
/**
|
||||
* @var AttachmentServiceValidator
|
||||
*/
|
||||
private $attachmentServiceValidator;
|
||||
|
||||
/**
|
||||
* @throws \OCP\AppFramework\QueryException
|
||||
@@ -122,6 +127,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->attachmentServiceValidator = $this->createMock(AttachmentServiceValidator::class);
|
||||
|
||||
$this->attachmentService = new AttachmentService(
|
||||
$this->attachmentMapper,
|
||||
@@ -132,7 +138,8 @@ class AttachmentServiceTest extends TestCase {
|
||||
$this->attachmentCacheHelper,
|
||||
$this->userId,
|
||||
$this->l10n,
|
||||
$this->activityManager
|
||||
$this->activityManager,
|
||||
$this->attachmentServiceValidator
|
||||
);
|
||||
}
|
||||
|
||||
@@ -158,7 +165,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
->willReturn($appContainer);
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $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, $this->attachmentServiceValidator);
|
||||
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
|
||||
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
|
||||
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
|
||||
@@ -188,7 +195,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
->method('getContainer')
|
||||
->willReturn($appContainer);
|
||||
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $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, $this->attachmentServiceValidator);
|
||||
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
|
||||
$attachmentService->getService('deck_file_invalid');
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ use OCP\IUserManager;
|
||||
use OCP\IGroupManager;
|
||||
use \Test\TestCase;
|
||||
use OCP\IURLGenerator;
|
||||
use OCA\Deck\Validators\BoardServiceValidator;
|
||||
|
||||
class BoardServiceTest extends TestCase {
|
||||
|
||||
@@ -80,6 +81,8 @@ class BoardServiceTest extends TestCase {
|
||||
private $userId = 'admin';
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
/** @var BoardServiceValidator */
|
||||
private $boardServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -99,6 +102,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->boardServiceValidator = $this->createMock(BoardServiceValidator::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -117,6 +121,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->eventDispatcher,
|
||||
$this->changeHelper,
|
||||
$this->urlGenerator,
|
||||
$this->boardServiceValidator,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Validators\CardServiceValidator;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
@@ -79,6 +80,8 @@ class CardServiceTest extends TestCase {
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var CardServiceValidator|MockObject */
|
||||
private $cardServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -97,6 +100,8 @@ class CardServiceTest extends TestCase {
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->cardServiceValidator = $this->createMock(CardServiceValidator::class);
|
||||
|
||||
$this->cardService = new CardService(
|
||||
$this->cardMapper,
|
||||
$this->stackMapper,
|
||||
@@ -113,6 +118,7 @@ class CardServiceTest extends TestCase {
|
||||
$this->changeHelper,
|
||||
$this->eventDispatcher,
|
||||
$this->urlGenerator,
|
||||
$this->cardServiceValidator,
|
||||
'user1'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OCA\Deck\Service;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Validators\LabelServiceValidator;
|
||||
use Test\TestCase;
|
||||
|
||||
class LabelServiceTest extends TestCase {
|
||||
@@ -40,6 +41,8 @@ class LabelServiceTest extends TestCase {
|
||||
private $boardService;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
/** @var LabelServiceValidator\MockObject */
|
||||
private $labelServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -49,11 +52,14 @@ class LabelServiceTest extends TestCase {
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->boardService = $this->createMock(BoardService::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->labelServiceValidator = $this->createMock(LabelServiceValidator::class);
|
||||
|
||||
$this->labelService = new LabelService(
|
||||
$this->labelMapper,
|
||||
$this->permissionService,
|
||||
$this->boardService,
|
||||
$this->changeHelper
|
||||
$this->changeHelper,
|
||||
$this->labelServiceValidator,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Validators\StackServiceValidator;
|
||||
use \Test\TestCase;
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,8 @@ class StackServiceTest extends TestCase {
|
||||
private $activityManager;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
/** @var StackServiceValidator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $stackServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -81,6 +84,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->labelMapper = $this->createMock(LabelMapper::class);
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->stackServiceValidator = $this->createMock(StackServiceValidator::class);
|
||||
|
||||
$this->stackService = new StackService(
|
||||
$this->stackMapper,
|
||||
@@ -93,6 +97,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->assignedUsersMapper,
|
||||
$this->attachmentService,
|
||||
$this->activityManager,
|
||||
$this->stackServiceValidator,
|
||||
$this->changeHelper
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user