feat: add validators to check values in services
Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
committed by
backportbot-nextcloud[bot]
parent
f250d9956b
commit
9d09916c17
@@ -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;
|
||||
@@ -89,6 +90,10 @@ class AttachmentServiceTest extends TestCase {
|
||||
* @var IAttachmentService|MockObject
|
||||
*/
|
||||
private $filesAppServiceImpl;
|
||||
/**
|
||||
* @var AttachmentServiceValidator
|
||||
*/
|
||||
private $attachmentServiceValidator;
|
||||
|
||||
/**
|
||||
* @throws \OCP\AppFramework\QueryException
|
||||
@@ -126,6 +131,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,
|
||||
@@ -137,7 +143,8 @@ class AttachmentServiceTest extends TestCase {
|
||||
$this->attachmentCacheHelper,
|
||||
$this->userId,
|
||||
$this->l10n,
|
||||
$this->activityManager
|
||||
$this->activityManager,
|
||||
$this->attachmentServiceValidator
|
||||
);
|
||||
}
|
||||
|
||||
@@ -163,7 +170,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
->willReturn($appContainer);
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->userManager, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $this->userId, $this->l10n, $this->activityManager);
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->userManager, $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')));
|
||||
@@ -193,7 +200,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
->method('getContainer')
|
||||
->willReturn($appContainer);
|
||||
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->userManager, $this->changeHelper, $this->permissionService, $application, $this->attachmentCacheHelper, $this->userId, $this->l10n, $this->activityManager);
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->userManager, $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');
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ use OCP\IGroupManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use \Test\TestCase;
|
||||
use OCP\IURLGenerator;
|
||||
use OCA\Deck\Validators\BoardServiceValidator;
|
||||
|
||||
class BoardServiceTest extends TestCase {
|
||||
|
||||
@@ -84,6 +85,8 @@ class BoardServiceTest extends TestCase {
|
||||
private $urlGenerator;
|
||||
/** @var IDBConnection|MockObject */
|
||||
private $connection;
|
||||
/** @var BoardServiceValidator */
|
||||
private $boardServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -104,6 +107,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
$this->boardServiceValidator = $this->createMock(BoardServiceValidator::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -123,6 +127,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->changeHelper,
|
||||
$this->urlGenerator,
|
||||
$this->connection,
|
||||
$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;
|
||||
@@ -84,6 +85,8 @@ class CardServiceTest extends TestCase {
|
||||
private $request;
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
/** @var CardServiceValidator|MockObject */
|
||||
private $cardServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -104,6 +107,7 @@ class CardServiceTest extends TestCase {
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
$this->cardServiceValidator = $this->createMock(CardServiceValidator::class);
|
||||
|
||||
$this->logger->expects($this->any())->method('error');
|
||||
|
||||
@@ -125,6 +129,7 @@ class CardServiceTest extends TestCase {
|
||||
$this->urlGenerator,
|
||||
$this->logger,
|
||||
$this->request,
|
||||
$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 Psr\Log\LoggerInterface;
|
||||
use \Test\TestCase;
|
||||
|
||||
@@ -70,6 +71,8 @@ class StackServiceTest extends TestCase {
|
||||
private $changeHelper;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
/** @var StackServiceValidator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $stackServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -85,6 +88,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->stackServiceValidator = $this->createMock(StackServiceValidator::class);
|
||||
|
||||
$this->stackService = new StackService(
|
||||
$this->stackMapper,
|
||||
@@ -98,7 +102,8 @@ class StackServiceTest extends TestCase {
|
||||
$this->attachmentService,
|
||||
$this->activityManager,
|
||||
$this->changeHelper,
|
||||
$this->logger
|
||||
$this->logger,
|
||||
$this->stackServiceValidator
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user