mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Code consistency and new tests.
This commit is contained in:
@@ -178,7 +178,7 @@ class JobConfigurationController extends Controller
|
|||||||
Log::debug(sprintf('Going to create class "%s"', $className));
|
Log::debug(sprintf('Going to create class "%s"', $className));
|
||||||
/** @var JobConfigurationInterface $configurator */
|
/** @var JobConfigurationInterface $configurator */
|
||||||
$configurator = app($className);
|
$configurator = app($className);
|
||||||
$configurator->setJob($importJob);
|
$configurator->setImportJob($importJob);
|
||||||
|
|
||||||
return $configurator;
|
return $configurator;
|
||||||
}
|
}
|
||||||
|
@@ -143,7 +143,7 @@ class JobStatusController extends Controller
|
|||||||
|
|
||||||
/** @var RoutineInterface $routine */
|
/** @var RoutineInterface $routine */
|
||||||
$routine = app($className);
|
$routine = app($className);
|
||||||
$routine->setJob($importJob);
|
$routine->setImportJob($importJob);
|
||||||
try {
|
try {
|
||||||
$routine->run();
|
$routine->run();
|
||||||
} catch (FireflyException|Exception $e) {
|
} catch (FireflyException|Exception $e) {
|
||||||
@@ -213,7 +213,7 @@ class JobStatusController extends Controller
|
|||||||
{
|
{
|
||||||
/** @var ImportArrayStorage $storage */
|
/** @var ImportArrayStorage $storage */
|
||||||
$storage = app(ImportArrayStorage::class);
|
$storage = app(ImportArrayStorage::class);
|
||||||
$storage->setJob($importJob);
|
$storage->setImportJob($importJob);
|
||||||
try {
|
try {
|
||||||
$storage->store();
|
$storage->store();
|
||||||
} catch (FireflyException|Exception $e) {
|
} catch (FireflyException|Exception $e) {
|
||||||
|
@@ -1,377 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* CsvProcessor.php
|
|
||||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This file is part of Firefly III.
|
|
||||||
*
|
|
||||||
* Firefly III is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Firefly III 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace FireflyIII\Import\FileProcessor;
|
|
||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Import\Object\ImportJournal;
|
|
||||||
use FireflyIII\Import\Specifics\SpecificInterface;
|
|
||||||
use FireflyIII\Models\ImportJob;
|
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use League\Csv\Reader;
|
|
||||||
use League\Csv\Statement;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* Class CsvProcessor, as the name suggests, goes over CSV file line by line and creates
|
|
||||||
* "ImportJournal" objects, which are used in another step to create new journals and transactions
|
|
||||||
* and what-not.
|
|
||||||
*/
|
|
||||||
class CsvProcessor implements FileProcessorInterface
|
|
||||||
{
|
|
||||||
/** @var ImportJob */
|
|
||||||
private $job;
|
|
||||||
/** @var Collection */
|
|
||||||
private $objects;
|
|
||||||
/** @var ImportJobRepositoryInterface */
|
|
||||||
private $repository;
|
|
||||||
/** @var array */
|
|
||||||
private $validConverters;
|
|
||||||
/** @var array */
|
|
||||||
private $validSpecifics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FileProcessorInterface constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->objects = new Collection;
|
|
||||||
$this->validSpecifics = array_keys(config('csv.import_specifics'));
|
|
||||||
$this->validConverters = array_keys(config('csv.import_roles'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function getObjects(): Collection
|
|
||||||
{
|
|
||||||
if (null === $this->job) {
|
|
||||||
throw new FireflyException('Cannot call getObjects() without a job.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does the actual job.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
* @throws \League\Csv\Exception
|
|
||||||
*/
|
|
||||||
public function run(): bool
|
|
||||||
{
|
|
||||||
if (null === $this->job) {
|
|
||||||
throw new FireflyException('Cannot call run() without a job.');
|
|
||||||
}
|
|
||||||
Log::debug('Now in CsvProcessor run(). Job is now running...');
|
|
||||||
|
|
||||||
$entries = new Collection($this->getImportArray());
|
|
||||||
$this->addStep();
|
|
||||||
Log::notice('Building importable objects from CSV file.');
|
|
||||||
Log::debug(sprintf('Number of entries: %d', $entries->count()));
|
|
||||||
$notImported = $entries->filter(
|
|
||||||
function (array $row, int $index) {
|
|
||||||
$row = array_values($row);
|
|
||||||
if ($this->rowAlreadyImported($row)) {
|
|
||||||
$message = sprintf('Row #%d has already been imported.', $index);
|
|
||||||
$this->repository->addError($this->job, $index, $message);
|
|
||||||
Log::info($message);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$this->addStep();
|
|
||||||
Log::debug(sprintf('Number of entries left: %d', $notImported->count()));
|
|
||||||
|
|
||||||
$notImported->each(
|
|
||||||
function (array $row, int $index) {
|
|
||||||
$journal = $this->importRow($index, $row);
|
|
||||||
$this->objects->push($journal);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$this->addStep();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to set the extended status.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*/
|
|
||||||
public function setExtendedStatus(array $array): void
|
|
||||||
{
|
|
||||||
$this->repository->setExtendedStatus($this->job, $array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set import job for this processor.
|
|
||||||
*
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return FileProcessorInterface
|
|
||||||
*/
|
|
||||||
public function setJob(ImportJob $job): FileProcessorInterface
|
|
||||||
{
|
|
||||||
$this->job = $job;
|
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
|
||||||
$this->repository->setUser($job->user);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to add a step.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
private function addStep()
|
|
||||||
{
|
|
||||||
$this->repository->addStepsDone($this->job, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add meta data to the individual value and verify that it can be handled in a later stage.
|
|
||||||
*
|
|
||||||
* @param int $index
|
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function annotateValue(int $index, string $value)
|
|
||||||
{
|
|
||||||
$config = $this->getConfig();
|
|
||||||
$role = $config['column-roles'][$index] ?? '_ignore';
|
|
||||||
$mapped = $config['column-mapping-config'][$index][$value] ?? null;
|
|
||||||
|
|
||||||
// throw error when not a valid converter.
|
|
||||||
if (!\in_array($role, $this->validConverters)) {
|
|
||||||
throw new FireflyException(sprintf('"%s" is not a valid role.', $role));
|
|
||||||
}
|
|
||||||
|
|
||||||
$entry = [
|
|
||||||
'role' => $role,
|
|
||||||
'value' => $value,
|
|
||||||
'mapped' => $mapped,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to return configuration.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getConfig(): array
|
|
||||||
{
|
|
||||||
return $this->repository->getConfiguration($this->job);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws \League\Csv\Exception
|
|
||||||
* @throws \League\Csv\Exception
|
|
||||||
*/
|
|
||||||
private function getImportArray(): array
|
|
||||||
{
|
|
||||||
$content = $this->repository->uploadFileContents($this->job);
|
|
||||||
$config = $this->getConfig();
|
|
||||||
$reader = Reader::createFromString($content);
|
|
||||||
$delimiter = $config['delimiter'] ?? ',';
|
|
||||||
$hasHeaders = $config['has-headers'] ?? false;
|
|
||||||
$offset = 0;
|
|
||||||
if ('tab' === $delimiter) {
|
|
||||||
$delimiter = "\t"; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
$reader->setDelimiter($delimiter);
|
|
||||||
if ($hasHeaders) {
|
|
||||||
$offset = 1;
|
|
||||||
}
|
|
||||||
$stmt = (new Statement)->offset($offset);
|
|
||||||
$records = $stmt->process($reader);
|
|
||||||
$return = [];
|
|
||||||
foreach ($records as $record) {
|
|
||||||
$return[] = $record;
|
|
||||||
}
|
|
||||||
Log::debug('Created a CSV reader.');
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Will return string representation of JSON error code.
|
|
||||||
*
|
|
||||||
* @param int $jsonError
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getJsonError(int $jsonError): string
|
|
||||||
{
|
|
||||||
$messages = [
|
|
||||||
JSON_ERROR_NONE => 'No JSON error',
|
|
||||||
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
|
|
||||||
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
|
|
||||||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
|
|
||||||
JSON_ERROR_SYNTAX => 'Syntax error.',
|
|
||||||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
|
|
||||||
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
|
|
||||||
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
|
|
||||||
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
|
|
||||||
JSON_ERROR_INVALID_PROPERTY_NAME => 'A property name that cannot be encoded was given.',
|
|
||||||
JSON_ERROR_UTF16 => 'Malformed UTF-16 characters, possibly incorrectly encoded.',
|
|
||||||
];
|
|
||||||
if (isset($messages[$jsonError])) {
|
|
||||||
return $messages[$jsonError];
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'Unknown JSON error';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hash an array and return the result.
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function getRowHash(array $array): string
|
|
||||||
{
|
|
||||||
$json = json_encode($array);
|
|
||||||
$jsonError = json_last_error();
|
|
||||||
|
|
||||||
if (false === $json) {
|
|
||||||
throw new FireflyException(sprintf('Error while encoding JSON for CSV row: %s', $this->getJsonError($jsonError))); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash('sha256', $json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a row, build import journal by annotating each value and storing it in the import journal.
|
|
||||||
*
|
|
||||||
* @param int $index
|
|
||||||
* @param array $row
|
|
||||||
*
|
|
||||||
* @return ImportJournal
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function importRow(int $index, array $row): ImportJournal
|
|
||||||
{
|
|
||||||
$row = array_values($row);
|
|
||||||
Log::debug(sprintf('Now at row %d', $index));
|
|
||||||
$row = $this->specifics($row);
|
|
||||||
$hash = $this->getRowHash($row);
|
|
||||||
$config = $this->getConfig();
|
|
||||||
|
|
||||||
$journal = new ImportJournal;
|
|
||||||
$journal->setUser($this->job->user);
|
|
||||||
$journal->setHash($hash);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
* @var string $value
|
|
||||||
*/
|
|
||||||
foreach ($row as $rowIndex => $value) {
|
|
||||||
$value = trim((string)$value);
|
|
||||||
if (\strlen($value) > 0) {
|
|
||||||
$annotated = $this->annotateValue($rowIndex, $value);
|
|
||||||
Log::debug('Annotated value', $annotated);
|
|
||||||
$journal->setValue($annotated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set some extra info:
|
|
||||||
$importAccount = (int)($config['import-account'] ?? 0.0);
|
|
||||||
$journal->asset->setDefaultAccountId($importAccount);
|
|
||||||
|
|
||||||
return $journal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the row has not been imported before.
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function rowAlreadyImported(array $array): bool
|
|
||||||
{
|
|
||||||
$hash = $this->getRowHash($array);
|
|
||||||
$count = $this->repository->countByHash($hash);
|
|
||||||
Log::debug(sprintf('Hash is %s and count is %d', $hash, $count));
|
|
||||||
|
|
||||||
return $count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* And this is the point where the specifix go to work.
|
|
||||||
*
|
|
||||||
* @param array $row
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function specifics(array $row): array
|
|
||||||
{
|
|
||||||
$config = $this->getConfig();
|
|
||||||
$names = array_keys($config['specifics'] ?? []);
|
|
||||||
foreach ($names as $name) {
|
|
||||||
if (!\in_array($name, $this->validSpecifics)) {
|
|
||||||
throw new FireflyException(sprintf('"%s" is not a valid class name', $name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var SpecificInterface $specific */
|
|
||||||
$specific = app('FireflyIII\Import\Specifics\\' . $name);
|
|
||||||
|
|
||||||
// it returns the row, possibly modified:
|
|
||||||
$row = $specific->run($row);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* FileProcessorInterface.php
|
|
||||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This file is part of Firefly III.
|
|
||||||
*
|
|
||||||
* Firefly III is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Firefly III 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace FireflyIII\Import\FileProcessor;
|
|
||||||
|
|
||||||
use FireflyIII\Models\ImportJob;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface FileProcessorInterface.
|
|
||||||
*/
|
|
||||||
interface FileProcessorInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getObjects(): Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function run(): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return FileProcessorInterface
|
|
||||||
*/
|
|
||||||
public function setJob(ImportJob $job): FileProcessorInterface;
|
|
||||||
}
|
|
@@ -33,7 +33,7 @@ use Illuminate\Support\MessageBag;
|
|||||||
class FakeJobConfiguration implements JobConfigurationInterface
|
class FakeJobConfiguration implements JobConfigurationInterface
|
||||||
{
|
{
|
||||||
/** @var ImportJob */
|
/** @var ImportJob */
|
||||||
private $job;
|
private $importJob;
|
||||||
|
|
||||||
/** @var ImportJobRepositoryInterface */
|
/** @var ImportJobRepositoryInterface */
|
||||||
private $repository;
|
private $repository;
|
||||||
@@ -57,8 +57,8 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
|||||||
// 'artist' must be 'david bowie', case insensitive
|
// 'artist' must be 'david bowie', case insensitive
|
||||||
// 'song' must be 'golden years', case insensitive.
|
// 'song' must be 'golden years', case insensitive.
|
||||||
// if stage is not "new", then album must be 'station to station'
|
// if stage is not "new", then album must be 'station to station'
|
||||||
$config = $this->job->configuration;
|
$config = $this->importJob->configuration;
|
||||||
if ($this->job->stage === 'new') {
|
if ($this->importJob->stage === 'new') {
|
||||||
return (isset($config['artist']) && 'david bowie' === strtolower($config['artist']))
|
return (isset($config['artist']) && 'david bowie' === strtolower($config['artist']))
|
||||||
&& (isset($config['song']) && 'golden years' === strtolower($config['song']))
|
&& (isset($config['song']) && 'golden years' === strtolower($config['song']))
|
||||||
&& isset($config['apply-rules']);
|
&& isset($config['apply-rules']);
|
||||||
@@ -82,7 +82,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
|||||||
$song = strtolower($data['song'] ?? '');
|
$song = strtolower($data['song'] ?? '');
|
||||||
$album = strtolower($data['album'] ?? '');
|
$album = strtolower($data['album'] ?? '');
|
||||||
$applyRules = isset($data['apply_rules']) ? (int)$data['apply_rules'] === 1 : null;
|
$applyRules = isset($data['apply_rules']) ? (int)$data['apply_rules'] === 1 : null;
|
||||||
$configuration = $this->job->configuration;
|
$configuration = $this->importJob->configuration;
|
||||||
if ($artist === 'david bowie') {
|
if ($artist === 'david bowie') {
|
||||||
// store artist
|
// store artist
|
||||||
$configuration['artist'] = $artist;
|
$configuration['artist'] = $artist;
|
||||||
@@ -101,7 +101,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
|||||||
$configuration['apply-rules'] = $applyRules;
|
$configuration['apply-rules'] = $applyRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->repository->setConfiguration($this->job, $configuration);
|
$this->repository->setConfiguration($this->importJob, $configuration);
|
||||||
$messages = new MessageBag();
|
$messages = new MessageBag();
|
||||||
|
|
||||||
if (\count($configuration) !== 3) {
|
if (\count($configuration) !== 3) {
|
||||||
@@ -135,7 +135,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
|||||||
public function getNextView(): string
|
public function getNextView(): string
|
||||||
{
|
{
|
||||||
// first configure artist:
|
// first configure artist:
|
||||||
$config = $this->job->configuration;
|
$config = $this->importJob->configuration;
|
||||||
$artist = $config['artist'] ?? '';
|
$artist = $config['artist'] ?? '';
|
||||||
$song = $config['song'] ?? '';
|
$song = $config['song'] ?? '';
|
||||||
$album = $config['album'] ?? '';
|
$album = $config['album'] ?? '';
|
||||||
@@ -149,18 +149,18 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
|||||||
if (strtolower($song) !== 'golden years') {
|
if (strtolower($song) !== 'golden years') {
|
||||||
return 'import.fake.enter-song';
|
return 'import.fake.enter-song';
|
||||||
}
|
}
|
||||||
if (strtolower($album) !== 'station to station' && $this->job->stage !== 'new') {
|
if (strtolower($album) !== 'station to station' && $this->importJob->stage !== 'new') {
|
||||||
return 'import.fake.enter-album';
|
return 'import.fake.enter-album';
|
||||||
}
|
}
|
||||||
return 'impossible-view'; // @codeCoverageIgnore
|
return 'impossible-view'; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->job = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -75,7 +75,7 @@ class FileJobConfiguration implements JobConfigurationInterface
|
|||||||
public function configureJob(array $data): MessageBag
|
public function configureJob(array $data): MessageBag
|
||||||
{
|
{
|
||||||
$configurator = $this->getConfigurationObject();
|
$configurator = $this->getConfigurationObject();
|
||||||
$configurator->setJob($this->importJob);
|
$configurator->setImportJob($this->importJob);
|
||||||
|
|
||||||
return $configurator->configureJob($data);
|
return $configurator->configureJob($data);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ class FileJobConfiguration implements JobConfigurationInterface
|
|||||||
public function getNextData(): array
|
public function getNextData(): array
|
||||||
{
|
{
|
||||||
$configurator = $this->getConfigurationObject();
|
$configurator = $this->getConfigurationObject();
|
||||||
$configurator->setJob($this->importJob);
|
$configurator->setImportJob($this->importJob);
|
||||||
|
|
||||||
return $configurator->getNextData();
|
return $configurator->getNextData();
|
||||||
}
|
}
|
||||||
@@ -124,12 +124,12 @@ class FileJobConfiguration implements JobConfigurationInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -35,6 +35,13 @@ interface JobConfigurationInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct();
|
public function __construct();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when the initial configuration for this job is complete.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function configurationComplete(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||||
* as an error to the user, regardless of its content.
|
* as an error to the user, regardless of its content.
|
||||||
@@ -60,14 +67,7 @@ interface JobConfigurationInterface
|
|||||||
public function getNextView(): string;
|
public function getNextView(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true when the initial configuration for this job is complete.
|
* @param ImportJob $importJob
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function configurationComplete(): bool;
|
public function setImportJob(ImportJob $importJob): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ImportJob $job
|
|
||||||
*/
|
|
||||||
public function setJob(ImportJob $job): void;
|
|
||||||
}
|
}
|
||||||
|
@@ -927,12 +927,15 @@ class BunqRoutine implements RoutineInterface
|
|||||||
throw new NotImplementedException;
|
throw new NotImplementedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
// TODO: Implement setJob() method.
|
// TODO: Implement setImportJob() method.
|
||||||
throw new NotImplementedException;
|
throw new NotImplementedException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -81,7 +81,7 @@ class FakeRoutine implements RoutineInterface
|
|||||||
case 'final':
|
case 'final':
|
||||||
/** @var StageFinalHandler $handler */
|
/** @var StageFinalHandler $handler */
|
||||||
$handler = app(StageFinalHandler::class);
|
$handler = app(StageFinalHandler::class);
|
||||||
$handler->setJob($this->importJob);
|
$handler->setImportJob($this->importJob);
|
||||||
$transactions = $handler->getTransactions();
|
$transactions = $handler->getTransactions();
|
||||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||||
$this->repository->setStage($this->importJob, 'final');
|
$this->repository->setStage($this->importJob, 'final');
|
||||||
@@ -90,14 +90,14 @@ class FakeRoutine implements RoutineInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ class FileRoutine implements RoutineInterface
|
|||||||
// get processor, depending on file type
|
// get processor, depending on file type
|
||||||
// is just CSV for now.
|
// is just CSV for now.
|
||||||
$processor = $this->getProcessor();
|
$processor = $this->getProcessor();
|
||||||
$processor->setJob($this->importJob);
|
$processor->setImportJob($this->importJob);
|
||||||
$transactions = $processor->run();
|
$transactions = $processor->run();
|
||||||
|
|
||||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||||
@@ -68,13 +68,13 @@ class FileRoutine implements RoutineInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($job->user);
|
||||||
}
|
}
|
||||||
|
@@ -40,9 +40,9 @@ interface RoutineInterface
|
|||||||
public function run(): void;
|
public function run(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void;
|
public function setImportJob(ImportJob $importJob): void;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -67,7 +67,7 @@ class ImportArrayStorage
|
|||||||
*
|
*
|
||||||
* @param ImportJob $importJob
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $importJob): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $importJob;
|
$this->importJob = $importJob;
|
||||||
$this->countTransfers();
|
$this->countTransfers();
|
||||||
|
@@ -47,7 +47,7 @@ interface ConfigurationInterface
|
|||||||
public function getNextData(): array;
|
public function getNextData(): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void;
|
public function setImportJob(ImportJob $importJob): void;
|
||||||
}
|
}
|
||||||
|
@@ -337,13 +337,13 @@ class ConfigureMappingHandler implements ConfigurationInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$this->columnConfig = [];
|
$this->columnConfig = [];
|
||||||
}
|
}
|
||||||
|
@@ -400,13 +400,13 @@ class ConfigureRolesHandler implements ConfigurationInterface
|
|||||||
/**
|
/**
|
||||||
* Set job and some start values.
|
* Set job and some start values.
|
||||||
*
|
*
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$this->totalColumns = 0;
|
$this->totalColumns = 0;
|
||||||
$this->examples = [];
|
$this->examples = [];
|
||||||
|
@@ -81,15 +81,15 @@ class ConfigureUploadHandler implements ConfigurationInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||||
$this->accountRepos->setUser($job->user);
|
$this->accountRepos->setUser($importJob->user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,12 +104,12 @@ class NewFileJobHandler implements ConfigurationInterface
|
|||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*/
|
*/
|
||||||
public function setJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$this->repository->setUser($job->user);
|
$this->repository->setUser($importJob->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Import\Routine\Fake;
|
namespace FireflyIII\Support\Import\Routine\Fake;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\ImportJob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
@@ -34,17 +35,8 @@ use Carbon\Carbon;
|
|||||||
*/
|
*/
|
||||||
class StageFinalHandler
|
class StageFinalHandler
|
||||||
{
|
{
|
||||||
|
/** @var ImportJob */
|
||||||
private $job;
|
private $importJob;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $job
|
|
||||||
*/
|
|
||||||
public function setJob($job): void
|
|
||||||
{
|
|
||||||
$this->job = $job;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
@@ -58,7 +50,7 @@ class StageFinalHandler
|
|||||||
'type' => 'withdrawal',
|
'type' => 'withdrawal',
|
||||||
'date' => Carbon::create()->format('Y-m-d'),
|
'date' => Carbon::create()->format('Y-m-d'),
|
||||||
'tags' => '',
|
'tags' => '',
|
||||||
'user' => $this->job->user_id,
|
'user' => $this->importJob->user_id,
|
||||||
|
|
||||||
// all custom fields:
|
// all custom fields:
|
||||||
'internal_reference' => null,
|
'internal_reference' => null,
|
||||||
@@ -103,7 +95,7 @@ class StageFinalHandler
|
|||||||
'type' => 'transfer',
|
'type' => 'transfer',
|
||||||
'date' => '2017-02-28',
|
'date' => '2017-02-28',
|
||||||
'tags' => '',
|
'tags' => '',
|
||||||
'user' => $this->job->user_id,
|
'user' => $this->importJob->user_id,
|
||||||
|
|
||||||
// all custom fields:
|
// all custom fields:
|
||||||
'internal_reference' => null,
|
'internal_reference' => null,
|
||||||
@@ -145,4 +137,12 @@ class StageFinalHandler
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ImportJob $importJob
|
||||||
|
*/
|
||||||
|
public function setImportJob(ImportJob $importJob): void
|
||||||
|
{
|
||||||
|
$this->importJob = $importJob;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -80,11 +80,11 @@ class CSVProcessor implements FileProcessorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setImportJob(ImportJob $job): void
|
public function setImportJob(ImportJob $importJob): void
|
||||||
{
|
{
|
||||||
Log::debug('Now in setJob()');
|
Log::debug('Now in setImportJob()');
|
||||||
$this->importJob = $job;
|
$this->importJob = $importJob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ interface FileProcessorInterface
|
|||||||
/**
|
/**
|
||||||
* Set values.
|
* Set values.
|
||||||
*
|
*
|
||||||
* @param ImportJob $job
|
* @param ImportJob $importJob
|
||||||
*/
|
*/
|
||||||
public function setImportJob(ImportJob $job): void;
|
public function setImportJob(ImportJob $importJob): void;
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ use FireflyIII\Models\ImportJob;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
||||||
|
use InvalidArgumentException;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,6 +113,8 @@ class ImportableConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param array $mappedValues
|
* @param array $mappedValues
|
||||||
*/
|
*/
|
||||||
public function setMappedValues(array $mappedValues): void
|
public function setMappedValues(array $mappedValues): void
|
||||||
@@ -179,18 +182,27 @@ class ImportableConverter
|
|||||||
Log::debug('Destination is an expense account. This is a withdrawal.');
|
Log::debug('Destination is an expense account. This is a withdrawal.');
|
||||||
$transactionType = 'withdrawal';
|
$transactionType = 'withdrawal';
|
||||||
}
|
}
|
||||||
if ($transactionType === 'unknown') {
|
if ($destination->id === $source->id) {
|
||||||
Log::error(
|
throw new FireflyException(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Cannot determine transaction type. Source account is a %s, destination is a %s',
|
'Source ("%s", #%d) and destination ("%s", #%d) are the same account.', $source->name, $source->id, $destination->name, $destination->id
|
||||||
$source->accountType->type, $destination->accountType->type
|
)
|
||||||
), ['source' => $source->toArray(), 'dest' => $destination->toArray()]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($transactionType === 'unknown') {
|
||||||
|
$message = sprintf(
|
||||||
|
'Cannot determine transaction type. Source account is a %s, destination is a %s', $source->accountType->type, $destination->accountType->type
|
||||||
|
);
|
||||||
|
Log::error($message, ['source' => $source->toArray(), 'dest' => $destination->toArray()]);
|
||||||
|
throw new FireflyException($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw error when both are he same
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$date = Carbon::createFromFormat($this->config['date-format'] ?? 'Ymd', $importable->date);
|
$date = Carbon::createFromFormat($this->config['date-format'] ?? 'Ymd', $importable->date);
|
||||||
} catch (InvalidDateException $e) {
|
} catch (InvalidDateException|InvalidArgumentException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
|
@@ -82,6 +82,7 @@ class MappingConverger
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getMappedValues(): array
|
public function getMappedValues(): array
|
||||||
|
@@ -64,7 +64,7 @@ class JobConfigurationControllerTest extends TestCase
|
|||||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$configurator->shouldReceive('setJob')->once();
|
$configurator->shouldReceive('setImportJob')->once();
|
||||||
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
||||||
$configurator->shouldReceive('getNextView')->once()->andReturn('import.fake.apply-rules');
|
$configurator->shouldReceive('getNextView')->once()->andReturn('import.fake.apply-rules');
|
||||||
$configurator->shouldReceive('getNextData')->once()
|
$configurator->shouldReceive('getNextData')->once()
|
||||||
@@ -122,7 +122,7 @@ class JobConfigurationControllerTest extends TestCase
|
|||||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$configurator->shouldReceive('setJob')->once();
|
$configurator->shouldReceive('setImportJob')->once();
|
||||||
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
|
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
|
||||||
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
|
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class JobConfigurationControllerTest extends TestCase
|
|||||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$configurator->shouldReceive('setJob')->once();
|
$configurator->shouldReceive('setImportJob')->once();
|
||||||
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
||||||
$configurator->shouldReceive('configureJob')->withArgs([[]])->once()->andReturn($messages);
|
$configurator->shouldReceive('configureJob')->withArgs([[]])->once()->andReturn($messages);
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ class JobConfigurationControllerTest extends TestCase
|
|||||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$configurator->shouldReceive('setJob')->once();
|
$configurator->shouldReceive('setImportJob')->once();
|
||||||
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
|
$configurator->shouldReceive('configurationComplete')->once()->andReturn(true);
|
||||||
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
|
$repository->shouldReceive('updateStatus')->withArgs([Mockery::any(), 'ready_to_run']);
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ class JobConfigurationControllerTest extends TestCase
|
|||||||
$configurator = $this->mock(FakeJobConfiguration::class);
|
$configurator = $this->mock(FakeJobConfiguration::class);
|
||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$configurator->shouldReceive('setJob')->once();
|
$configurator->shouldReceive('setImportJob')->once();
|
||||||
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
$configurator->shouldReceive('configurationComplete')->once()->andReturn(false);
|
||||||
$configurator->shouldReceive('configureJob')->once()->andReturn($messages);
|
$configurator->shouldReceive('configureJob')->once()->andReturn($messages);
|
||||||
$repository->shouldReceive('storeFileUpload')->once()->andReturn(new MessageBag);
|
$repository->shouldReceive('storeFileUpload')->once()->andReturn(new MessageBag);
|
||||||
|
@@ -198,7 +198,7 @@ class JobStatusControllerTest extends TestCase
|
|||||||
|
|
||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
||||||
$routine->shouldReceive('setJob')->once();
|
$routine->shouldReceive('setImportJob')->once();
|
||||||
$routine->shouldReceive('run')->once();
|
$routine->shouldReceive('run')->once();
|
||||||
|
|
||||||
// call thing.
|
// call thing.
|
||||||
@@ -229,7 +229,7 @@ class JobStatusControllerTest extends TestCase
|
|||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
||||||
$routine->shouldReceive('setJob')->once();
|
$routine->shouldReceive('setImportJob')->once();
|
||||||
$routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));
|
$routine->shouldReceive('run')->andThrow(new Exception('Unknown exception'));
|
||||||
|
|
||||||
// call thing.
|
// call thing.
|
||||||
@@ -260,7 +260,7 @@ class JobStatusControllerTest extends TestCase
|
|||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'running']);
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
||||||
$routine->shouldReceive('setJob')->once();
|
$routine->shouldReceive('setImportJob')->once();
|
||||||
$routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));
|
$routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception'));
|
||||||
|
|
||||||
// call thing.
|
// call thing.
|
||||||
@@ -312,7 +312,7 @@ class JobStatusControllerTest extends TestCase
|
|||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storage_finished']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storage_finished']);
|
||||||
$storage->shouldReceive('setJob')->once();
|
$storage->shouldReceive('setImportJob')->once();
|
||||||
$storage->shouldReceive('store')->once();
|
$storage->shouldReceive('store')->once();
|
||||||
|
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ class JobStatusControllerTest extends TestCase
|
|||||||
// mock calls:
|
// mock calls:
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'storing_data']);
|
||||||
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'error']);
|
||||||
$storage->shouldReceive('setJob')->once();
|
$storage->shouldReceive('setImportJob')->once();
|
||||||
$storage->shouldReceive('store')->once()->andThrow(new FireflyException('Some storage exception.'));
|
$storage->shouldReceive('store')->once()->andThrow(new FireflyException('Some storage exception.'));
|
||||||
|
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertTrue($configurator->configurationComplete());
|
$this->assertTrue($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertTrue($configurator->configurationComplete());
|
$this->assertTrue($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -420,7 +420,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -455,7 +455,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -490,7 +490,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$messages = $configurator->configureJob($data);
|
$messages = $configurator->configureJob($data);
|
||||||
$this->assertTrue($messages->has('some_key'));
|
$this->assertTrue($messages->has('some_key'));
|
||||||
}
|
}
|
||||||
@@ -514,7 +514,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$view = $configurator->getNextView();
|
$view = $configurator->getNextView();
|
||||||
$this->assertEquals('import.fake.enter-album', $view);
|
$this->assertEquals('import.fake.enter-album', $view);
|
||||||
}
|
}
|
||||||
@@ -538,7 +538,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$view = $configurator->getNextView();
|
$view = $configurator->getNextView();
|
||||||
$this->assertEquals('import.fake.enter-artist', $view);
|
$this->assertEquals('import.fake.enter-artist', $view);
|
||||||
}
|
}
|
||||||
@@ -562,7 +562,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$view = $configurator->getNextView();
|
$view = $configurator->getNextView();
|
||||||
$this->assertEquals('import.fake.apply-rules', $view);
|
$this->assertEquals('import.fake.apply-rules', $view);
|
||||||
}
|
}
|
||||||
@@ -586,7 +586,7 @@ class FakeJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// call configuration
|
// call configuration
|
||||||
$configurator = new FakeJobConfiguration;
|
$configurator = new FakeJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$view = $configurator->getNextView();
|
$view = $configurator->getNextView();
|
||||||
$this->assertEquals('import.fake.enter-song', $view);
|
$this->assertEquals('import.fake.enter-song', $view);
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertFalse($configurator->configurationComplete());
|
$this->assertFalse($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
// should be false:
|
// should be false:
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
$this->assertTrue($configurator->configurationComplete());
|
$this->assertTrue($configurator->configurationComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +107,10 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
|
|
||||||
$handler = $this->mock(ConfigureMappingHandler::class);
|
$handler = $this->mock(ConfigureMappingHandler::class);
|
||||||
$handler->shouldReceive('setJob')->once()->withArgs([Mockery::any()]);
|
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
|
||||||
$handler->shouldReceive('configureJob')->withArgs([['c' => 'd']])->andReturn($bag)->once();
|
$handler->shouldReceive('configureJob')->withArgs([['c' => 'd']])->andReturn($bag)->once();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -140,10 +140,10 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
|
|
||||||
$handler = $this->mock(ConfigureUploadHandler::class);
|
$handler = $this->mock(ConfigureUploadHandler::class);
|
||||||
$handler->shouldReceive('setJob')->once()->withArgs([Mockery::any()]);
|
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
|
||||||
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -173,10 +173,10 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
|
|
||||||
$handler = $this->mock(ConfigureMappingHandler::class);
|
$handler = $this->mock(ConfigureMappingHandler::class);
|
||||||
$handler->shouldReceive('setJob')->once()->withArgs([Mockery::any()]);
|
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
|
||||||
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -206,10 +206,10 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
|
|
||||||
$handler = $this->mock(NewFileJobHandler::class);
|
$handler = $this->mock(NewFileJobHandler::class);
|
||||||
$handler->shouldReceive('setJob')->once()->withArgs([Mockery::any()]);
|
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
|
||||||
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -239,10 +239,10 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
|
|
||||||
$handler = $this->mock(ConfigureRolesHandler::class);
|
$handler = $this->mock(ConfigureRolesHandler::class);
|
||||||
$handler->shouldReceive('setJob')->once()->withArgs([Mockery::any()]);
|
$handler->shouldReceive('setImportJob')->once()->withArgs([Mockery::any()]);
|
||||||
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
$handler->shouldReceive('getNextData')->andReturn(['a' => 'b'])->withNoArgs()->once();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -272,7 +272,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $configurator->getNextView();
|
$result = $configurator->getNextView();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -300,7 +300,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $configurator->getNextView();
|
$result = $configurator->getNextView();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -328,7 +328,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $configurator->getNextView();
|
$result = $configurator->getNextView();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -356,7 +356,7 @@ class FileJobConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$result = 'x';
|
$result = 'x';
|
||||||
$configurator = new FileJobConfiguration;
|
$configurator = new FileJobConfiguration;
|
||||||
$configurator->setJob($job);
|
$configurator->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $configurator->getNextView();
|
$result = $configurator->getNextView();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
|
@@ -65,7 +65,7 @@ class FakeRoutineTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$routine = new FakeRoutine;
|
$routine = new FakeRoutine;
|
||||||
$routine->setJob($job);
|
$routine->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$routine->run();
|
$routine->run();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -98,10 +98,10 @@ class FakeRoutineTest extends TestCase
|
|||||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
||||||
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), []])->once();
|
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), []])->once();
|
||||||
$handler->shouldReceive('getTransactions')->once()->andReturn([]);
|
$handler->shouldReceive('getTransactions')->once()->andReturn([]);
|
||||||
$handler->shouldReceive('setJob')->once();
|
$handler->shouldReceive('setImportJob')->once();
|
||||||
|
|
||||||
$routine = new FakeRoutine;
|
$routine = new FakeRoutine;
|
||||||
$routine->setJob($job);
|
$routine->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$routine->run();
|
$routine->run();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -136,7 +136,7 @@ class FakeRoutineTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$routine = new FakeRoutine;
|
$routine = new FakeRoutine;
|
||||||
$routine->setJob($job);
|
$routine->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$routine->run();
|
$routine->run();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
|
@@ -63,12 +63,12 @@ class FileRoutineTest extends TestCase
|
|||||||
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
|
||||||
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once();
|
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once();
|
||||||
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->once()->andReturn([]);
|
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->once()->andReturn([]);
|
||||||
$processor->shouldReceive('setJob')->once();
|
$processor->shouldReceive('setImportJob')->once();
|
||||||
$processor->shouldReceive('run')->once()->andReturn(['a' => 'b']);
|
$processor->shouldReceive('run')->once()->andReturn(['a' => 'b']);
|
||||||
|
|
||||||
|
|
||||||
$routine = new FileRoutine;
|
$routine = new FileRoutine;
|
||||||
$routine->setJob($job);
|
$routine->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$routine->run();
|
$routine->run();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
|
@@ -76,7 +76,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$journalRepos->shouldReceive('setUser')->once();
|
$journalRepos->shouldReceive('setUser')->once();
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +131,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
->withArgs([Mockery::any(), 'Entry #1 ("' . $transactions[1]['description'] . '") could not be imported. It already exists.']);
|
->withArgs([Mockery::any(), 'Entry #1 ("' . $transactions[1]['description'] . '") could not be imported. It already exists.']);
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -170,7 +170,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$journalRepos->shouldReceive('setUser')->once();
|
$journalRepos->shouldReceive('setUser')->once();
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -214,7 +214,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$journalRepos->shouldReceive('setUser')->once();
|
$journalRepos->shouldReceive('setUser')->once();
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -265,7 +265,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$journalRepos->shouldReceive('findByHash')->andReturn(null)->once();
|
$journalRepos->shouldReceive('findByHash')->andReturn(null)->once();
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -320,7 +320,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$journalRepos->shouldReceive('findByHash')->andReturn(null)->once();
|
$journalRepos->shouldReceive('findByHash')->andReturn(null)->once();
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -393,7 +393,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$collector->shouldReceive('getJournals')->andReturn($transferCollection);
|
$collector->shouldReceive('getJournals')->andReturn($transferCollection);
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
@@ -472,7 +472,7 @@ class ImportArrayStorageTest extends TestCase
|
|||||||
$collector->shouldReceive('getJournals')->andReturn($transferCollection);
|
$collector->shouldReceive('getJournals')->andReturn($transferCollection);
|
||||||
|
|
||||||
$storage = new ImportArrayStorage;
|
$storage = new ImportArrayStorage;
|
||||||
$storage->setJob($job);
|
$storage->setImportJob($job);
|
||||||
$result = new Collection;
|
$result = new Collection;
|
||||||
try {
|
try {
|
||||||
$result = $storage->store();
|
$result = $storage->store();
|
||||||
|
@@ -74,7 +74,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$result = $handler->applySpecifics($config, []);
|
$result = $handler->applySpecifics($config, []);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$handler->configureJob($input);
|
$handler->configureJob($input);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $handler->doColumnConfig($input);
|
$result = $handler->doColumnConfig($input);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -231,7 +231,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
foreach ($combinations as $info) {
|
foreach ($combinations as $info) {
|
||||||
$this->assertEquals($info['expected'], $handler->doMapOfColumn($info['role'], $info['requested']));
|
$this->assertEquals($info['expected'], $handler->doMapOfColumn($info['role'], $info['requested']));
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $handler->getNextData();
|
$result = $handler->getNextData();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -340,7 +340,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
foreach ($combinations as $info) {
|
foreach ($combinations as $info) {
|
||||||
$this->assertEquals($info['expected'], $handler->getPreProcessorName($info['role']));
|
$this->assertEquals($info['expected'], $handler->getPreProcessorName($info['role']));
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
$attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
|
$attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$reader = $handler->getReader();
|
$reader = $handler->getReader();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -449,7 +449,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
$job->save();
|
$job->save();
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$result = [];
|
$result = [];
|
||||||
try {
|
try {
|
||||||
$result = $handler->getValuesForMapping($reader, $config, $columnConfig);
|
$result = $handler->getValuesForMapping($reader, $config, $columnConfig);
|
||||||
@@ -478,7 +478,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
|||||||
$job->save();
|
$job->save();
|
||||||
|
|
||||||
$handler = new ConfigureMappingHandler;
|
$handler = new ConfigureMappingHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$keys = array_keys(config('csv.import_roles'));
|
$keys = array_keys(config('csv.import_roles'));
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$this->assertEquals($key, $handler->sanitizeColumnName($key));
|
$this->assertEquals($key, $handler->sanitizeColumnName($key));
|
||||||
|
@@ -159,7 +159,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
|||||||
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expected]);
|
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expected]);
|
||||||
|
|
||||||
$handler = new ConfigureRolesHandler();
|
$handler = new ConfigureRolesHandler();
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$handler->configureJob($data);
|
$handler->configureJob($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
|||||||
$file = "one,two,,three\nfour,five,,six\none,three,X,three";
|
$file = "one,two,,three\nfour,five,,six\none,three,X,three";
|
||||||
$reader = Reader::createFromString($file);
|
$reader = Reader::createFromString($file);
|
||||||
$handler = new ConfigureRolesHandler;
|
$handler = new ConfigureRolesHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$handler->getExamplesFromFile($reader, $job->configuration);
|
$handler->getExamplesFromFile($reader, $job->configuration);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -321,7 +321,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new ConfigureRolesHandler();
|
$handler = new ConfigureRolesHandler();
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$result = $handler->getNextData();
|
$result = $handler->getNextData();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -373,7 +373,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
|||||||
$attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
|
$attachments->shouldReceive('getAttachmentContent')->withArgs([Mockery::any()])->andReturn($fileContent);
|
||||||
|
|
||||||
$handler = new ConfigureRolesHandler();
|
$handler = new ConfigureRolesHandler();
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$reader = $handler->getReader();
|
$reader = $handler->getReader();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -518,7 +518,7 @@ class ConfigureRolesHandlerTest extends TestCase
|
|||||||
->withArgs([Mockery::any(), ['column-count' => 0]]);
|
->withArgs([Mockery::any(), ['column-count' => 0]]);
|
||||||
|
|
||||||
$handler = new ConfigureRolesHandler();
|
$handler = new ConfigureRolesHandler();
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$handler->saveColumCount();
|
$handler->saveColumCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
|||||||
$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'roles']);
|
$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'roles']);
|
||||||
|
|
||||||
$handler = new ConfigureUploadHandler;
|
$handler = new ConfigureUploadHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$result = $handler->configureJob($data);
|
$result = $handler->configureJob($data);
|
||||||
$this->assertCount(0, $result);
|
$this->assertCount(0, $result);
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
|||||||
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
|
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $expectedConfig]);
|
||||||
|
|
||||||
$handler = new ConfigureUploadHandler;
|
$handler = new ConfigureUploadHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$result = $handler->configureJob($data);
|
$result = $handler->configureJob($data);
|
||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
$this->assertEquals('You have selected an invalid account to import into.', $result->get('account')[0]);
|
$this->assertEquals('You have selected an invalid account to import into.', $result->get('account')[0]);
|
||||||
@@ -153,7 +153,7 @@ class ConfigureUploadHandlerTest extends TestCase
|
|||||||
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['date-format' => 'Ymd']]);
|
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), ['date-format' => 'Ymd']]);
|
||||||
|
|
||||||
$handler = new ConfigureUploadHandler;
|
$handler = new ConfigureUploadHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
$result = $handler->getNextData();
|
$result = $handler->getNextData();
|
||||||
$expected = [
|
$expected = [
|
||||||
'accounts' => [],
|
'accounts' => [],
|
||||||
|
@@ -85,7 +85,7 @@ class NewFileJobHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new NewFileJobHandler;
|
$handler = new NewFileJobHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$messages = $handler->configureJob($data);
|
$messages = $handler->configureJob($data);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -139,7 +139,7 @@ class NewFileJobHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$handler = new NewFileJobHandler;
|
$handler = new NewFileJobHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
try {
|
try {
|
||||||
$messages = $handler->configureJob($data);
|
$messages = $handler->configureJob($data);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@@ -190,7 +190,7 @@ class NewFileJobHandlerTest extends TestCase
|
|||||||
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['a' => 'b']])->once();
|
$repository->shouldReceive('setConfiguration')->withArgs([Mockery::any(), ['a' => 'b']])->once();
|
||||||
|
|
||||||
$handler = new NewFileJobHandler;
|
$handler = new NewFileJobHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$handler->storeConfiguration();
|
$handler->storeConfiguration();
|
||||||
@@ -237,7 +237,7 @@ class NewFileJobHandlerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$handler = new NewFileJobHandler;
|
$handler = new NewFileJobHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $handler->validateAttachments();
|
$result = $handler->validateAttachments();
|
||||||
@@ -288,7 +288,7 @@ class NewFileJobHandlerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$handler = new NewFileJobHandler;
|
$handler = new NewFileJobHandler;
|
||||||
$handler->setJob($job);
|
$handler->setImportJob($job);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $handler->validateAttachments();
|
$result = $handler->validateAttachments();
|
||||||
|
@@ -0,0 +1,535 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ImportableConverterTest.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Support\Import\Routine\File;
|
||||||
|
|
||||||
|
|
||||||
|
use Amount;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
||||||
|
use FireflyIII\Support\Import\Routine\File\AssetAccountMapper;
|
||||||
|
use FireflyIII\Support\Import\Routine\File\CurrencyMapper;
|
||||||
|
use FireflyIII\Support\Import\Routine\File\ImportableConverter;
|
||||||
|
use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
|
||||||
|
use Mockery;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo test foreign currency
|
||||||
|
* todo test budget (known and unknown)
|
||||||
|
* todo test category (known and unknown)
|
||||||
|
* todo test foreign currency
|
||||||
|
*
|
||||||
|
* Class ImportableConverterTest
|
||||||
|
*/
|
||||||
|
class ImportableConverterTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Basic test. Should match a withdrawal. Amount is negative.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasic(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '-45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importable->tags = ['a', 'b', 'c'];
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
$expense = $this->user()->accounts()->where('account_type_id', 4)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($expense);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
|
||||||
|
// verify content of $result
|
||||||
|
$this->assertEquals('withdrawal', $result[0]['type']);
|
||||||
|
$this->assertEquals('2018-09-17', $result[0]['date']);
|
||||||
|
$this->assertEquals($importable->tags, $result[0]['tags']);
|
||||||
|
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Two asset accounts mean its a transfer.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicDefaultCurrency(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '45.67';
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
$other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn(null);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
|
||||||
|
// verify content of $result
|
||||||
|
$today = new Carbon();
|
||||||
|
$this->assertEquals('transfer', $result[0]['type']);
|
||||||
|
$this->assertEquals($today->format('Y-m-d'), $result[0]['date']);
|
||||||
|
$this->assertEquals([], $result[0]['tags']);
|
||||||
|
$this->assertEquals($euro->id, $result[0]['transactions'][0]['currency_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Positive amount, so transaction is a deposit.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicDeposit(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importable->meta['date-book'] = '2018-01-02';
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
$revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($revenue);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
|
||||||
|
// verify content of $result
|
||||||
|
$this->assertEquals('deposit', $result[0]['type']);
|
||||||
|
$this->assertEquals('2018-09-17', $result[0]['date']);
|
||||||
|
$this->assertEquals([], $result[0]['tags']);
|
||||||
|
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||||
|
$this->assertEquals($revenue->id, $result[0]['transactions'][0]['source_id']);
|
||||||
|
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
|
||||||
|
$this->assertEquals($importable->meta['date-book'], $result[0]['book_date']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source and destination are the same. Should result in error message.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicSameAssets(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '-45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($asset);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
$repository->shouldReceive('addErrorMessage')->withArgs(
|
||||||
|
[Mockery::any(),
|
||||||
|
'Row #1: Source ("' . $asset->name . '", #' . $asset->id . ') and destination ("' . $asset->name . '", #' . $asset->id . ') are the same account.']
|
||||||
|
)->once();
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Two asset accounts mean its a transfer. This has a positive amount.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicTransfer(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importable->billId = 2; // will be ignored because it's not valid.
|
||||||
|
$importable->billName = 'Some Bill'; // will be included because bill ID is not valid.
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
$other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
|
||||||
|
// verify content of $result
|
||||||
|
$this->assertEquals('transfer', $result[0]['type']);
|
||||||
|
$this->assertEquals('2018-09-17', $result[0]['date']);
|
||||||
|
$this->assertEquals([], $result[0]['tags']);
|
||||||
|
$this->assertNull($result[0]['bill_id']);
|
||||||
|
$this->assertEquals($importable->billName, $result[0]['bill_name']);
|
||||||
|
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||||
|
// since amount is positive, $asset recieves the money
|
||||||
|
$this->assertEquals($other->id, $result[0]['transactions'][0]['source_id']);
|
||||||
|
$this->assertEquals($asset->id, $result[0]['transactions'][0]['destination_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfer with negative amount flows the other direction. See source_id and destination_id
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicTransferNegative(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '-45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importable->billId = 3; // is added to array of valid values, see below.
|
||||||
|
$importable->billName = 'Some bill'; // will be ignored because ID is valid.
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$validMappings = [
|
||||||
|
'bill-id' => [3],
|
||||||
|
];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
|
$other = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $asset->id)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($other);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$converter->setMappedValues($validMappings);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
|
||||||
|
// verify content of $result
|
||||||
|
$this->assertEquals('transfer', $result[0]['type']);
|
||||||
|
$this->assertEquals('2018-09-17', $result[0]['date']);
|
||||||
|
$this->assertEquals([], $result[0]['tags']);
|
||||||
|
$this->assertEquals(3, $result[0]['bill_id']);
|
||||||
|
$this->assertNull($result[0]['bill_name']);
|
||||||
|
$this->assertEquals($usd->id, $result[0]['transactions'][0]['currency_id']);
|
||||||
|
// since amount is negative, $asset sends the money
|
||||||
|
$this->assertEquals($asset->id, $result[0]['transactions'][0]['source_id']);
|
||||||
|
$this->assertEquals($other->id, $result[0]['transactions'][0]['destination_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When source and dest are weird account types, will give error.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testBasicWeirdAccounts(): void
|
||||||
|
{
|
||||||
|
$nullAccount = ['name' => null, 'iban' => null, 'number' => null, 'bic' => null];
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importable->amount = '-45.67';
|
||||||
|
$importable->date = '20180917';
|
||||||
|
$importables = [$importable];
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [
|
||||||
|
'date-format' => 'Ymd',
|
||||||
|
];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
|
||||||
|
// get default currency
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
$usd = TransactionCurrency::whereCode('USD')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
|
||||||
|
// set user and config:
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
// respond to mapping call:
|
||||||
|
$asset = $this->user()->accounts()->where('account_type_id', 6)->first();
|
||||||
|
$other = $this->user()->accounts()->where('account_type_id', 2)->where('id', '!=', $asset)->first();
|
||||||
|
|
||||||
|
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
|
||||||
|
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '-45.67', $nullAccount])->andReturn($other);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn($usd);
|
||||||
|
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
|
||||||
|
$repository->shouldReceive('addErrorMessage')->withArgs(
|
||||||
|
[Mockery::any(), 'Row #1: Cannot determine transaction type. Source account is a Initial balance account, destination is a Cash account']
|
||||||
|
)->once();
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit no amount information.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testEmpty(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic input until it stops crashing.
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Support\Import\Routine\File\ImportableConverter
|
||||||
|
*/
|
||||||
|
public function testNoAmount(): void
|
||||||
|
{
|
||||||
|
$importable = new ImportTransaction;
|
||||||
|
$importables = [$importable];
|
||||||
|
$job = $this->user()->importJobs()->first();
|
||||||
|
$job->configuration = [];
|
||||||
|
$job->save();
|
||||||
|
|
||||||
|
// mock used classes:
|
||||||
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$assetMapper = $this->mock(AssetAccountMapper::class);
|
||||||
|
$opposingMapper = $this->mock(OpposingAccountMapper::class);
|
||||||
|
$currencyMapper = $this->mock(CurrencyMapper::class);
|
||||||
|
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||||
|
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($euro)->once();
|
||||||
|
$repository->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setUser')->once();
|
||||||
|
$opposingMapper->shouldReceive('setUser')->once();
|
||||||
|
$currencyMapper->shouldReceive('setUser')->once();
|
||||||
|
$assetMapper->shouldReceive('setDefaultAccount')->withArgs([0])->once();
|
||||||
|
$repository->shouldReceive('addErrorMessage')->withArgs([Mockery::any(), 'Row #1: No transaction amount information.'])->once();
|
||||||
|
|
||||||
|
$converter = new ImportableConverter;
|
||||||
|
$converter->setImportJob($job);
|
||||||
|
$result = $converter->convert($importables);
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user