Translations and tests

Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
Vitor Mattos
2021-07-11 01:47:45 -03:00
committed by Julius Härtl
parent e28a47e9e0
commit eb8bf3f22b
3 changed files with 20 additions and 17 deletions

View File

@@ -36,6 +36,7 @@ use OCA\Deck\Db\StackMapper;
use OCA\Deck\Service\BoardService; use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\LabelService; use OCA\Deck\Service\LabelService;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -57,12 +58,12 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
private $connection; private $connection;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var TrelloActions */
private $trelloActions;
/** @var Board */ /** @var Board */
private $board; private $board;
/** @var LabelService */ /** @var LabelService */
private $labelService; private $labelService;
/** @var IL10N */
private $l10n;
/** /**
* Data object created from JSON of origin system * Data object created from JSON of origin system
* *
@@ -83,7 +84,7 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
private $labels = []; private $labels = [];
/** @var Card[] */ /** @var Card[] */
private $cards = []; private $cards = [];
/** @var IUser */ /** @var IUser[] */
private $members = []; private $members = [];
public function __construct( public function __construct(
@@ -94,7 +95,8 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
AssignmentMapper $assignmentMapper, AssignmentMapper $assignmentMapper,
AclMapper $aclMapper, AclMapper $aclMapper,
IDBConnection $connection, IDBConnection $connection,
IUserManager $userManager IUserManager $userManager,
IL10N $l10n
) { ) {
$this->boardService = $boardService; $this->boardService = $boardService;
$this->labelService = $labelService; $this->labelService = $labelService;
@@ -104,6 +106,7 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
$this->aclMapper = $aclMapper; $this->aclMapper = $aclMapper;
$this->connection = $connection; $this->connection = $connection;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->l10n = $l10n;
} }
public function validate(InputInterface $input, OutputInterface $output): void { public function validate(InputInterface $input, OutputInterface $output): void {
@@ -127,7 +130,7 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
$this->importCards(); $this->importCards();
} }
private function assignUsersToBoard() { private function assignUsersToBoard(): void {
foreach ($this->members as $member) { foreach ($this->members as $member) {
$acl = new Acl(); $acl = new Acl();
$acl->setBoardId($this->board->getId()); $acl->setBoardId($this->board->getId());
@@ -260,17 +263,15 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
} }
} }
/**
* @return void
*/
private function appendAttachmentsToDescription($trelloCard) { private function appendAttachmentsToDescription($trelloCard) {
if (empty($trelloCard->attachments)) { if (empty($trelloCard->attachments)) {
return; return;
} }
$translations = $this->getSetting('translations'); $trelloCard->desc .= "\n\n## {$this->l10n->t('Attachments')}\n";
$attachmentsLabel = empty($translations->{'Attachments'}) ? 'Attachments' : $translations->{'Attachments'}; $trelloCard->desc .= "| {$this->l10n->t('URL')} | {$this->l10n->t('Name')} | {$this->l10n->t('date')} |\n";
$URLLabel = empty($translations->{'URL'}) ? 'URL' : $translations->{'URL'};
$nameLabel = empty($translations->{'Name'}) ? 'Name' : $translations->{'Name'};
$dateLabel = empty($translations->{'Date'}) ? 'Date' : $translations->{'Date'};
$trelloCard->desc .= "\n\n## {$attachmentsLabel}\n";
$trelloCard->desc .= "| $URLLabel | $nameLabel | $dateLabel |\n";
$trelloCard->desc .= "|---|---|---|\n"; $trelloCard->desc .= "|---|---|---|\n";
foreach ($trelloCard->attachments as $attachment) { foreach ($trelloCard->attachments as $attachment) {
$name = $attachment->name === $attachment->url ? null : $attachment->name; $name = $attachment->name === $attachment->url ? null : $attachment->name;
@@ -278,7 +279,7 @@ class TrelloHelper extends ImportAbstract implements ImportInterface {
} }
} }
private function assignToMember(Card $card, $trelloCard) { private function assignToMember(Card $card, $trelloCard): void {
foreach ($trelloCard->idMembers as $idMember) { foreach ($trelloCard->idMembers as $idMember) {
$assignment = new Assignment(); $assignment = new Assignment();
$assignment->setCardId($card->getId()); $assignment->setCardId($card->getId());

View File

@@ -12,9 +12,6 @@
"type": "string", "type": "string",
"required": true, "required": true,
"pattern": "^[0-9a-fA-F]{6}$" "pattern": "^[0-9a-fA-F]{6}$"
},
"translations": {
"type": "object"
} }
} }
} }

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\StackMapper;
use OCA\Deck\Service\BoardService; use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\LabelService; use OCA\Deck\Service\LabelService;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager; use OCP\IUserManager;
use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
@@ -52,6 +53,8 @@ class TrelloHelperTest extends \Test\TestCase {
private $userManager; private $userManager;
/** @var TrelloHelper */ /** @var TrelloHelper */
private $trelloHelper; private $trelloHelper;
/** @var IL10N */
private $l10n;
public function setUp(): void { public function setUp(): void {
parent::setUp(); parent::setUp();
$this->boardService = $this->createMock(BoardService::class); $this->boardService = $this->createMock(BoardService::class);
@@ -62,6 +65,7 @@ class TrelloHelperTest extends \Test\TestCase {
$this->aclMapper = $this->createMock(AclMapper::class); $this->aclMapper = $this->createMock(AclMapper::class);
$this->connection = $this->createMock(IDBConnection::class); $this->connection = $this->createMock(IDBConnection::class);
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->l10n = $this->createMock(IL10N::class);
$this->trelloHelper = new TrelloHelper( $this->trelloHelper = new TrelloHelper(
$this->boardService, $this->boardService,
$this->labelService, $this->labelService,
@@ -70,7 +74,8 @@ class TrelloHelperTest extends \Test\TestCase {
$this->assignmentMapper, $this->assignmentMapper,
$this->aclMapper, $this->aclMapper,
$this->connection, $this->connection,
$this->userManager $this->userManager,
$this->l10n
); );
$questionHelper = new QuestionHelper(); $questionHelper = new QuestionHelper();
$command = new BoardImport($this->trelloHelper); $command = new BoardImport($this->trelloHelper);