Create route to get json schema to validate config
Fix visibility Make compatible with php 7.2 Remove returing instance Increase coverage Reduce psalm info Throw exception if system not defined Increment coverage Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
4138953208
commit
e01e4cf1a7
@@ -91,6 +91,7 @@ return [
|
|||||||
['name' => 'board_api#updateAcl', 'url' => '/api/v{apiVersion}/boards/{boardId}/acl/{aclId}', 'verb' => 'PUT'],
|
['name' => 'board_api#updateAcl', 'url' => '/api/v{apiVersion}/boards/{boardId}/acl/{aclId}', 'verb' => 'PUT'],
|
||||||
|
|
||||||
['name' => 'board_import_api#getAllowedSystems', 'url' => '/api/v{apiVersion}/boards/import/getSystems','verb' => 'GET'],
|
['name' => 'board_import_api#getAllowedSystems', 'url' => '/api/v{apiVersion}/boards/import/getSystems','verb' => 'GET'],
|
||||||
|
['name' => 'board_import_api#getConfigSchema', 'url' => '/api/v{apiVersion}/boards/import/config/schema/{name}','verb' => 'GET'],
|
||||||
['name' => 'board_import_api#import', 'url' => '/api/v{apiVersion}/boards/import','verb' => 'POST'],
|
['name' => 'board_import_api#import', 'url' => '/api/v{apiVersion}/boards/import','verb' => 'POST'],
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
docs/API.md
17
docs/API.md
@@ -992,6 +992,23 @@ For now only `deck_file` is supported as an attachment type.
|
|||||||
|
|
||||||
#### Request parameters
|
#### Request parameters
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| ------------ | ------- | --------------------------------------------- |
|
||||||
|
| system | Integer | The system name. Example: trello |
|
||||||
|
|
||||||
|
#### Response
|
||||||
|
|
||||||
|
Make a request to see the json schema of system
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### GET /boards/import/config/system/{schema} - Import a board
|
||||||
|
|
||||||
|
#### Request parameters
|
||||||
|
|
||||||
#### Response
|
#### Response
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class BoardImport extends Command {
|
class BoardImport extends Command {
|
||||||
/** @var boardImportCommandService */
|
/** @var BoardImportCommandService */
|
||||||
private $boardImportCommandService;
|
private $boardImportCommandService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ class BoardImportApiController extends ApiController {
|
|||||||
private $userId;
|
private $userId;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$appName,
|
string $appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
BoardImportService $boardImportService,
|
BoardImportService $boardImportService,
|
||||||
$userId
|
string $userId
|
||||||
) {
|
) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->boardImportService = $boardImportService;
|
$this->boardImportService = $boardImportService;
|
||||||
@@ -51,7 +51,7 @@ class BoardImportApiController extends ApiController {
|
|||||||
* @CORS
|
* @CORS
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function import($system, $config, $data) {
|
public function import(string $system, array $config, array $data): DataResponse {
|
||||||
$this->boardImportService->setSystem($system);
|
$this->boardImportService->setSystem($system);
|
||||||
$config = json_decode(json_encode($config));
|
$config = json_decode(json_encode($config));
|
||||||
$config->owner = $this->userId;
|
$config->owner = $this->userId;
|
||||||
@@ -67,8 +67,20 @@ class BoardImportApiController extends ApiController {
|
|||||||
* @CORS
|
* @CORS
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function getAllowedSystems() {
|
public function getAllowedSystems(): DataResponse {
|
||||||
$allowedSystems = $this->boardImportService->getAllowedImportSystems();
|
$allowedSystems = $this->boardImportService->getAllowedImportSystems();
|
||||||
return new DataResponse($allowedSystems, Http::STATUS_OK);
|
return new DataResponse($allowedSystems, Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @CORS
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*/
|
||||||
|
public function getConfigSchema(string $name): DataResponse {
|
||||||
|
$this->boardImportService->setSystem($name);
|
||||||
|
$this->boardImportService->validateSystem();
|
||||||
|
$jsonSchemaPath = json_decode(file_get_contents($this->boardImportService->getJsonSchemaPath()));
|
||||||
|
return new DataResponse($jsonSchemaPath, Http::STATUS_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,25 @@
|
|||||||
<?php
|
<?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;
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
@@ -29,24 +50,23 @@ abstract class ABoardImportService {
|
|||||||
*/
|
*/
|
||||||
abstract public function getCards(): array;
|
abstract public function getCards(): array;
|
||||||
|
|
||||||
abstract public function updateStack(string $id, Stack $stack): self;
|
abstract public function updateStack(string $id, Stack $stack): void;
|
||||||
|
|
||||||
abstract public function updateCard(string $id, Card $card): self;
|
abstract public function updateCard(string $id, Card $card): void;
|
||||||
|
|
||||||
abstract public function importParticipants(): self;
|
abstract public function importParticipants(): void;
|
||||||
|
|
||||||
abstract public function importComments();
|
abstract public function importComments(): void;
|
||||||
|
|
||||||
/** @return Label[] */
|
/** @return Label[] */
|
||||||
abstract public function importLabels(): array;
|
abstract public function importLabels(): array;
|
||||||
|
|
||||||
abstract public function assignCardsToLabels(): self;
|
abstract public function assignCardsToLabels(): void;
|
||||||
|
|
||||||
abstract public function validateUsers(): self;
|
abstract public function validateUsers(): void;
|
||||||
|
|
||||||
public function setImportService($service): self {
|
public function setImportService(BoardImportService $service): void {
|
||||||
$this->boardImportService = $service;
|
$this->boardImportService = $service;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getImportService(): BoardImportService {
|
public function getImportService(): BoardImportService {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Service;
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
use OCA\Deck\Command\BoardImport;
|
|
||||||
use OCA\Deck\Exceptions\ConflictException;
|
use OCA\Deck\Exceptions\ConflictException;
|
||||||
use OCA\Deck\NotFoundException;
|
use OCA\Deck\NotFoundException;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
@@ -33,18 +32,21 @@ use Symfony\Component\Console\Question\ChoiceQuestion;
|
|||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
class BoardImportCommandService extends BoardImportService {
|
class BoardImportCommandService extends BoardImportService {
|
||||||
/** @var Command */
|
|
||||||
private $command;
|
|
||||||
/** @var InputInterface */
|
|
||||||
private $input;
|
|
||||||
/** @var OutputInterface */
|
|
||||||
private $output;
|
|
||||||
/**
|
/**
|
||||||
* Data object created from config JSON
|
* @var Command
|
||||||
*
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
* @var \StdClass
|
|
||||||
*/
|
*/
|
||||||
public $config;
|
private $command;
|
||||||
|
/**
|
||||||
|
* @var InputInterface
|
||||||
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
|
*/
|
||||||
|
private $input;
|
||||||
|
/**
|
||||||
|
* @var OutputInterface
|
||||||
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
|
*/
|
||||||
|
private $output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define Command instance
|
* Define Command instance
|
||||||
@@ -56,14 +58,11 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
$this->command = $command;
|
$this->command = $command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getCommand(): Command {
|
||||||
* @return BoardImport
|
|
||||||
*/
|
|
||||||
public function getCommand() {
|
|
||||||
return $this->command;
|
return $this->command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setInput($input): self {
|
public function setInput(InputInterface $input): self {
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -72,7 +71,7 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
return $this->input;
|
return $this->input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOutput($output): self {
|
public function setOutput(OutputInterface $output): self {
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -81,12 +80,12 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
return $this->output;
|
return $this->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate() {
|
public function validate(): void {
|
||||||
$this->validateData();
|
$this->validateData();
|
||||||
parent::validate();
|
parent::validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateConfig() {
|
protected function validateConfig(): void {
|
||||||
try {
|
try {
|
||||||
parent::validateConfig();
|
parent::validateConfig();
|
||||||
return;
|
return;
|
||||||
@@ -96,7 +95,7 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
'Please inform a valid config json file: ',
|
'Please inform a valid config json file: ',
|
||||||
'config.json'
|
'config.json'
|
||||||
);
|
);
|
||||||
$question->setValidator(function ($answer) {
|
$question->setValidator(function (string $answer) {
|
||||||
if (!is_file($answer)) {
|
if (!is_file($answer)) {
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
'config file not found'
|
'config file not found'
|
||||||
@@ -108,7 +107,7 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
$this->setConfigInstance($configFile);
|
$this->setConfigInstance($configFile);
|
||||||
} catch (ConflictException $e) {
|
} catch (ConflictException $e) {
|
||||||
$this->getOutput()->writeln('<error>Invalid config file</error>');
|
$this->getOutput()->writeln('<error>Invalid config file</error>');
|
||||||
$this->getOutput()->writeln(array_map(function ($v) {
|
$this->getOutput()->writeln(array_map(function (array $v): string {
|
||||||
return $v['message'];
|
return $v['message'];
|
||||||
}, $e->getData()));
|
}, $e->getData()));
|
||||||
$this->getOutput()->writeln('Valid schema:');
|
$this->getOutput()->writeln('Valid schema:');
|
||||||
@@ -121,7 +120,7 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateSystem() {
|
public function validateSystem(): void {
|
||||||
try {
|
try {
|
||||||
parent::validateSystem();
|
parent::validateSystem();
|
||||||
return;
|
return;
|
||||||
@@ -142,13 +141,13 @@ class BoardImportCommandService extends BoardImportService {
|
|||||||
|
|
||||||
private function validateData(): self {
|
private function validateData(): self {
|
||||||
$filename = $this->getInput()->getOption('data');
|
$filename = $this->getInput()->getOption('data');
|
||||||
if (!is_file($filename)) {
|
if (!is_string($filename) || empty($filename) || !is_file($filename)) {
|
||||||
$helper = $this->getCommand()->getHelper('question');
|
$helper = $this->getCommand()->getHelper('question');
|
||||||
$question = new Question(
|
$question = new Question(
|
||||||
'Please inform a valid data json file: ',
|
'Please inform a valid data json file: ',
|
||||||
'data.json'
|
'data.json'
|
||||||
);
|
);
|
||||||
$question->setValidator(function ($answer) {
|
$question->setValidator(function (string $answer) {
|
||||||
if (!is_file($answer)) {
|
if (!is_file($answer)) {
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
'Data file not found'
|
'Data file not found'
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ namespace OCA\Deck\Service;
|
|||||||
|
|
||||||
use JsonSchema\Constraints\Constraint;
|
use JsonSchema\Constraints\Constraint;
|
||||||
use JsonSchema\Validator;
|
use JsonSchema\Validator;
|
||||||
|
use OC\Comments\Comment;
|
||||||
use OCA\Deck\AppInfo\Application;
|
use OCA\Deck\AppInfo\Application;
|
||||||
use OCA\Deck\BadRequestException;
|
use OCA\Deck\BadRequestException;
|
||||||
use OCA\Deck\Db\AclMapper;
|
use OCA\Deck\Db\AclMapper;
|
||||||
|
use OCA\Deck\Db\Assignment;
|
||||||
use OCA\Deck\Db\AssignmentMapper;
|
use OCA\Deck\Db\AssignmentMapper;
|
||||||
use OCA\Deck\Db\Board;
|
use OCA\Deck\Db\Board;
|
||||||
use OCA\Deck\Db\BoardMapper;
|
use OCA\Deck\Db\BoardMapper;
|
||||||
@@ -38,6 +40,7 @@ use OCA\Deck\Db\Stack;
|
|||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\Exceptions\ConflictException;
|
use OCA\Deck\Exceptions\ConflictException;
|
||||||
use OCA\Deck\NotFoundException;
|
use OCA\Deck\NotFoundException;
|
||||||
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\Comments\ICommentsManager;
|
use OCP\Comments\ICommentsManager;
|
||||||
use OCP\Comments\NotFoundException as CommentNotFoundException;
|
use OCP\Comments\NotFoundException as CommentNotFoundException;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
@@ -63,24 +66,29 @@ class BoardImportService {
|
|||||||
/** @var ICommentsManager */
|
/** @var ICommentsManager */
|
||||||
private $commentsManager;
|
private $commentsManager;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $system;
|
private $system = '';
|
||||||
/** @var ABoardImportService */
|
/** @var null|ABoardImportService */
|
||||||
private $systemInstance;
|
private $systemInstance;
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
private $allowedSystems;
|
private $allowedSystems = [];
|
||||||
/**
|
/**
|
||||||
* Data object created from config JSON
|
* Data object created from config JSON
|
||||||
*
|
*
|
||||||
* @var \stdClass
|
* @var \stdClass
|
||||||
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
*/
|
*/
|
||||||
public $config;
|
public $config;
|
||||||
/**
|
/**
|
||||||
* Data object created from JSON of origin system
|
* Data object created from JSON of origin system
|
||||||
*
|
*
|
||||||
* @var \stdClass
|
* @var \stdClass
|
||||||
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
*/
|
*/
|
||||||
private $data;
|
private $data;
|
||||||
/** @var Board */
|
/**
|
||||||
|
* @var Board
|
||||||
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
|
*/
|
||||||
private $board;
|
private $board;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -103,6 +111,7 @@ class BoardImportService {
|
|||||||
$this->cardMapper = $cardMapper;
|
$this->cardMapper = $cardMapper;
|
||||||
$this->assignmentMapper = $assignmentMapper;
|
$this->assignmentMapper = $assignmentMapper;
|
||||||
$this->commentsManager = $commentsManager;
|
$this->commentsManager = $commentsManager;
|
||||||
|
$this->setData(new \stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function import(): void {
|
public function import(): void {
|
||||||
@@ -120,31 +129,35 @@ class BoardImportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate() {
|
public function validate(): void {
|
||||||
$this->validateSystem();
|
$this->validateSystem();
|
||||||
$this->validateConfig();
|
$this->validateConfig();
|
||||||
$this->validateUsers();
|
$this->validateUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateSystem() {
|
public function validateSystem(): void {
|
||||||
if (!in_array($this->getSystem(), $this->getAllowedImportSystems())) {
|
if (!in_array($this->getSystem(), $this->getAllowedImportSystems())) {
|
||||||
throw new NotFoundException('Invalid system');
|
throw new NotFoundException('Invalid system');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSystem(string $system): self {
|
/**
|
||||||
|
* @param mixed $system
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setSystem($system): self {
|
||||||
$this->system = $system;
|
$this->system = $system;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSystem() {
|
public function getSystem(): string {
|
||||||
return $this->system;
|
return $this->system;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllowedImportSystems(): array {
|
public function getAllowedImportSystems(): array {
|
||||||
if (!$this->allowedSystems) {
|
if (!$this->allowedSystems) {
|
||||||
$allowedSystems = glob(__DIR__ . '/BoardImport*Service.php');
|
$allowedSystems = glob(__DIR__ . '/BoardImport*Service.php');
|
||||||
$allowedSystems = array_filter($allowedSystems, function ($name) {
|
$allowedSystems = array_filter($allowedSystems, function (string $name) {
|
||||||
$name = basename($name);
|
$name = basename($name);
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'ABoardImportService.php':
|
case 'ABoardImportService.php':
|
||||||
@@ -165,6 +178,9 @@ class BoardImportService {
|
|||||||
|
|
||||||
public function getImportSystem(): ABoardImportService {
|
public function getImportSystem(): ABoardImportService {
|
||||||
$systemClass = 'OCA\\Deck\\Service\\BoardImport' . ucfirst($this->getSystem()) . 'Service';
|
$systemClass = 'OCA\\Deck\\Service\\BoardImport' . ucfirst($this->getSystem()) . 'Service';
|
||||||
|
if (!$this->getSystem()) {
|
||||||
|
throw new NotFoundException('System to import not found');
|
||||||
|
}
|
||||||
if (!is_object($this->systemInstance)) {
|
if (!is_object($this->systemInstance)) {
|
||||||
$this->systemInstance = \OC::$server->get($systemClass);
|
$this->systemInstance = \OC::$server->get($systemClass);
|
||||||
$this->systemInstance->setImportService($this);
|
$this->systemInstance->setImportService($this);
|
||||||
@@ -173,22 +189,21 @@ class BoardImportService {
|
|||||||
return $this->systemInstance;
|
return $this->systemInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setImportSystem($instance) {
|
public function setImportSystem(ABoardImportService $instance): void {
|
||||||
$this->systemInstance = $instance;
|
$this->systemInstance = $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insertAssignment($assignment): self {
|
public function insertAssignment(Assignment $assignment): self {
|
||||||
$this->assignmentMapper->insert($assignment);
|
$this->assignmentMapper->insert($assignment);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importBoard() {
|
public function importBoard(): void {
|
||||||
$board = $this->getImportSystem()->getBoard();
|
$board = $this->getImportSystem()->getBoard();
|
||||||
if ($board) {
|
if ($board) {
|
||||||
$this->boardMapper->insert($board);
|
$this->boardMapper->insert($board);
|
||||||
$this->board = $board;
|
$this->board = $board;
|
||||||
}
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoard(): Board {
|
public function getBoard(): Board {
|
||||||
@@ -210,7 +225,7 @@ class BoardImportService {
|
|||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createLabel($title, $color, $boardId): Label {
|
public function createLabel(string $title, string $color, int $boardId): Entity {
|
||||||
$label = new Label();
|
$label = new Label();
|
||||||
$label->setTitle($title);
|
$label->setTitle($title);
|
||||||
$label->setColor($color);
|
$label->setColor($color);
|
||||||
@@ -240,6 +255,11 @@ class BoardImportService {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $cardId
|
||||||
|
* @param mixed $labelId
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function assignCardToLabel($cardId, $labelId): self {
|
public function assignCardToLabel($cardId, $labelId): self {
|
||||||
$this->cardMapper->assignLabel(
|
$this->cardMapper->assignLabel(
|
||||||
$cardId,
|
$cardId,
|
||||||
@@ -248,18 +268,16 @@ class BoardImportService {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assignCardsToLabels(): self {
|
public function assignCardsToLabels(): void {
|
||||||
$this->getImportSystem()->assignCardsToLabels();
|
$this->getImportSystem()->assignCardsToLabels();
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importComments(): self {
|
public function importComments(): void {
|
||||||
$this->getImportSystem()->importComments();
|
$this->getImportSystem()->importComments();
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insertComment($cardId, $comment) {
|
public function insertComment(string $cardId, Comment $comment): void {
|
||||||
$comment->setObject('deckCard', (string) $cardId);
|
$comment->setObject('deckCard', $cardId);
|
||||||
$comment->setVerb('comment');
|
$comment->setVerb('comment');
|
||||||
// Check if parent is a comment on the same card
|
// Check if parent is a comment on the same card
|
||||||
if ($comment->getParentId() !== '0') {
|
if ($comment->getParentId() !== '0') {
|
||||||
@@ -298,7 +316,6 @@ class BoardImportService {
|
|||||||
if ($affectedRows > 0) {
|
if ($affectedRows > 0) {
|
||||||
$comment->setId((string)$qb->getLastInsertId());
|
$comment->setId((string)$qb->getLastInsertId());
|
||||||
}
|
}
|
||||||
return $comment;
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
throw new BadRequestException('Invalid input values');
|
throw new BadRequestException('Invalid input values');
|
||||||
} catch (CommentNotFoundException $e) {
|
} catch (CommentNotFoundException $e) {
|
||||||
@@ -306,16 +323,15 @@ class BoardImportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importParticipants() {
|
public function importParticipants(): void {
|
||||||
$this->getImportSystem()->importParticipants();
|
$this->getImportSystem()->importParticipants();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setData(\stdClass $data): self {
|
final public function setData(\stdClass $data): void {
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getData() {
|
public function getData(): \stdClass {
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,14 +340,13 @@ class BoardImportService {
|
|||||||
*
|
*
|
||||||
* @param string $configName
|
* @param string $configName
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return self
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setConfig(string $configName, $value): self {
|
public function setConfig(string $configName, $value): void {
|
||||||
if (!$this->config) {
|
if (empty((array) $this->config)) {
|
||||||
$this->setConfigInstance(new \stdClass);
|
$this->setConfigInstance(new \stdClass);
|
||||||
}
|
}
|
||||||
$this->config->$configName = $value;
|
$this->config->$configName = $value;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,32 +356,37 @@ class BoardImportService {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getConfig(string $configName = null) {
|
public function getConfig(string $configName = null) {
|
||||||
if (!is_object($this->config) || !$configName) {
|
|
||||||
return $this->config;
|
|
||||||
}
|
|
||||||
if (!property_exists($this->config, $configName)) {
|
if (!property_exists($this->config, $configName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $this->config->$configName;
|
return $this->config->$configName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $config
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function setConfigInstance($config): self {
|
public function setConfigInstance($config): self {
|
||||||
$this->config = $config;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function validateConfig() {
|
|
||||||
$config = $this->getConfig();
|
|
||||||
if (empty($config)) {
|
|
||||||
throw new NotFoundException('Please inform a valid config json file');
|
|
||||||
}
|
|
||||||
if (is_string($config)) {
|
if (is_string($config)) {
|
||||||
if (!is_file($config)) {
|
if (!is_file($config)) {
|
||||||
throw new NotFoundException('Please inform a valid config json file');
|
throw new NotFoundException('Please inform a valid config json file');
|
||||||
}
|
}
|
||||||
$config = json_decode(file_get_contents($config));
|
$config = json_decode(file_get_contents($config));
|
||||||
|
if (!is_object($config)) {
|
||||||
|
throw new NotFoundException('Please inform a valid config json file');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$schemaPath = __DIR__ . '/fixtures/config-' . $this->getSystem() . '-schema.json';
|
$this->config = $config;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfigInstance(): \stdClass {
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateConfig(): void {
|
||||||
|
$config = $this->getConfigInstance();
|
||||||
|
$schemaPath = $this->getJsonSchemaPath();
|
||||||
$validator = new Validator();
|
$validator = new Validator();
|
||||||
$newConfig = clone $config;
|
$newConfig = clone $config;
|
||||||
$validator->validate(
|
$validator->validate(
|
||||||
@@ -381,17 +401,19 @@ class BoardImportService {
|
|||||||
$this->validateOwner();
|
$this->validateOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateOwner(): self {
|
public function getJsonSchemaPath(): string {
|
||||||
|
return __DIR__ . '/fixtures/config-' . $this->getSystem() . '-schema.json';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateOwner(): void {
|
||||||
$owner = $this->userManager->get($this->getConfig('owner'));
|
$owner = $this->userManager->get($this->getConfig('owner'));
|
||||||
if (!$owner) {
|
if (!$owner) {
|
||||||
throw new \LogicException('Owner "' . $this->getConfig('owner')->getUID() . '" not found on Nextcloud. Check setting json.');
|
throw new \LogicException('Owner "' . $this->getConfig('owner')->getUID() . '" not found on Nextcloud. Check setting json.');
|
||||||
}
|
}
|
||||||
$this->setConfig('owner', $owner);
|
$this->setConfig('owner', $owner);
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateUsers(): self {
|
public function validateUsers(): void {
|
||||||
$this->getImportSystem()->validateUsers();
|
$this->getImportSystem()->validateUsers();
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ use OCA\Deck\Db\Board;
|
|||||||
use OCA\Deck\Db\Card;
|
use OCA\Deck\Db\Card;
|
||||||
use OCA\Deck\Db\Label;
|
use OCA\Deck\Db\Label;
|
||||||
use OCA\Deck\Db\Stack;
|
use OCA\Deck\Db\Stack;
|
||||||
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
@@ -47,9 +48,9 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
*/
|
*/
|
||||||
private $stacks = [];
|
private $stacks = [];
|
||||||
/**
|
/**
|
||||||
* Array of labels
|
* Array of Labels
|
||||||
*
|
*
|
||||||
* @var Label[]
|
* @var Label[]|Entity[]
|
||||||
*/
|
*/
|
||||||
private $labels = [];
|
private $labels = [];
|
||||||
/** @var Card[] */
|
/** @var Card[] */
|
||||||
@@ -65,15 +66,12 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function validateUsers(): void {
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function validateUsers(): self {
|
|
||||||
if (empty($this->getImportService()->getConfig('uidRelation'))) {
|
if (empty($this->getImportService()->getConfig('uidRelation'))) {
|
||||||
return $this;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($this->getImportService()->getConfig('uidRelation') as $trelloUid => $nextcloudUid) {
|
foreach ($this->getImportService()->getConfig('uidRelation') as $trelloUid => $nextcloudUid) {
|
||||||
$user = array_filter($this->getImportService()->getData()->members, function ($u) use ($trelloUid) {
|
$user = array_filter($this->getImportService()->getData()->members, function (\stdClass $u) use ($trelloUid) {
|
||||||
return $u->username === $trelloUid;
|
return $u->username === $trelloUid;
|
||||||
});
|
});
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@@ -82,6 +80,7 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
if (!is_string($nextcloudUid) && !is_numeric($nextcloudUid)) {
|
if (!is_string($nextcloudUid) && !is_numeric($nextcloudUid)) {
|
||||||
throw new \LogicException('User on setting uidRelation is invalid');
|
throw new \LogicException('User on setting uidRelation is invalid');
|
||||||
}
|
}
|
||||||
|
$nextcloudUid = (string) $nextcloudUid;
|
||||||
$this->getImportService()->getConfig('uidRelation')->$trelloUid = $this->userManager->get($nextcloudUid);
|
$this->getImportService()->getConfig('uidRelation')->$trelloUid = $this->userManager->get($nextcloudUid);
|
||||||
if (!$this->getImportService()->getConfig('uidRelation')->$trelloUid) {
|
if (!$this->getImportService()->getConfig('uidRelation')->$trelloUid) {
|
||||||
throw new \LogicException('User on setting uidRelation not found: ' . $nextcloudUid);
|
throw new \LogicException('User on setting uidRelation not found: ' . $nextcloudUid);
|
||||||
@@ -89,7 +88,6 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
$user = current($user);
|
$user = current($user);
|
||||||
$this->members[$user->id] = $this->getImportService()->getConfig('uidRelation')->$trelloUid;
|
$this->members[$user->id] = $this->getImportService()->getConfig('uidRelation')->$trelloUid;
|
||||||
}
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +111,7 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checklistItem($item): string {
|
private function checklistItem(\stdClass $item): string {
|
||||||
if (($item->state == 'incomplete')) {
|
if (($item->state == 'incomplete')) {
|
||||||
$string_start = '- [ ]';
|
$string_start = '- [ ]';
|
||||||
} else {
|
} else {
|
||||||
@@ -123,7 +121,7 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
return $check_item_string;
|
return $check_item_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formulateChecklistText($checklist): string {
|
private function formulateChecklistText(\stdClass $checklist): string {
|
||||||
$checklist_string = "\n\n## {$checklist->name}\n";
|
$checklist_string = "\n\n## {$checklist->name}\n";
|
||||||
foreach ($checklist->checkItems as $item) {
|
foreach ($checklist->checkItems as $item) {
|
||||||
$checklist_item_string = $this->checklistItem($item);
|
$checklist_item_string = $this->checklistItem($item);
|
||||||
@@ -175,17 +173,13 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
return $this->cards;
|
return $this->cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateCard($id, Card $card): self {
|
public function updateCard(string $id, Card $card): void {
|
||||||
$this->cards[$id] = $card;
|
$this->cards[$id] = $card;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function appendAttachmentsToDescription(\stdClass $trelloCard): void {
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
private function appendAttachmentsToDescription($trelloCard): self {
|
|
||||||
if (empty($trelloCard->attachments)) {
|
if (empty($trelloCard->attachments)) {
|
||||||
return $this;
|
return;
|
||||||
}
|
}
|
||||||
$trelloCard->desc .= "\n\n## {$this->l10n->t('Attachments')}\n";
|
$trelloCard->desc .= "\n\n## {$this->l10n->t('Attachments')}\n";
|
||||||
$trelloCard->desc .= "| {$this->l10n->t('File')} | {$this->l10n->t('date')} |\n";
|
$trelloCard->desc .= "| {$this->l10n->t('File')} | {$this->l10n->t('date')} |\n";
|
||||||
@@ -194,10 +188,9 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
$name = $attachment->name === $attachment->url ? null : $attachment->name;
|
$name = $attachment->name === $attachment->url ? null : $attachment->name;
|
||||||
$trelloCard->desc .= "| [{$name}]({$attachment->url}) | {$attachment->date} |\n";
|
$trelloCard->desc .= "| [{$name}]({$attachment->url}) | {$attachment->date} |\n";
|
||||||
}
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importParticipants(): self {
|
public function importParticipants(): void {
|
||||||
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
||||||
foreach ($trelloCard->idMembers as $idMember) {
|
foreach ($trelloCard->idMembers as $idMember) {
|
||||||
if (empty($this->members[$idMember])) {
|
if (empty($this->members[$idMember])) {
|
||||||
@@ -210,14 +203,13 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
$this->getImportService()->insertAssignment($assignment);
|
$this->getImportService()->insertAssignment($assignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importComments() {
|
public function importComments(): void {
|
||||||
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
||||||
$comments = array_filter(
|
$comments = array_filter(
|
||||||
$this->getImportService()->getData()->actions,
|
$this->getImportService()->getData()->actions,
|
||||||
function ($a) use ($trelloCard) {
|
function (\stdClass $a) use ($trelloCard) {
|
||||||
return $a->type === 'commentCard' && $a->data->card->id === $trelloCard->id;
|
return $a->type === 'commentCard' && $a->data->card->id === $trelloCard->id;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -235,21 +227,21 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
\DateTime::createFromFormat('Y-m-d\TH:i:s.v\Z', $trelloComment->date)
|
\DateTime::createFromFormat('Y-m-d\TH:i:s.v\Z', $trelloComment->date)
|
||||||
);
|
);
|
||||||
$this->getImportService()->insertComment(
|
$this->getImportService()->insertComment(
|
||||||
$this->cards[$trelloCard->id]->getId(),
|
(string) $this->cards[$trelloCard->id]->getId(),
|
||||||
$comment
|
$comment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function replaceUsernames($text) {
|
private function replaceUsernames(string $text): string {
|
||||||
foreach ($this->getImportService()->getConfig('uidRelation') as $trello => $nextcloud) {
|
foreach ($this->getImportService()->getConfig('uidRelation') as $trello => $nextcloud) {
|
||||||
$text = str_replace($trello, $nextcloud->getUID(), $text);
|
$text = str_replace($trello, $nextcloud->getUID(), $text);
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assignCardsToLabels(): self {
|
public function assignCardsToLabels(): void {
|
||||||
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
||||||
foreach ($trelloCard->labels as $label) {
|
foreach ($trelloCard->labels as $label) {
|
||||||
$this->getImportService()->assignCardToLabel(
|
$this->getImportService()->assignCardToLabel(
|
||||||
@@ -258,7 +250,6 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,12 +270,11 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateStack($id, $stack): self {
|
public function updateStack(string $id, Stack $stack): void {
|
||||||
$this->stacks[$id] = $stack;
|
$this->stacks[$id] = $stack;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateColor($color): string {
|
private function translateColor(string $color): string {
|
||||||
switch ($color) {
|
switch ($color) {
|
||||||
case 'red':
|
case 'red':
|
||||||
return 'ff0000';
|
return 'ff0000';
|
||||||
@@ -313,7 +303,7 @@ class BoardImportTrelloService extends ABoardImportService {
|
|||||||
|
|
||||||
public function getBoard(): Board {
|
public function getBoard(): Board {
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
if (!$this->getImportService()->getData()->name) {
|
if (empty($this->getImportService()->getData()->name)) {
|
||||||
throw new BadRequestException('Invalid name of board');
|
throw new BadRequestException('Invalid name of board');
|
||||||
}
|
}
|
||||||
$board->setTitle($this->getImportService()->getData()->name);
|
$board->setTitle($this->getImportService()->getData()->name);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ use OCA\Deck\Db\LabelMapper;
|
|||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCP\Comments\ICommentsManager;
|
use OCP\Comments\ICommentsManager;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class BoardImportServiceTest extends \Test\TestCase {
|
class BoardImportServiceTest extends \Test\TestCase {
|
||||||
@@ -83,8 +84,32 @@ class BoardImportServiceTest extends \Test\TestCase {
|
|||||||
$importService
|
$importService
|
||||||
->method('getBoard')
|
->method('getBoard')
|
||||||
->willReturn($board);
|
->willReturn($board);
|
||||||
|
$this->boardImportService->setSystem('trello');
|
||||||
$this->boardImportService->setImportSystem($importService);
|
$this->boardImportService->setImportSystem($importService);
|
||||||
$actual = $this->boardImportService->import();
|
$actual = $this->boardImportService->import();
|
||||||
$this->assertNull($actual);
|
$this->assertNull($actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testImportBoard() {
|
||||||
|
$this->boardImportService->setSystem('trello');
|
||||||
|
$data = json_decode(file_get_contents(__DIR__ . '/../../data/data-trello.json'));
|
||||||
|
$this->boardImportService->setData($data);
|
||||||
|
$configInstance = json_decode(file_get_contents(__DIR__ . '/../../data/config-trello.json'));
|
||||||
|
$this->boardImportService->setConfigInstance($configInstance);
|
||||||
|
|
||||||
|
$owner = $this->createMock(IUser::class);
|
||||||
|
$owner
|
||||||
|
->method('getUID')
|
||||||
|
->willReturn('owner');
|
||||||
|
$this->userManager
|
||||||
|
->method('get')
|
||||||
|
->willReturn($owner);
|
||||||
|
$this->boardImportService->validateOwner();
|
||||||
|
$actual = $this->boardImportService->importBoard();
|
||||||
|
$this->assertNull($actual);
|
||||||
|
$board = $this->boardImportService->getBoard();
|
||||||
|
$this->assertEquals('Test Board Name', $board->getTitle());
|
||||||
|
$this->assertEquals('owner', $board->getOwner());
|
||||||
|
$this->assertEquals('0800fd', $board->getColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace OCA\Deck\Service;
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
|
use OCA\Deck\Db\Board;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
@@ -46,7 +47,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
|||||||
$importService = $this->createMock(BoardImportService::class);
|
$importService = $this->createMock(BoardImportService::class);
|
||||||
$this->service->setImportService($importService);
|
$this->service->setImportService($importService);
|
||||||
$actual = $this->service->validateUsers();
|
$actual = $this->service->validateUsers();
|
||||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
$this->assertNull($actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateUsersWithInvalidUser() {
|
public function testValidateUsersWithInvalidUser() {
|
||||||
@@ -59,17 +60,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
|||||||
]);
|
]);
|
||||||
$importService
|
$importService
|
||||||
->method('getData')
|
->method('getData')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"members": [{"username": "othre_trello_user"}]}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"username": "othre_trello_user"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$this->service->setImportService($importService);
|
$this->service->setImportService($importService);
|
||||||
$actual = $this->service->validateUsers();
|
$actual = $this->service->validateUsers();
|
||||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||||
@@ -85,17 +76,7 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
|||||||
]);
|
]);
|
||||||
$importService
|
$importService
|
||||||
->method('getData')
|
->method('getData')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"members": [{"username": "trello_user"}]}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"username": "trello_user"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$this->service->setImportService($importService);
|
$this->service->setImportService($importService);
|
||||||
$actual = $this->service->validateUsers();
|
$actual = $this->service->validateUsers();
|
||||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||||
@@ -106,26 +87,10 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
|||||||
$importService = $this->createMock(BoardImportService::class);
|
$importService = $this->createMock(BoardImportService::class);
|
||||||
$importService
|
$importService
|
||||||
->method('getConfig')
|
->method('getConfig')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"trello_user": "nextcloud_user"}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"trello_user": "nextcloud_user"
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$importService
|
$importService
|
||||||
->method('getData')
|
->method('getData')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"members": [{"username": "trello_user"}]}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"username": "trello_user"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$this->service->setImportService($importService);
|
$this->service->setImportService($importService);
|
||||||
$actual = $this->service->validateUsers();
|
$actual = $this->service->validateUsers();
|
||||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
||||||
@@ -135,35 +100,53 @@ class BoardImportTrelloServiceTest extends \Test\TestCase {
|
|||||||
$importService = $this->createMock(BoardImportService::class);
|
$importService = $this->createMock(BoardImportService::class);
|
||||||
$importService
|
$importService
|
||||||
->method('getConfig')
|
->method('getConfig')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"trello_user": "nextcloud_user"}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"trello_user": "nextcloud_user"
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$importService
|
$importService
|
||||||
->method('getData')
|
->method('getData')
|
||||||
->willReturn(json_decode(
|
->willReturn(json_decode('{"members": [{"id": "fakeid", "username": "trello_user"}]}'));
|
||||||
<<<JSON
|
|
||||||
{
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"id": "fakeid",
|
|
||||||
"username": "trello_user"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
));
|
|
||||||
$fakeUser = $this->createMock(IUser::class);
|
$fakeUser = $this->createMock(IUser::class);
|
||||||
$this->userManager
|
$this->userManager
|
||||||
// ->expects($this->once())
|
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('nextcloud_user')
|
->with('nextcloud_user')
|
||||||
->willReturn($fakeUser);
|
->willReturn($fakeUser);
|
||||||
$this->service->setImportService($importService);
|
$this->service->setImportService($importService);
|
||||||
$actual = $this->service->validateUsers();
|
$actual = $this->service->validateUsers();
|
||||||
$this->assertInstanceOf(BoardImportTrelloService::class, $actual);
|
$this->assertNull($actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBoardWithSuccess() {
|
||||||
|
$importService = $this->createMock(BoardImportService::class);
|
||||||
|
$owner = $this->createMock(IUser::class);
|
||||||
|
$owner
|
||||||
|
->method('getUID')
|
||||||
|
->willReturn('owner');
|
||||||
|
$importService
|
||||||
|
->method('getConfig')
|
||||||
|
->withConsecutive(
|
||||||
|
['owner'],
|
||||||
|
['color']
|
||||||
|
)->willReturnonConsecutiveCalls(
|
||||||
|
$owner,
|
||||||
|
'000000'
|
||||||
|
);
|
||||||
|
$importService
|
||||||
|
->method('getData')
|
||||||
|
->willReturn(json_decode('{"name": "test"}'));
|
||||||
|
$this->service->setImportService($importService);
|
||||||
|
$actual = $this->service->getBoard();
|
||||||
|
$this->assertInstanceOf(Board::class, $actual);
|
||||||
|
$this->assertEquals('test', $actual->getTitle());
|
||||||
|
$this->assertEquals('owner', $actual->getOwner());
|
||||||
|
$this->assertEquals('000000', $actual->getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBoardWithInvalidName() {
|
||||||
|
$this->expectErrorMessage('Invalid name of board');
|
||||||
|
$importService = $this->createMock(BoardImportService::class);
|
||||||
|
$importService
|
||||||
|
->method('getData')
|
||||||
|
->willReturn(new \stdClass);
|
||||||
|
$this->service->setImportService($importService);
|
||||||
|
$this->service->getBoard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user