Skip to content

Firefly III: a personal finances manager

Improve test coverage and remove deprecated code.

James Colebc7c3bb9b3af
diff --git a/app/Http/Controllers/Import/PrerequisitesController.php b/app/Http/Controllers/Import/PrerequisitesController.php
index 6d7fc3a25a..b8bdebbd52 100644
--- a/app/Http/Controllers/Import/PrerequisitesController.php
+++ b/app/Http/Controllers/Import/PrerequisitesController.php
@@ -145,7 +145,8 @@ class PrerequisitesController extends Controller
$object->setUser(auth()->user());
Log::debug('Going to store entered prerequisites.');
// store post data
- $result = $object->storePrerequisites($request);
+ $data = $request->all();
+ $result = $object->storePrerequisites($data);
Log::debug(sprintf('Result of storePrerequisites has message count: %d', $result->count()));
if ($result->count() > 0) {
diff --git a/app/Import/JobConfiguration/FakeJobConfiguration.php b/app/Import/JobConfiguration/FakeJobConfiguration.php
index 25d7c445d3..f4d8e6e772 100644
--- a/app/Import/JobConfiguration/FakeJobConfiguration.php
+++ b/app/Import/JobConfiguration/FakeJobConfiguration.php
@@ -114,7 +114,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
/**
* Return the data required for the next step in the job configuration.
- *
+ * @codeCoverageIgnore
* @return array
*/
public function getNextData(): array
@@ -152,6 +152,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
if (strtolower($album) !== 'station to station' && $this->job->stage !== 'new') {
return 'import.fake.enter-album';
}
+ return 'impossible-view'; // @codeCoverageIgnore
}
/**
diff --git a/app/Import/Object/ImportAccount.php b/app/Import/Object/ImportAccount.php
index fe2ffc8767..fdfef58293 100644
--- a/app/Import/Object/ImportAccount.php
+++ b/app/Import/Object/ImportAccount.php
@@ -30,6 +30,8 @@ use FireflyIII\User;
use Log;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportAccount.
*/
class ImportAccount
diff --git a/app/Import/Object/ImportBill.php b/app/Import/Object/ImportBill.php
index 19364f9df6..5222334aa6 100644
--- a/app/Import/Object/ImportBill.php
+++ b/app/Import/Object/ImportBill.php
@@ -29,6 +29,8 @@ use Log;
use Steam;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportBill.
*/
class ImportBill
diff --git a/app/Import/Object/ImportBudget.php b/app/Import/Object/ImportBudget.php
index 53e92a8f80..55f4e6e559 100644
--- a/app/Import/Object/ImportBudget.php
+++ b/app/Import/Object/ImportBudget.php
@@ -28,6 +28,8 @@ use FireflyIII\User;
use Log;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportBudget.
*/
class ImportBudget
diff --git a/app/Import/Object/ImportCategory.php b/app/Import/Object/ImportCategory.php
index 9427d74871..bcdf0a9477 100644
--- a/app/Import/Object/ImportCategory.php
+++ b/app/Import/Object/ImportCategory.php
@@ -28,6 +28,8 @@ use FireflyIII\User;
use Log;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportCategory
*/
class ImportCategory
diff --git a/app/Import/Object/ImportCurrency.php b/app/Import/Object/ImportCurrency.php
index 2d63bf9955..b570632064 100644
--- a/app/Import/Object/ImportCurrency.php
+++ b/app/Import/Object/ImportCurrency.php
@@ -28,6 +28,8 @@ use FireflyIII\User;
use Log;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportCurrency
*/
class ImportCurrency
diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.php
index 8c2311c09f..c4e96db676 100644
--- a/app/Import/Object/ImportJournal.php
+++ b/app/Import/Object/ImportJournal.php
@@ -33,6 +33,8 @@ use Log;
use Steam;
/**
+ * @deprecated
+ * @codeCoverageIgnore
* Class ImportJournal.
*/
class ImportJournal
diff --git a/app/Import/Prerequisites/BunqPrerequisites.php b/app/Import/Prerequisites/BunqPrerequisites.php
index f1f93aab3e..fe6d46c0f9 100644
--- a/app/Import/Prerequisites/BunqPrerequisites.php
+++ b/app/Import/Prerequisites/BunqPrerequisites.php
@@ -36,19 +36,155 @@ use Preferences;
*/
class BunqPrerequisites implements PrerequisitesInterface
{
- /** @var User */
- private $user;
-
+// /** @var User */
+// private $user;
+//
+// /**
+// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+// *
+// * @return string
+// */
+// public function getView(): string
+// {
+// Log::debug('Now in BunqPrerequisites::getView()');
+//
+// return 'import.bunq.prerequisites';
+// }
+//
+// /**
+// * Returns any values required for the prerequisites-view.
+// *
+// * @return array
+// */
+// public function getViewParameters(): array
+// {
+// Log::debug('Now in BunqPrerequisites::getViewParameters()');
+// $key = '';
+// $serverIP = '';
+// if ($this->hasApiKey()) {
+// $key = Preferences::getForUser($this->user, 'bunq_api_key', null)->data;
+// }
+// if ($this->hasServerIP()) {
+// $serverIP = Preferences::getForUser($this->user, 'external_ip', null)->data;
+// }
+// if (!$this->hasServerIP()) {
+// /** @var IPRetrievalInterface $service */
+// $service = app(IPRetrievalInterface::class);
+// $serverIP = (string)$service->getIP();
+// }
+//
+//
+// // get IP address
+// return ['key' => $key, 'ip' => $serverIP];
+// }
+//
+// /**
+// * Returns if this import method has any special prerequisites such as config
+// * variables or other things. The only thing we verify is the presence of the API key. Everything else
+// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
+// *
+// * @return bool
+// */
+// public function hasPrerequisites(): bool
+// {
+// $hasApiKey = $this->hasApiKey();
+// $hasServerIP = $this->hasServerIP();
+//
+// return !$hasApiKey || !$hasServerIP;
+// }
+//
+// /**
+// * Indicate if all prerequisites have been met.
+// *
+// * @return bool
+// */
+// public function isComplete(): bool
+// {
+// // is complete when user has entered both the API key
+// // and his IP address.
+//
+// $hasApiKey = $this->hasApiKey();
+// $hasServerIP = $this->hasServerIP();
+//
+// return $hasApiKey && $hasServerIP;
+// }
+//
+// /**
+// * Set the user for this Prerequisites-routine. Class is expected to implement and save this.
+// *
+// * @param User $user
+// */
+// public function setUser(User $user): void
+// {
+// Log::debug(sprintf('Now in setUser(#%d)', $user->id));
+// $this->user = $user;
+// }
+//
+// /**
+// * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
+// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+// *
+// * @param Request $request
+// *
+// * @return MessageBag
+// */
+// public function storePrerequisites(Request $request): MessageBag
+// {
+// $apiKey = $request->get('api_key');
+// $serverIP = $request->get('external_ip');
+// Log::debug('Storing bunq API key');
+// Preferences::setForUser($this->user, 'bunq_api_key', $apiKey);
+// Preferences::setForUser($this->user, 'external_ip', $serverIP);
+//
+// return new MessageBag;
+// }
+//
+// /**
+// * @return bool
+// */
+// private function hasApiKey(): bool
+// {
+// $apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
+// if (null === $apiKey) {
+// return false;
+// }
+// if (null === $apiKey->data) {
+// return false;
+// }
+// if (\strlen((string)$apiKey->data) === 64) {
+// return true;
+// }
+//
+// return false;
+// }
+//
+// /**
+// * @return bool
+// */
+// private function hasServerIP(): bool
+// {
+// $serverIP = Preferences::getForUser($this->user, 'external_ip', false);
+// if (null === $serverIP) {
+// return false;
+// }
+// if (null === $serverIP->data) {
+// return false;
+// }
+// if (\strlen((string)$serverIP->data) > 6) {
+// return true;
+// }
+//
+// return false;
+// }
/**
- * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+ * Returns view name that allows user to fill in prerequisites.
*
* @return string
*/
public function getView(): string
{
- Log::debug('Now in BunqPrerequisites::getView()');
-
- return 'import.bunq.prerequisites';
+ // TODO: Implement getView() method.
+ throw new NotImplementedException;
}
/**
@@ -58,39 +194,8 @@ class BunqPrerequisites implements PrerequisitesInterface
*/
public function getViewParameters(): array
{
- Log::debug('Now in BunqPrerequisites::getViewParameters()');
- $key = '';
- $serverIP = '';
- if ($this->hasApiKey()) {
- $key = Preferences::getForUser($this->user, 'bunq_api_key', null)->data;
- }
- if ($this->hasServerIP()) {
- $serverIP = Preferences::getForUser($this->user, 'external_ip', null)->data;
- }
- if (!$this->hasServerIP()) {
- /** @var IPRetrievalInterface $service */
- $service = app(IPRetrievalInterface::class);
- $serverIP = (string)$service->getIP();
- }
-
-
- // get IP address
- return ['key' => $key, 'ip' => $serverIP];
- }
-
- /**
- * Returns if this import method has any special prerequisites such as config
- * variables or other things. The only thing we verify is the presence of the API key. Everything else
- * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
- *
- * @return bool
- */
- public function hasPrerequisites(): bool
- {
- $hasApiKey = $this->hasApiKey();
- $hasServerIP = $this->hasServerIP();
-
- return !$hasApiKey || !$hasServerIP;
+ // TODO: Implement getViewParameters() method.
+ throw new NotImplementedException;
}
/**
@@ -100,13 +205,8 @@ class BunqPrerequisites implements PrerequisitesInterface
*/
public function isComplete(): bool
{
- // is complete when user has entered both the API key
- // and his IP address.
-
- $hasApiKey = $this->hasApiKey();
- $hasServerIP = $this->hasServerIP();
-
- return $hasApiKey && $hasServerIP;
+ // TODO: Implement isComplete() method.
+ throw new NotImplementedException;
}
/**
@@ -116,64 +216,22 @@ class BunqPrerequisites implements PrerequisitesInterface
*/
public function setUser(User $user): void
{
- Log::debug(sprintf('Now in setUser(#%d)', $user->id));
- $this->user = $user;
+ // TODO: Implement setUser() method.
+ throw new NotImplementedException;
}
/**
- * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
- * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+ * This method responds to the user's submission of an API key. Should do nothing but store the value.
+ *
+ * Errors must be returned in the message bag under the field name they are requested by.
*
- * @param Request $request
+ * @param array $data
*
* @return MessageBag
*/
- public function storePrerequisites(Request $request): MessageBag
+ public function storePrerequisites(array $data): MessageBag
{
- $apiKey = $request->get('api_key');
- $serverIP = $request->get('external_ip');
- Log::debug('Storing bunq API key');
- Preferences::setForUser($this->user, 'bunq_api_key', $apiKey);
- Preferences::setForUser($this->user, 'external_ip', $serverIP);
-
- return new MessageBag;
- }
-
- /**
- * @return bool
- */
- private function hasApiKey(): bool
- {
- $apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
- if (null === $apiKey) {
- return false;
- }
- if (null === $apiKey->data) {
- return false;
- }
- if (\strlen((string)$apiKey->data) === 64) {
- return true;
- }
-
- return false;
- }
-
- /**
- * @return bool
- */
- private function hasServerIP(): bool
- {
- $serverIP = Preferences::getForUser($this->user, 'external_ip', false);
- if (null === $serverIP) {
- return false;
- }
- if (null === $serverIP->data) {
- return false;
- }
- if (\strlen((string)$serverIP->data) > 6) {
- return true;
- }
-
- return false;
+ // TODO: Implement storePrerequisites() method.
+ throw new NotImplementedException;
}
}
diff --git a/app/Import/Prerequisites/FakePrerequisites.php b/app/Import/Prerequisites/FakePrerequisites.php
index e79dd3b337..ac8c07affb 100644
--- a/app/Import/Prerequisites/FakePrerequisites.php
+++ b/app/Import/Prerequisites/FakePrerequisites.php
@@ -39,6 +39,7 @@ class FakePrerequisites implements PrerequisitesInterface
/**
* Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
*
+ * @codeCoverageIgnore
* @return string
*/
public function getView(): string
@@ -59,7 +60,7 @@ class FakePrerequisites implements PrerequisitesInterface
}
$oldKey = (string)\request()->old('api_key');
if ($oldKey !== '') {
- $apiKey = \request()->old('api_key');
+ $apiKey = \request()->old('api_key'); // @codeCoverageIgnore
}
return ['api_key' => $apiKey];
@@ -87,13 +88,13 @@ class FakePrerequisites implements PrerequisitesInterface
}
/**
- * @param Request $request
+ * @param array $data
*
* @return MessageBag
*/
- public function storePrerequisites(Request $request): MessageBag
+ public function storePrerequisites(array $data): MessageBag
{
- $apiKey = (string)$request->get('api_key');
+ $apiKey = $data['api_key'] ?? '';
$messageBag = new MessageBag();
if (32 !== \strlen($apiKey)) {
$messageBag->add('api_key', 'API key must be 32 chars.');
diff --git a/app/Import/Prerequisites/FilePrerequisites.php b/app/Import/Prerequisites/FilePrerequisites.php
index ad299fee09..7e9ee6becc 100644
--- a/app/Import/Prerequisites/FilePrerequisites.php
+++ b/app/Import/Prerequisites/FilePrerequisites.php
@@ -34,17 +34,92 @@ use Illuminate\Support\MessageBag;
*/
class FilePrerequisites implements PrerequisitesInterface
{
- /** @var User */
- private $user;
-
+// /** @var User */
+// private $user;
+//
+// /**
+// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+// *
+// * @return string
+// */
+// public function getView(): string
+// {
+// return '';
+// }
+//
+// /**
+// * Returns any values required for the prerequisites-view.
+// *
+// * @return array
+// */
+// public function getViewParameters(): array
+// {
+// return [];
+// }
+//
+// /**
+// * Returns if this import method has any special prerequisites such as config
+// * variables or other things. The only thing we verify is the presence of the API key. Everything else
+// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
+// *
+// * True if prerequisites. False if not.
+// *
+// * @return bool
+// *
+// * @throws FireflyException
+// */
+// public function hasPrerequisites(): bool
+// {
+// if ($this->user->hasRole('demo')) {
+// throw new FireflyException('Apologies, the demo user cannot import files.');
+// }
+//
+// return false;
+// }
+//
+// /**
+// * Indicate if all prerequisites have been met.
+// *
+// * @return bool
+// */
+// public function isComplete(): bool
+// {
+// // has no prerequisites, so always return true.
+// return true;
+// }
+//
+// /**
+// * Set the user for this Prerequisites-routine. Class is expected to implement and save this.
+// *
+// * @param User $user
+// */
+// public function setUser(User $user): void
+// {
+// $this->user = $user;
+//
+// }
+//
+// /**
+// * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
+// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+// *
+// * @param Request $request
+// *
+// * @return MessageBag
+// */
+// public function storePrerequisites(Request $request): MessageBag
+// {
+// return new MessageBag;
+// }
/**
- * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+ * Returns view name that allows user to fill in prerequisites.
*
* @return string
*/
public function getView(): string
{
- return '';
+ // TODO: Implement getView() method.
+ throw new NotImplementedException;
}
/**
@@ -54,27 +129,8 @@ class FilePrerequisites implements PrerequisitesInterface
*/
public function getViewParameters(): array
{
- return [];
- }
-
- /**
- * Returns if this import method has any special prerequisites such as config
- * variables or other things. The only thing we verify is the presence of the API key. Everything else
- * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
- *
- * True if prerequisites. False if not.
- *
- * @return bool
- *
- * @throws FireflyException
- */
- public function hasPrerequisites(): bool
- {
- if ($this->user->hasRole('demo')) {
- throw new FireflyException('Apologies, the demo user cannot import files.');
- }
-
- return false;
+ // TODO: Implement getViewParameters() method.
+ throw new NotImplementedException;
}
/**
@@ -84,8 +140,8 @@ class FilePrerequisites implements PrerequisitesInterface
*/
public function isComplete(): bool
{
- // has no prerequisites, so always return true.
- return true;
+ // TODO: Implement isComplete() method.
+ throw new NotImplementedException;
}
/**
@@ -95,20 +151,22 @@ class FilePrerequisites implements PrerequisitesInterface
*/
public function setUser(User $user): void
{
- $this->user = $user;
-
+ // TODO: Implement setUser() method.
+ throw new NotImplementedException;
}
/**
- * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
- * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+ * This method responds to the user's submission of an API key. Should do nothing but store the value.
+ *
+ * Errors must be returned in the message bag under the field name they are requested by.
*
- * @param Request $request
+ * @param array $data
*
* @return MessageBag
*/
- public function storePrerequisites(Request $request): MessageBag
+ public function storePrerequisites(array $data): MessageBag
{
- return new MessageBag;
+ // TODO: Implement storePrerequisites() method.
+ throw new NotImplementedException;
}
}
diff --git a/app/Import/Prerequisites/PrerequisitesInterface.php b/app/Import/Prerequisites/PrerequisitesInterface.php
index 962147be49..588821eeca 100644
--- a/app/Import/Prerequisites/PrerequisitesInterface.php
+++ b/app/Import/Prerequisites/PrerequisitesInterface.php
@@ -64,9 +64,9 @@ interface PrerequisitesInterface
*
* Errors must be returned in the message bag under the field name they are requested by.
*
- * @param Request $request
+ * @param array $data
*
* @return MessageBag
*/
- public function storePrerequisites(Request $request): MessageBag;
+ public function storePrerequisites(array $data): MessageBag;
}
diff --git a/app/Import/Prerequisites/SpectrePrerequisites.php b/app/Import/Prerequisites/SpectrePrerequisites.php
index 1905ea2b6f..80bd702b4f 100644
--- a/app/Import/Prerequisites/SpectrePrerequisites.php
+++ b/app/Import/Prerequisites/SpectrePrerequisites.php
@@ -36,17 +36,168 @@ use Preferences;
*/
class SpectrePrerequisites implements PrerequisitesInterface
{
- /** @var User */
- private $user;
-
+// /** @var User */
+// private $user;
+//
+// /**
+// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+// *
+// * @return string
+// */
+// public function getView(): string
+// {
+// return 'import.spectre.prerequisites';
+// }
+//
+// /**
+// * Returns any values required for the prerequisites-view.
+// *
+// * @return array
+// */
+// public function getViewParameters(): array
+// {
+// $publicKey = $this->getPublicKey();
+// $subTitle = (string)trans('import.spectre_title');
+// $subTitleIcon = 'fa-archive';
+//
+// return compact('publicKey', 'subTitle', 'subTitleIcon');
+// }
+//
+// /**
+// * Returns if this import method has any special prerequisites such as config
+// * variables or other things. The only thing we verify is the presence of the API key. Everything else
+// * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
+// *
+// * @return bool
+// */
+// public function hasPrerequisites(): bool
+// {
+// $values = [
+// Preferences::getForUser($this->user, 'spectre_app_id', false),
+// Preferences::getForUser($this->user, 'spectre_secret', false),
+// ];
+// /** @var Preference $value */
+// foreach ($values as $value) {
+// if (false === $value->data || null === $value->data) {
+// Log::info(sprintf('Config var "%s" is missing.', $value->name));
+//
+// return true;
+// }
+// }
+// Log::debug('All prerequisites are here!');
+//
+// return false;
+// }
+//
+// /**
+// * Indicate if all prerequisites have been met.
+// *
+// * @return bool
+// */
+// public function isComplete(): bool
+// {
+// // return true when user has set the App Id and the Spectre Secret.
+// $values = [
+// Preferences::getForUser($this->user, 'spectre_app_id', false),
+// Preferences::getForUser($this->user, 'spectre_secret', false),
+// ];
+// $result = true;
+// /** @var Preference $value */
+// foreach ($values as $value) {
+// if (false === $value->data || null === $value->data) {
+// $result = false;
+// }
+// }
+//
+// return $result;
+// }
+//
+// /**
+// * Set the user for this Prerequisites-routine. Class is expected to implement and save this.
+// *
+// * @param User $user
+// */
+// public function setUser(User $user): void
+// {
+// $this->user = $user;
+//
+// }
+//
+// /**
+// * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
+// * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+// *
+// * @param Request $request
+// *
+// * @return MessageBag
+// */
+// public function storePrerequisites(Request $request): MessageBag
+// {
+// Log::debug('Storing Spectre API keys..');
+// Preferences::setForUser($this->user, 'spectre_app_id', $request->get('app_id'));
+// Preferences::setForUser($this->user, 'spectre_secret', $request->get('secret'));
+// Log::debug('Done!');
+//
+// return new MessageBag;
+// }
+//
+// /**
+// * This method creates a new public/private keypair for the user. This isn't really secure, since the key is generated on the fly with
+// * no regards for HSM's, smart cards or other things. It would require some low level programming to get this right. But the private key
+// * is stored encrypted in the database so it's something.
+// */
+// private function createKeyPair(): void
+// {
+// Log::debug('Generate new Spectre key pair for user.');
+// $keyConfig = [
+// 'digest_alg' => 'sha512',
+// 'private_key_bits' => 2048,
+// 'private_key_type' => OPENSSL_KEYTYPE_RSA,
+// ];
+// // Create the private and public key
+// $res = openssl_pkey_new($keyConfig);
+//
+// // Extract the private key from $res to $privKey
+// $privKey = '';
+// openssl_pkey_export($res, $privKey);
+//
+// // Extract the public key from $res to $pubKey
+// $pubKey = openssl_pkey_get_details($res);
+//
+// Preferences::setForUser($this->user, 'spectre_private_key', $privKey);
+// Preferences::setForUser($this->user, 'spectre_public_key', $pubKey['key']);
+// Log::debug('Created key pair');
+//
+// }
+//
+// /**
+// * Get a public key from the users preferences.
+// *
+// * @return string
+// */
+// private function getPublicKey(): string
+// {
+// Log::debug('get public key');
+// $preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
+// if (null === $preference) {
+// Log::debug('public key is null');
+// // create key pair
+// $this->createKeyPair();
+// }
+// $preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
+// Log::debug('Return public key for user');
+//
+// return $preference->data;
+// }
/**
- * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
+ * Returns view name that allows user to fill in prerequisites.
*
* @return string
*/
public function getView(): string
{
- return 'import.spectre.prerequisites';
+ // TODO: Implement getView() method.
+ throw new NotImplementedException;
}
/**
@@ -56,37 +207,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
*/
public function getViewParameters(): array
{
- $publicKey = $this->getPublicKey();
- $subTitle = (string)trans('import.spectre_title');
- $subTitleIcon = 'fa-archive';
-
- return compact('publicKey', 'subTitle', 'subTitleIcon');
- }
-
- /**
- * Returns if this import method has any special prerequisites such as config
- * variables or other things. The only thing we verify is the presence of the API key. Everything else
- * tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
- *
- * @return bool
- */
- public function hasPrerequisites(): bool
- {
- $values = [
- Preferences::getForUser($this->user, 'spectre_app_id', false),
- Preferences::getForUser($this->user, 'spectre_secret', false),
- ];
- /** @var Preference $value */
- foreach ($values as $value) {
- if (false === $value->data || null === $value->data) {
- Log::info(sprintf('Config var "%s" is missing.', $value->name));
-
- return true;
- }
- }
- Log::debug('All prerequisites are here!');
-
- return false;
+ // TODO: Implement getViewParameters() method.
+ throw new NotImplementedException;
}
/**
@@ -96,20 +218,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
*/
public function isComplete(): bool
{
- // return true when user has set the App Id and the Spectre Secret.
- $values = [
- Preferences::getForUser($this->user, 'spectre_app_id', false),
- Preferences::getForUser($this->user, 'spectre_secret', false),
- ];
- $result = true;
- /** @var Preference $value */
- foreach ($values as $value) {
- if (false === $value->data || null === $value->data) {
- $result = false;
- }
- }
-
- return $result;
+ // TODO: Implement isComplete() method.
+ throw new NotImplementedException;
}
/**
@@ -119,74 +229,22 @@ class SpectrePrerequisites implements PrerequisitesInterface
*/
public function setUser(User $user): void
{
- $this->user = $user;
-
+ // TODO: Implement setUser() method.
+ throw new NotImplementedException;
}
/**
- * This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
- * If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
+ * This method responds to the user's submission of an API key. Should do nothing but store the value.
*
- * @param Request $request
+ * Errors must be returned in the message bag under the field name they are requested by.
*
- * @return MessageBag
- */
- public function storePrerequisites(Request $request): MessageBag
- {
- Log::debug('Storing Spectre API keys..');
- Preferences::setForUser($this->user, 'spectre_app_id', $request->get('app_id'));
- Preferences::setForUser($this->user, 'spectre_secret', $request->get('secret'));
- Log::debug('Done!');
-
- return new MessageBag;
- }
-
- /**
- * This method creates a new public/private keypair for the user. This isn't really secure, since the key is generated on the fly with
- * no regards for HSM's, smart cards or other things. It would require some low level programming to get this right. But the private key
- * is stored encrypted in the database so it's something.
- */
- private function createKeyPair(): void
- {
- Log::debug('Generate new Spectre key pair for user.');
- $keyConfig = [
- 'digest_alg' => 'sha512',
- 'private_key_bits' => 2048,
- 'private_key_type' => OPENSSL_KEYTYPE_RSA,
- ];
- // Create the private and public key
- $res = openssl_pkey_new($keyConfig);
-
- // Extract the private key from $res to $privKey
- $privKey = '';
- openssl_pkey_export($res, $privKey);
-
- // Extract the public key from $res to $pubKey
- $pubKey = openssl_pkey_get_details($res);
-
- Preferences::setForUser($this->user, 'spectre_private_key', $privKey);
- Preferences::setForUser($this->user, 'spectre_public_key', $pubKey['key']);
- Log::debug('Created key pair');
-
- }
-
- /**
- * Get a public key from the users preferences.
+ * @param array $data
*
- * @return string
+ * @return MessageBag
*/
- private function getPublicKey(): string
+ public function storePrerequisites(array $data): MessageBag
{
- Log::debug('get public key');
- $preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
- if (null === $preference) {
- Log::debug('public key is null');
- // create key pair
- $this->createKeyPair();
- }
- $preference = Preferences::getForUser($this->user, 'spectre_public_key', null);
- Log::debug('Return public key for user');
-
- return $preference->data;
+ // TODO: Implement storePrerequisites() method.
+ throw new NotImplementedException;
}
}
diff --git a/app/Import/Routine/FakeRoutine.php b/app/Import/Routine/FakeRoutine.php
index 1894ebaac5..ea626e3e19 100644
--- a/app/Import/Routine/FakeRoutine.php
+++ b/app/Import/Routine/FakeRoutine.php
@@ -65,14 +65,15 @@ class FakeRoutine implements RoutineInterface
{
Log::debug(sprintf('Now in run() for fake routine with status: %s', $this->job->status));
if ($this->job->status !== 'running') {
- throw new FireflyException('This fake job should not be started.');
+ throw new FireflyException('This fake job should not be started.'); // @codeCoverageIgnore
}
switch ($this->job->stage) {
default:
- throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage));
+ throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage)); // @codeCoverageIgnore
case 'new':
- $handler = new StageNewHandler;
+ /** @var StageNewHandler $handler */
+ $handler = app(StageNewHandler::class);
$handler->run();
$this->repository->setStage($this->job, 'ahoy');
// set job finished this step:
@@ -80,13 +81,15 @@ class FakeRoutine implements RoutineInterface
return;
case 'ahoy':
- $handler = new StageAhoyHandler;
+ /** @var StageAhoyHandler $handler */
+ $handler = app(StageAhoyHandler::class);
$handler->run();
$this->repository->setStatus($this->job, 'need_job_config');
$this->repository->setStage($this->job, 'final');
break;
case 'final':
- $handler = new StageFinalHandler;
+ /** @var StageFinalHandler $handler */
+ $handler = app(StageFinalHandler::class);
$handler->setJob($this->job);
$transactions = $handler->getTransactions();
$this->repository->setStatus($this->job, 'provider_finished');
diff --git a/app/Import/Specifics/AbnAmroDescription.php b/app/Import/Specifics/AbnAmroDescription.php
index 47ab96db0a..9a6ab878d0 100644
--- a/app/Import/Specifics/AbnAmroDescription.php
+++ b/app/Import/Specifics/AbnAmroDescription.php
@@ -36,6 +36,7 @@ class AbnAmroDescription implements SpecificInterface
public $row;
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getDescription(): string
@@ -44,6 +45,7 @@ class AbnAmroDescription implements SpecificInterface
}
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getName(): string
@@ -81,7 +83,7 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is GEA/BEA-format, false otherwise
*/
- protected function parseABNAMRODescription()
+ protected function parseABNAMRODescription(): bool
{
// See if the current description is formatted in ABN AMRO format
if (preg_match('/ABN AMRO.{24} (.*)/', $this->row[7], $matches)) {
@@ -99,7 +101,7 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is GEA/BEAformat, false otherwise
*/
- protected function parseGEABEADescription()
+ protected function parseGEABEADescription(): bool
{
// See if the current description is formatted in GEA/BEA format
if (preg_match('/([BG]EA) +(NR:[a-zA-Z:0-9]+) +([0-9.\/]+) +([^,]*)/', $this->row[7], $matches)) {
@@ -124,7 +126,7 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is SEPA format, false otherwise
*/
- protected function parseSepaDescription()
+ protected function parseSepaDescription(): bool
{
// See if the current description is formatted as a SEPA plain description
if (preg_match('/^SEPA(.{28})/', $this->row[7], $matches)) {
@@ -178,7 +180,7 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is TRTP format, false otherwise
*/
- protected function parseTRTPDescription()
+ protected function parseTRTPDescription(): bool
{
// See if the current description is formatted in TRTP format
if (preg_match_all('!\/([A-Z]{3,4})\/([^/]*)!', $this->row[7], $matches, PREG_SET_ORDER)) {
@@ -196,7 +198,7 @@ class AbnAmroDescription implements SpecificInterface
switch (strtoupper($key)) {
case 'NAME':
- $this->row[8] = $name = $value;
+ $this->row[8] = $value;
break;
case 'REMI':
$newDescription = $value;
diff --git a/app/Import/Specifics/IngDescription.php b/app/Import/Specifics/IngDescription.php
index 4277a31df2..e4c7d7a920 100644
--- a/app/Import/Specifics/IngDescription.php
+++ b/app/Import/Specifics/IngDescription.php
@@ -38,6 +38,7 @@ class IngDescription implements SpecificInterface
public $row;
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getDescription(): string
@@ -46,6 +47,7 @@ class IngDescription implements SpecificInterface
}
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getName(): string
@@ -84,41 +86,29 @@ class IngDescription implements SpecificInterface
/**
* Add the Opposing name from cell 1 in the description for Betaalautomaten
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
- *
- * @return bool true
*/
- protected function addNameIngDescription()
+ protected function addNameIngDescription(): void
{
$this->row[8] = $this->row[1] . ' ' . $this->row[8];
-
- return true;
}
/**
* Remove IBAN number out of the description
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
- *
- * @return bool true
*/
- protected function removeIBANIngDescription()
+ protected function removeIBANIngDescription(): void
{
// Try replace the iban number with nothing. The IBAN nr is found in the third row
$this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]);
-
- return true;
}
/**
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ).
- *
- * @return bool true
*/
- protected function removeNameIngDescription()
+ protected function removeNameIngDescription(): void
{
// Try remove everything before the 'Omschrijving'
$this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]);
-
- return true;
}
/**
@@ -127,7 +117,7 @@ class IngDescription implements SpecificInterface
private function copyDescriptionToOpposite(): void
{
$search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen'];
- if (0 === \strlen($this->row[3])) {
+ if ('' === (string)$this->row[3]) {
$this->row[3] = trim(str_ireplace($search, '', $this->row[8]));
}
}
diff --git a/app/Import/Specifics/PresidentsChoice.php b/app/Import/Specifics/PresidentsChoice.php
index 6db235e8e8..ccf907092c 100644
--- a/app/Import/Specifics/PresidentsChoice.php
+++ b/app/Import/Specifics/PresidentsChoice.php
@@ -28,6 +28,7 @@ namespace FireflyIII\Import\Specifics;
class PresidentsChoice implements SpecificInterface
{
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getDescription(): string
@@ -36,6 +37,7 @@ class PresidentsChoice implements SpecificInterface
}
/**
+ * @codeCoverageIgnore
* @return string
*/
public static function getName(): string
diff --git a/tests/Unit/Import/Configuration/FileConfiguratorTest.php b/tests/Unit/Import/Configuration/FileConfiguratorTest.php
deleted file mode 100644
index a5bf52d6fd..0000000000
--- a/tests/Unit/Import/Configuration/FileConfiguratorTest.php
+++ /dev/null
@@ -1,688 +0,0 @@
-<?php
-/**
- * FileConfiguratorTest.php
- * Copyright (c) 2018 [email protected]
- *
- * 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\Import\Configuration;
-
-use FireflyIII\Import\Configuration\FileConfigurator;
-use FireflyIII\Models\ImportJob;
-use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
-use FireflyIII\Support\Import\Configuration\File\Initial;
-use FireflyIII\Support\Import\Configuration\File\Map;
-use FireflyIII\Support\Import\Configuration\File\Roles;
-use FireflyIII\Support\Import\Configuration\File\UploadConfig;
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class FileConfiguratorTest
- */
-class FileConfiguratorTest extends TestCase
-{
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::setJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfig
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
- */
- public function testConfigureJobInitial()
- {
- // data
- $config = ['stage' => 'initial'];
- $data = ['some' => 'array'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repository
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
-
- // assert that new initial is created:
- $processor = $this->mock(Initial::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
- $processor->shouldReceive('getWarningMessage')->andReturn('')->once();
-
- // config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->configureJob($data);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
- */
- public function testConfigureJobMap()
- {
- // data
- $config = ['stage' => 'map'];
- $data = ['some' => 'array'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repository
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Roles is created:
- $processor = $this->mock(Map::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
- $processor->shouldReceive('getWarningMessage')->andReturn('')->once();
-
- // config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->configureJob($data);
- }
-
- /**
- * Should throw a FireflyException when $job is null.
- *
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::__construct
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @expectedException \FireflyIII\Exceptions\FireflyException
- */
- public function testConfigureJobNoJob()
- {
- // config
- $configurator = new FileConfigurator();
- $configurator->configureJob([]);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage Cannot handle job stage "ready" in getConfigurationClass().
- */
- public function testConfigureJobReady()
- {
- // data
- $config = ['stage' => 'ready'];
- $data = ['some' => 'array'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->configureJob($data);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
- */
- public function testConfigureJobRoles()
- {
- $config = ['stage' => 'roles'];
- $data = ['some' => 'array'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Roles is created:
- $processor = $this->mock(Roles::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
- $processor->shouldReceive('getWarningMessage')->andReturn('')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->configureJob($data);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::configureJob
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getConfigurationClass
- */
- public function testConfigureJobUploadConfig()
- {
- // data
- $config = ['stage' => 'upload-config'];
- $data = ['some' => 'array'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new UploadConfig is created:
- $processor = $this->mock(UploadConfig::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('storeConfiguration')->withArgs([$data])->once()->andReturn(true);
- $processor->shouldReceive('getWarningMessage')->andReturn('')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->configureJob($data);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- */
- public function testGetNextDataInitial()
- {
- // data
- $config = ['stage' => 'initial'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Initial is created:
- $processor = $this->mock(Initial::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('getData')->once();
-
-
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * Should throw a FireflyException when $job is null.
- *
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- * @expectedException \FireflyIII\Exceptions\FireflyException
- */
- public function testGetNextDataNoJob()
- {
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $configurator = new FileConfigurator();
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- */
- public function testGetNextDataUploadConfig()
- {
- // data
- $config = ['stage' => 'upload-config'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Initial is created:
- $processor = $this->mock(UploadConfig::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('getData')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage Cannot handle job stage "ksksjje" in getConfigurationClass().
- */
- public function testGetNextDataUploadInvalid()
- {
- // data
- $config = ['stage' => 'ksksjje'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // should throw error
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- */
- public function testGetNextDataUploadMap()
- {
- // data:
- $config = ['stage' => 'map'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Initial is created:
- $processor = $this->mock(Map::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('getData')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage Cannot handle job stage "ready" in getConfigurationClass().
- */
- public function testGetNextDataUploadReady()
- {
- // data
- $config = ['stage' => 'ready'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextData
- */
- public function testGetNextDataUploadRoles()
- {
- // data
- $config = ['stage' => 'roles'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // assert that new Initial is created:
- $processor = $this->mock(Roles::class);
- $processor->shouldReceive('setJob')->withArgs([$job])->once();
- $processor->shouldReceive('getData')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextData();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- */
- public function testGetNextViewInitial()
- {
- // data
- $config = ['stage' => 'initial'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $view = $configurator->getNextView();
-
- // test
- $this->assertEquals('import.file.initial', $view);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage No view for stage "slkds903ms90k"
- */
- public function testGetNextViewInvalid()
- {
- // data
- $config = ['stage' => 'slkds903ms90k'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextView();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- */
- public function testGetNextViewMap()
- {
- // data
- $config = ['stage' => 'map'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $view = $configurator->getNextView();
-
- // test
- $this->assertEquals('import.file.map', $view);
- }
-
- /**
- * Should throw a FireflyException when $job is null.
- *
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- * @expectedException \FireflyIII\Exceptions\FireflyException
- */
- public function testGetNextViewNoJob()
- {
- $configurator = new FileConfigurator();
- $configurator->getNextView();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage No view for stage "ready"
- */
- public function testGetNextViewReady()
- {
- // data
- $config = ['stage' => 'ready'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run configx§
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $configurator->getNextView();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- */
- public function testGetNextViewRoles()
- {
- // data
- $config = ['stage' => 'roles'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $view = $configurator->getNextView();
-
- // test
- $this->assertEquals('import.file.roles', $view);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getNextView
- */
- public function testGetNextViewUploadConfig()
- {
- // data
- $config = ['stage' => 'upload-config'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $view = $configurator->getNextView();
-
- // test
- $this->assertEquals('import.file.upload-config', $view);
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getWarningMessage
- */
- public function testGetWarningMessage()
- {
- // data
- $config = ['stage' => 'upload-config'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->once();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $warning = $configurator->getWarningMessage();
-
- // test
- $this->assertEquals('', $warning);
-
- }
-
- /**
- * Should throw a FireflyException when $job is null.
- *
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::getWarningMessage
- * @expectedException \FireflyIII\Exceptions\FireflyException
- */
- public function testGetWarningMessageNoJob()
- {
- $configurator = new FileConfigurator();
- $configurator->getWarningMessage();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
- */
- public function testIsJobConfiguredFalse()
- {
- // data
- $config = ['stage' => 'upload-config'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $result = $configurator->isJobConfigured();
-
- // test
- $this->assertFalse($result);
- }
-
- /**
- * Should throw a FireflyException when $job is null.
- *
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
- * @expectedException \FireflyIII\Exceptions\FireflyException
- */
- public function testIsJobConfiguredNoJob()
- {
- $configurator = new FileConfigurator();
- $configurator->isJobConfigured();
- }
-
- /**
- * @covers \FireflyIII\Import\Configuration\FileConfigurator::isJobConfigured
- */
- public function testIsJobConfiguredTrue()
- {
- // data
- $config = ['stage' => 'ready'];
- $extended = ['steps' => 0, 'done' => 0];
- $job = $this->getJob($config);
-
- // mock repos
- $repository = $this->mock(ImportJobRepositoryInterface::class);
- $repository->shouldReceive('setUser')->withArgs([Mockery::any()])->once();
- $repository->shouldReceive('getConfiguration')->andReturn($config)->twice();
- $repository->shouldReceive('setConfiguration')->once();
- $repository->shouldReceive('getExtendedStatus')->andReturn($extended)->once();
- $repository->shouldReceive('setExtendedStatus')->once();
-
- // run config
- $configurator = new FileConfigurator();
- $configurator->setJob($job);
- $result = $configurator->isJobConfigured();
-
- // test
- $this->assertTrue($result);
- }
-
- /**
- * @param array $config
- *
- * @return ImportJob
- */
- protected function getJob(array $config): ImportJob
- {
- $job = new ImportJob;
- $job->file_type = 'file';
- $job->status = 'new';
- $job->key = 'x' . random_int(1, 100000);
- $job->user()->associate($this->user());
- $job->configuration = $config;
-
- return $job;
- }
-}
diff --git a/tests/Unit/Import/JobConfiguration/FakeJobConfigurationTest.php b/tests/Unit/Import/JobConfiguration/FakeJobConfigurationTest.php
new file mode 100644
index 0000000000..10027d3dbe
--- /dev/null
+++ b/tests/Unit/Import/JobConfiguration/FakeJobConfigurationTest.php
@@ -0,0 +1,593 @@
+<?php
+/**
+ * FakeJobConfigurationTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\JobConfiguration;
+
+use FireflyIII\Import\JobConfiguration\FakeJobConfiguration;
+use FireflyIII\Models\ImportJob;
+use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
+use Mockery;
+use Tests\TestCase;
+
+/**
+ * Class FakeJobConfigurationTest
+ */
+class FakeJobConfigurationTest extends TestCase
+{
+ /**
+ * No config, job is new.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCC(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'A_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertFalse($configurator->configurationComplete());
+ }
+
+ /**
+ * No config, job is not new.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCAlbumFalse(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'B_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'needs_config';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertFalse($configurator->configurationComplete());
+ }
+
+ /**
+ * Job only says to apply rules.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCApplyRules(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'C_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'apply-rules' => true,
+ ];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertFalse($configurator->configurationComplete());
+ }
+
+ /**
+ * Job has album but wrong one.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCBadAlbum(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'D_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'config';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'song' => 'golden years',
+ 'artist' => 'david bowie',
+ 'album' => 'some album',
+ 'apply-rules' => true,
+ ];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertFalse($configurator->configurationComplete());
+ }
+
+ /**
+ * Job has album + song, but bad content.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCBadInfo(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'E_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'song' => 'some song',
+ 'artist' => 'david bowie',
+ 'apply-rules' => true,
+ ];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertFalse($configurator->configurationComplete());
+ }
+
+ /**
+ * Job has correct album
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCGoodAlbum(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'f_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'config';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'song' => 'golden years',
+ 'artist' => 'david bowie',
+ 'album' => 'station to station',
+ 'apply-rules' => true,
+ ];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertTrue($configurator->configurationComplete());
+ }
+
+ /**
+ * Job has correct content for "new"!
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testCCGoodNewInfo(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'g_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [
+ 'song' => 'golden years',
+ 'artist' => 'david bowie',
+ 'apply-rules' => true,
+ ];
+ $job->save();
+
+ // should be false:
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $this->assertTrue($configurator->configurationComplete());
+ }
+
+ /**
+ * Apply rules with submitted "false"
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobARFalse(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'h_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['apply_rules' => 0];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), ['apply-rules' => false]])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Apply rules with submitted "false"
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobARTrue(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'i_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['apply_rules' => 1];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), ['apply-rules' => true]])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with bad song.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobBadAlbum(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'j_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['album' => 'Station to Bowie'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), []])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with bad artist.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobBadArtist(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'k_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['artist' => 'DaViD BoWXXXXXiE'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), []])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with bad song.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobBadSong(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'l_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['song' => 'Golden Bowie'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), []])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with good album.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobGoodAlbum(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'm_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['album' => 'Station to Station'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), ['album' => 'station to station']])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with good artist.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobGoodArtist(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'n_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['artist' => 'DaViD BoWiE'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), ['artist' => 'david bowie']])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Submit job with good song.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testConfigureJobGoodSong(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'o_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock repository:
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // data to submit:
+ $data = ['song' => 'Golden Years'];
+
+ // expect the config to update:
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setConfiguration')
+ ->withArgs([Mockery::any(), ['song' => 'golden years']])->once();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $messages = $configurator->configureJob($data);
+ $this->assertTrue($messages->has('some_key'));
+ }
+
+ /**
+ * Have rules, have artist, have song, must ask album
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testGetNextViewAlbum(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'p_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'not_new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = ['apply-rules' => false, 'artist' => 'david bowie', 'song' => 'golden years'];
+ $job->save();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $view = $configurator->getNextView();
+ $this->assertEquals('import.fake.enter-album', $view);
+ }
+
+ /**
+ * Have rules, must ask artist
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testGetNextViewArtist(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'p_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = ['apply-rules' => false];
+ $job->save();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $view = $configurator->getNextView();
+ $this->assertEquals('import.fake.enter-artist', $view);
+ }
+
+ /**
+ * With empty config, should return view for rules.
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testGetNextViewRules(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'p_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $view = $configurator->getNextView();
+ $this->assertEquals('import.fake.apply-rules', $view);
+ }
+
+ /**
+ * Have rules, have artist, must ask song
+ *
+ * @covers \FireflyIII\Import\JobConfiguration\FakeJobConfiguration
+ */
+ public function testGetNextViewSong(): void
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'p_unit_' . random_int(1, 1000);
+ $job->status = 'new';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = ['apply-rules' => false, 'artist' => 'david bowie'];
+ $job->save();
+
+ // call configuration
+ $configurator = new FakeJobConfiguration;
+ $configurator->setJob($job);
+ $view = $configurator->getNextView();
+ $this->assertEquals('import.fake.enter-song', $view);
+ }
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Object/ImportAccountTest.php b/tests/Unit/Import/Object/ImportAccountTest.php
deleted file mode 100644
index b527883ba7..0000000000
--- a/tests/Unit/Import/Object/ImportAccountTest.php
+++ /dev/null
@@ -1,127 +0,0 @@
-<?php
-/**
- * ImportAccountTest.php
- * Copyright (c) 2018 [email protected]
- *
- * 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\Import\Object;
-
-use FireflyIII\Import\Object\ImportAccount;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
-use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-
-use Mockery;
-use Tests\TestCase;
-
-/**
- * Class ImportAccountTest
- */
-class ImportAccountTest extends TestCase
-{
-
- /**
- * Should error because it requires a default asset account.
- *
- * @covers \FireflyIII\Import\Object\ImportAccount
- */
- public function testBasic()
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $accountType = AccountType::where('type', AccountType::ASSET)->first();
- $account = Account::find(1);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
- $repository->shouldReceive('getAccountType')->twice()->withArgs([AccountType::ASSET])->andReturn($accountType);
- //$repository->shouldReceive('getAccountsByType')->twice()->withArgs([[AccountType::ASSET]])->andReturn(new Collection());
- $repository->shouldReceive('findNull')->once()->withArgs([1])->andReturn($account);
-
- // create import account.
- $importAccount = new ImportAccount;
- $importAccount->setUser($this->user());
- $importAccount->setDefaultAccountId(1);
- $found = $importAccount->getAccount();
- $this->assertEquals(1, $found->id);
-
- }
-
- /**
- * Should error because it requires a default asset account.
- *
- * @covers \FireflyIII\Import\Object\ImportAccount
- */
- public function testEmptyMappingAccountId()
- {
- // mock stuff
- $repository = $this->mock(AccountRepositoryInterface::class);
- $accountType = AccountType::where('type', AccountType::ASSET)->first();
- $account = Account::find(1);
-
- // mock calls:
- $repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
- $repository->shouldReceive('getAccountType')->once()->withArgs([AccountType::ASSET])->andReturn($accountType);
-
- // create import account.
- $importAccount = new ImportAccount;
- $importAccount->setUser($this->user());
- $importAccount->setDefaultAccountId(1);
-
- // add an account id:
- $accountId = [
- 'role' => 'account-id',
- 'mapped' => null,
- 'value' => 2,
- ];
- $importAccount->setAccountId($accountId);
-
-
- $found = $importAccount->getAccount();
- $this->assertEquals(2, $found->id);
-
- }
-
- /**
- * @covers \FireflyIII\Import\Object\ImportAccount
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage ImportAccount cannot continue without a default account to fall back on.
- */
- public function testNoAccount()
- {
- $repository = $this->mock(AccountRepositoryInterface::class);
- $repository->shouldReceive('setUser')->once()->withArgs([Mockery::any()]);
- $importAccount = new ImportAccount;
- $importAccount->setUser($this->user());
- $importAccount->getAccount();
- }
-
- /**
- * @covers \FireflyIII\Import\Object\ImportAccount
- * @expectedException \FireflyIII\Exceptions\FireflyException
- * @expectedExceptionMessage ImportAccount cannot continue without user.
- */
- public function testNoUser()
- {
- $this->mock(AccountRepositoryInterface::class);
- $importAccount = new ImportAccount;
- $importAccount->getAccount();
- }
-}
diff --git a/tests/Unit/Import/Prerequisites/FakePrerequisitesTest.php b/tests/Unit/Import/Prerequisites/FakePrerequisitesTest.php
new file mode 100644
index 0000000000..dd15107619
--- /dev/null
+++ b/tests/Unit/Import/Prerequisites/FakePrerequisitesTest.php
@@ -0,0 +1,174 @@
+<?php
+/**
+ * FakePrerequisitesTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Prerequisites;
+
+
+use FireflyIII\Import\Prerequisites\FakePrerequisites;
+use FireflyIII\Models\Preference;
+use Mockery;
+use Preferences;
+use Tests\TestCase;
+
+/**
+ * Class FakePrerequisitesTest
+ */
+class FakePrerequisitesTest extends TestCase
+{
+ /**
+ * Bad API key length in preferences
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testGetViewParametersBadLength(): void
+ {
+ // API key should be empty:
+ $apiPref = new Preference;
+ $apiPref->data = 'abc';
+
+ Preferences::shouldReceive('getForUser')
+ ->withArgs([Mockery::any(), 'fake_api_key', false])->once()
+ ->andReturn($apiPref);
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $result = $object->getViewParameters();
+ $this->assertEquals(['api_key' => ''], $result);
+ }
+
+ /**
+ * No API key in preference.
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testGetViewParametersDataNull(): void
+ {
+ // API key should be empty:
+ $apiPref = new Preference;
+ $apiPref->data = null;
+
+ Preferences::shouldReceive('getForUser')
+ ->withArgs([Mockery::any(), 'fake_api_key', false])->once()
+ ->andReturn($apiPref);
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $result = $object->getViewParameters();
+ $this->assertEquals(['api_key' => ''], $result);
+ }
+
+ /**
+ * Good API key length in preferences
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testGetViewParametersGoodLength(): void
+ {
+ // API key should be empty:
+ $apiPref = new Preference;
+ $apiPref->data = '123456789012345678901234567890AA';
+
+ Preferences::shouldReceive('getForUser')
+ ->withArgs([Mockery::any(), 'fake_api_key', false])->twice()
+ ->andReturn($apiPref);
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $result = $object->getViewParameters();
+ $this->assertEquals(['api_key' => '123456789012345678901234567890AA'], $result);
+ }
+
+ /**
+ * No preference at all.
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testGetViewParametersPrefNull(): void
+ {
+ Preferences::shouldReceive('getForUser')
+ ->withArgs([Mockery::any(), 'fake_api_key', false])->once()
+ ->andReturn(null);
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $result = $object->getViewParameters();
+ $this->assertEquals(['api_key' => ''], $result);
+ }
+
+ /**
+ * Also test hasApiKey but that one is covered.
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testIsComplete(): void
+ {
+ // API key should be empty:
+ $apiPref = new Preference;
+ $apiPref->data = null;
+
+ Preferences::shouldReceive('getForUser')
+ ->withArgs([Mockery::any(), 'fake_api_key', false])->once()
+ ->andReturn($apiPref);
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $this->assertFalse($object->isComplete());
+ }
+
+ /**
+ * Also test hasApiKey but that one is covered.
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testStorePrerequisitesBad(): void
+ {
+ $data = [
+ 'api_key' => 'Hallo',
+ ];
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $messages = $object->storePrerequisites($data);
+ $this->assertCount(1, $messages);
+ $this->assertEquals('API key must be 32 chars.', $messages->first());
+ }
+
+ /**
+ * Also test hasApiKey but that one is covered.
+ *
+ * @covers \FireflyIII\Import\Prerequisites\FakePrerequisites
+ */
+ public function testStorePrerequisitesGood(): void
+ {
+ $data = [
+ 'api_key' => '123456789012345678901234567890AA',
+ ];
+
+ Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'fake_api_key', '123456789012345678901234567890AA'])->once();
+
+ $object = new FakePrerequisites();
+ $object->setUser($this->user());
+ $messages = $object->storePrerequisites($data);
+ $this->assertCount(0, $messages);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Routine/FakeRoutineTest.php b/tests/Unit/Import/Routine/FakeRoutineTest.php
new file mode 100644
index 0000000000..70d21d4e21
--- /dev/null
+++ b/tests/Unit/Import/Routine/FakeRoutineTest.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * FakeRoutineTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Routine;
+
+use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Import\Routine\FakeRoutine;
+use FireflyIII\Models\ImportJob;
+use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
+use FireflyIII\Support\Import\Routine\Fake\StageAhoyHandler;
+use FireflyIII\Support\Import\Routine\Fake\StageFinalHandler;
+use FireflyIII\Support\Import\Routine\Fake\StageNewHandler;
+use Mockery;
+use Tests\TestCase;
+
+/**
+ * Class FakeRoutineTest
+ */
+class FakeRoutineTest extends TestCase
+{
+ /**
+ * @covers \FireflyIII\Import\Routine\FakeRoutine
+ */
+ public function testRunAhoy()
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'a_route_' . random_int(1, 1000);
+ $job->status = 'running';
+ $job->stage = 'ahoy';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock
+ $handler = $this->mock(StageAhoyHandler::class);
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // calls
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'need_job_config'])->once();
+ $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
+ $handler->shouldReceive('run')->once();
+
+
+ $routine = new FakeRoutine;
+ $routine->setJob($job);
+ try {
+ $routine->run();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Import\Routine\FakeRoutine
+ */
+ public function testRunFinal()
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'a_route_' . random_int(1, 1000);
+ $job->status = 'running';
+ $job->stage = 'final';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock
+ $handler = $this->mock(StageFinalHandler::class);
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // calls
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
+ $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
+ $repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), []])->once();
+ $handler->shouldReceive('getTransactions')->once()->andReturn([]);
+ $handler->shouldReceive('setJob')->once();
+
+ $routine = new FakeRoutine;
+ $routine->setJob($job);
+ try {
+ $routine->run();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * @covers \FireflyIII\Import\Routine\FakeRoutine
+ */
+ public function testRunNew()
+ {
+ $job = new ImportJob;
+ $job->user_id = $this->user()->id;
+ $job->key = 'a_route_' . random_int(1, 1000);
+ $job->status = 'running';
+ $job->stage = 'new';
+ $job->provider = 'fake';
+ $job->file_type = '';
+ $job->configuration = [];
+ $job->save();
+
+ // mock
+ $handler = $this->mock(StageNewHandler::class);
+ $repository = $this->mock(ImportJobRepositoryInterface::class);
+
+ // calls
+ $repository->shouldReceive('setUser')->once();
+ $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'ahoy'])->once();
+ $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->once();
+ $handler->shouldReceive('run')->once();
+
+
+ $routine = new FakeRoutine;
+ $routine->setJob($job);
+ try {
+ $routine->run();
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php b/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php
new file mode 100644
index 0000000000..97ace313bb
--- /dev/null
+++ b/tests/Unit/Import/Specifics/AbnAmroDescriptionTest.php
@@ -0,0 +1,168 @@
+<?php
+/**
+ * AbnAmroDescriptionTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Specifics;
+
+
+use FireflyIII\Import\Specifics\AbnAmroDescription;
+use Tests\TestCase;
+
+/**
+ * Class AbnAmroDescriptionTest
+ */
+class AbnAmroDescriptionTest extends TestCase
+{
+ /**
+ * Should return the exact same array.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testEmptyRow(): void
+ {
+ $row = [1, 2, 3, 4];
+
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals($row, $result);
+ }
+
+ /**
+ * Data that cannot be parsed.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testParseABN(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'ABN AMRO 12345678901234567890ABC SomeOtherDescr', ''];
+
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('SomeOtherDescr', $result[7]);
+ $this->assertEquals('ABN AMRO', $result[8]);
+ }
+
+ /**
+ * GEA
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testParseGea(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'BEA: GEA NR:00AJ01 31.01.01/19.54 Van HarenSchoenen132 UDE,PAS333', ''];
+
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Van HarenSchoenen132 UDE', $result[8]);
+ $this->assertEquals('GEA Van HarenSchoenen132 UDE', $result[7]);
+ }
+
+ /**
+ * Gea bea
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testParseGeaBea(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'BEA: BEA NR:00AJ01 31.01.01/19.54 Van HarenSchoenen132 UDE,PAS333', ''];
+
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Van HarenSchoenen132 UDE', $result[8]);
+ $this->assertEquals('Van HarenSchoenen132 UDE', $result[7]);
+ }
+
+ /**
+ * Data that cannot be parsed.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testParseUnknown(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'Blabla', ''];
+
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Unknown', $result[8]);
+ }
+
+ /**
+ * Basic SEPA data.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testSepaBasic(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: 1232138 1232131233 412321 iBOOD.com iBOOD.com B.V. Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('1232138 1232131233 412321 iBOOD.com iBOOD.com B.V.', $result[7]);
+ $this->assertEquals('Silver Ocean B.V.', $result[8]);
+ $this->assertEquals('NL12RABO0121212212', $result[9]);
+ }
+
+ /**
+ * Basic SEPA data.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testSepaBasicNoDescription(): void
+ {
+ $row = [0, 1, 2, 3, 4, 5, 6, 'SEPA PLAIN: SEPA iDEAL IBAN: NL12RABO0121212212 BIC: RABONL2U Naam: Silver Ocean B.V. Omschrijving: Kenmerk: 12-12-2014 21:03 002000 0213123238', '',''];
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals(' PLAIN: SEPA iDEAL - Silver Ocean B.V. (12-12-2014)', $result[7]);
+ $this->assertEquals('Silver Ocean B.V.', $result[8]);
+ $this->assertEquals('NL12RABO0121212212', $result[9]);
+ }
+
+ /**
+ * Basic TRTP data.
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testTRTPBasic(): void {
+
+ $row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI/Nullijn/EREF/NOTPROVIDED', '',''];
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Nullijn', $result[7]);
+ $this->assertEquals('baasd dsdsT CJ', $result[8]);
+ $this->assertEquals('NL23ABNA0000000000', $result[9]);
+ }
+ /**
+ * Basic TRTP data with empty description
+ *
+ * @covers \FireflyIII\Import\Specifics\AbnAmroDescription
+ */
+ public function testTRTPEmptyDescr(): void {
+
+ $row = [0, 1, 2, 3, 4, 5, 6, '/TRTP/SEPA OVERBOEKING/IBAN/NL23ABNA0000000000/BIC/ABNANL2A/NAME/baasd dsdsT CJ/REMI//EREF/NOTPROVIDED', '',''];
+ $parser = new AbnAmroDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('SEPA OVERBOEKING - (NOTPROVIDED)', $result[7]);
+ $this->assertEquals('baasd dsdsT CJ', $result[8]);
+ $this->assertEquals('NL23ABNA0000000000', $result[9]);
+ }
+
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Specifics/IngDescriptionTest.php b/tests/Unit/Import/Specifics/IngDescriptionTest.php
new file mode 100644
index 0000000000..70638e13a3
--- /dev/null
+++ b/tests/Unit/Import/Specifics/IngDescriptionTest.php
@@ -0,0 +1,138 @@
+<?php
+/**
+ * IngDescriptionTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Specifics;
+
+
+use FireflyIII\Import\Specifics\IngDescription;
+use Tests\TestCase;
+
+/**
+ * Class IngDescriptionTest
+ */
+class IngDescriptionTest extends TestCase
+{
+ /**
+ * Try if the IBAN is removed in GT transactions
+ *
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunGTRemoveIban(): void
+ {
+ $iban = 'NL66INGB0665877351';
+ $row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Should be removed', $result[8]);
+ }
+
+ /**
+ * Try if the IBAN is removed in OV transactions
+ *
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunOVRemoveIban(): void
+ {
+ $iban = 'NL66INGB0665877351';
+ $row = [0, 1, 2, $iban, 'OV', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Should be removed', $result[8]);
+ }
+
+ /**
+ * Try if the IBAN is removed in IC transactions
+ *
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunICRemoveIban(): void
+ {
+ $iban = 'NL66INGB0665877351';
+ $row = [0, 1, 2, $iban, 'IC', 5, 6, 7, 'Should be removed IBAN: ' . $iban, 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Should be removed', $result[8]);
+ }
+
+ /**
+ * Empty description? Use "tegenrekening".
+ * Remove specific fields.
+ *
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunEmptyDescr(): void
+ {
+ $row = [0, 1, 2, '', 'GT', 5, 6, 7, 'Naar Oranje Spaarrekening Bla bla', 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Bla bla', $result[3]);
+ }
+
+ /**
+ * Test changes to BA row.
+ *
+ * Remove specific fields.
+ *
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunBABasic(): void
+ {
+ $row = [0, 'XX', 2, '', 'BA', 5, 6, 7, 'XX', 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('XX XX', $result[8]);
+ }
+
+ /**
+ * See if the description is removed
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunGTRemoveDescr(): void
+ {
+ $iban = 'NL66INGB0665877351';
+ $row = [0, 1, 2, $iban, 'GT', 5, 6, 7, 'Bla bla bla Omschrijving: Should be removed IBAN: ' . $iban, 9, 10];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+ $this->assertEquals('Should be removed', $result[8]);
+ }
+
+ /**
+ * @covers \FireflyIII\Import\Specifics\IngDescription
+ */
+ public function testRunShortArray(): void
+ {
+ $row = [0, 1, 2, 3];
+
+ $parser = new IngDescription;
+ $result = $parser->run($row);
+
+ $this->assertEquals($row, $result);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Specifics/PresidentsChoiceTest.php b/tests/Unit/Import/Specifics/PresidentsChoiceTest.php
new file mode 100644
index 0000000000..d6e509f880
--- /dev/null
+++ b/tests/Unit/Import/Specifics/PresidentsChoiceTest.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * PresidentsChoiceTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Specifics;
+
+
+use FireflyIII\Import\Specifics\PresidentsChoice;
+use Tests\TestCase;
+
+/**
+ * Class PresidentsChoiceTest
+ */
+class PresidentsChoiceTest extends TestCase
+{
+
+ /**
+ * @covers \FireflyIII\Import\Specifics\PresidentsChoice
+ */
+ public function testRunBasic():void {
+ $row = [''];
+
+ $parser = new PresidentsChoice;
+ $result = $parser->run($row);
+ $this->assertEquals($row, $result);
+
+ }
+
+ /**
+ * @covers \FireflyIII\Import\Specifics\PresidentsChoice
+ */
+ public function testRunAmount():void {
+ $row = ['','Descr','12.34','',''];
+
+ $parser = new PresidentsChoice;
+ $result = $parser->run($row);
+ $this->assertEquals('-12.34', $result[3]);
+ $this->assertEquals('Descr', $result[2]);
+
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/Specifics/RabobankDescriptionTest.php b/tests/Unit/Import/Specifics/RabobankDescriptionTest.php
new file mode 100644
index 0000000000..fd5d07af19
--- /dev/null
+++ b/tests/Unit/Import/Specifics/RabobankDescriptionTest.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * RabobankDescriptionTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Import\Specifics;
+
+
+use Tests\TestCase;
+
+/**
+ * Class RabobankDescriptionTest
+ */
+class RabobankDescriptionTest extends TestCase
+{
+ public function testRunBasic(): void
+ {
+ $this->assertTrue(true);
+ }
+
+}
\ No newline at end of file