Refactor and improvements on command
Check available helpers Default permission: view only Moved validate setting from helper to command Turn more easy create a importer Docblock and improvements on interface lcfirst on system property Helper moved to ImporHelper folder Moved fixtures to ImportHelper Rename settings to config Big refactor to move import methods to service Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
eb8bf3f22b
commit
fd92fc3c4d
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace OCA\Deck\Command;
|
||||
|
||||
use OCA\Deck\Command\Helper\TrelloHelper;
|
||||
use OCA\Deck\Command\ImportHelper\TrelloHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -55,12 +55,12 @@ class BoardImportTest extends \Test\TestCase {
|
||||
$input->method('getOption')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('system')],
|
||||
[$this->equalTo('setting')],
|
||||
[$this->equalTo('config')],
|
||||
[$this->equalTo('data')]
|
||||
)
|
||||
->will($this->returnValueMap([
|
||||
['system', 'trello'],
|
||||
['setting', __DIR__ . '/fixtures/setting-trello.json'],
|
||||
['config', __DIR__ . '/fixtures/config-trello.json'],
|
||||
['data', __DIR__ . '/fixtures/data-trello.json']
|
||||
]));
|
||||
$output = $this->createMock(OutputInterface::class);
|
||||
|
||||
@@ -23,59 +23,23 @@
|
||||
|
||||
namespace OCA\Deck\Command;
|
||||
|
||||
use OCA\Deck\Command\Helper\TrelloHelper;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use OCA\Deck\Service\LabelService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserManager;
|
||||
use OCA\Deck\Command\ImportHelper\TrelloHelper;
|
||||
use OCA\Deck\Service\TrelloImportService;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class TrelloHelperTest extends \Test\TestCase {
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
/** @var LabelService */
|
||||
private $labelService;
|
||||
/** @var StackMapper */
|
||||
private $stackMapper;
|
||||
/** @var CardMapper */
|
||||
private $cardMapper;
|
||||
/** @var IDBConnection */
|
||||
private $connection;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var TrelloHelper */
|
||||
private $trelloHelper;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->boardService = $this->createMock(BoardService::class);
|
||||
$this->labelService = $this->createMock(LabelService::class);
|
||||
$this->stackMapper = $this->createMock(StackMapper::class);
|
||||
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||
$this->assignmentMapper = $this->createMock(AssignmentMapper::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->trelloImportService = $this->createMock(TrelloImportService::class);
|
||||
$this->trelloHelper = new TrelloHelper(
|
||||
$this->boardService,
|
||||
$this->labelService,
|
||||
$this->stackMapper,
|
||||
$this->cardMapper,
|
||||
$this->assignmentMapper,
|
||||
$this->aclMapper,
|
||||
$this->connection,
|
||||
$this->userManager,
|
||||
$this->l10n
|
||||
$this->trelloImportService
|
||||
);
|
||||
$questionHelper = new QuestionHelper();
|
||||
$command = new BoardImport($this->trelloHelper);
|
||||
@@ -92,47 +56,17 @@ class TrelloHelperTest extends \Test\TestCase {
|
||||
|
||||
$input->method('getOption')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('data')],
|
||||
[$this->equalTo('setting')]
|
||||
[$this->equalTo('system')],
|
||||
[$this->equalTo('config')]
|
||||
)
|
||||
->will($this->returnValueMap([
|
||||
['data', __DIR__ . '/../fixtures/data-trello.json'],
|
||||
['setting', __DIR__ . '/../fixtures/setting-trello.json']
|
||||
['system', 'trello'],
|
||||
['config', __DIR__ . '/../fixtures/config-trello.json']
|
||||
]));
|
||||
$output = $this->createMock(OutputInterface::class);
|
||||
|
||||
$user = $this->createMock(\OCP\IUser::class);
|
||||
$user
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($user);
|
||||
$board = $this->createMock(\OCA\Deck\Db\Board::class);
|
||||
$this->boardService
|
||||
->expects($this->once())
|
||||
->method('create')
|
||||
->willReturn($board);
|
||||
$label = $this->createMock(\OCA\Deck\Db\Label::class);
|
||||
$this->labelService
|
||||
->expects($this->once())
|
||||
->method('create')
|
||||
->willReturn($label);
|
||||
$stack = $this->createMock(\OCA\Deck\Db\Stack::class);
|
||||
$this->stackMapper
|
||||
->expects($this->once())
|
||||
->method('insert')
|
||||
->willReturn($stack);
|
||||
$card = $this->createMock(\OCA\Deck\Db\Card::class);
|
||||
$this->cardMapper
|
||||
->expects($this->once())
|
||||
->method('insert')
|
||||
->willReturn($card);
|
||||
|
||||
$this->trelloHelper->validate($input, $output);
|
||||
$this->invokePrivate($this->trelloHelper->getCommand(), 'validateSystem', [$input, $output]);
|
||||
$this->invokePrivate($this->trelloHelper->getCommand(), 'validateConfig', [$input, $output]);
|
||||
$actual = $this->trelloHelper->import($input, $output);
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
104
tests/unit/Service/TrelloImportServiceTest.php
Normal file
104
tests/unit/Service/TrelloImportServiceTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @author Vitor Mattos <vitor@php.rio>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class TrelloImportServiceTest extends \Test\TestCase {
|
||||
/** @var TrelloImportService */
|
||||
private $trelloImportService;
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
/** @var LabelService */
|
||||
private $labelService;
|
||||
/** @var StackMapper */
|
||||
private $stackMapper;
|
||||
/** @var CardMapper */
|
||||
private $cardMapper;
|
||||
/** @var AssignmentMapper */
|
||||
private $assignmentMapper;
|
||||
/** @var AclMapper */
|
||||
private $aclMapper;
|
||||
/** @var IDBConnection */
|
||||
private $connection;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->boardService = $this->createMock(BoardService::class);
|
||||
$this->labelService = $this->createMock(LabelService::class);
|
||||
$this->stackMapper = $this->createMock(StackMapper::class);
|
||||
$this->cardMapper = $this->createMock(CardMapper::class);
|
||||
$this->assignmentMapper = $this->createMock(AssignmentMapper::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->trelloImportService = new TrelloImportService(
|
||||
$this->boardService,
|
||||
$this->labelService,
|
||||
$this->stackMapper,
|
||||
$this->cardMapper,
|
||||
$this->assignmentMapper,
|
||||
$this->aclMapper,
|
||||
$this->connection,
|
||||
$this->userManager,
|
||||
$this->l10n
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateOwnerWithFaliure() {
|
||||
$owner = $this->createMock(\OCP\IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
$this->trelloImportService->setConfig('owner', $owner);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn(null);
|
||||
$this->expectErrorMessage('Owner "admin" not found on Nextcloud. Check setting json.');
|
||||
$this->trelloImportService->validateOwner();
|
||||
}
|
||||
|
||||
public function testValidateOwnerWithSuccess() {
|
||||
$owner = $this->createMock(\OCP\IUser::class);
|
||||
$owner
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
$this->trelloImportService->setConfig('owner', $owner);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->willReturn($owner);
|
||||
$actual = $this->trelloImportService->validateOwner();
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user