mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Update test code.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Tests\Unit\Support\Import\Configuration\File;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Import\Mapper\Budgets;
|
||||
use FireflyIII\Import\MapperPreProcess\TagsSpace;
|
||||
use FireflyIII\Import\Specifics\IngDescription;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
@@ -333,7 +334,7 @@ class ConfigureMappingHandlerTest extends TestCase
|
||||
$job->save();
|
||||
|
||||
$combinations = [
|
||||
['role' => 'tags-space', 'expected' => '\\FireflyIII\\Import\\MapperPreProcess\\TagsSpace'], // tags- space has a pre-processor. Return it.
|
||||
['role' => 'tags-space', 'expected' => TagsSpace::class], // tags- space has a pre-processor. Return it.
|
||||
['role' => 'description', 'expected' => ''], // description has not.
|
||||
['role' => 'no-such-role', 'expected' => ''], // not existing role has not.
|
||||
];
|
||||
|
748
tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php
Normal file
748
tests/Unit/Support/Import/Placeholder/ImportTransactionTest.php
Normal file
@@ -0,0 +1,748 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportTransactionTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Placeholder;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Support\Import\Placeholder\ColumnValue;
|
||||
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ImportTransactionTest
|
||||
*/
|
||||
class ImportTransactionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test what happens when you set the account-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVAccountIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('account-id');
|
||||
$columnValue->setOriginalRole('account-name');
|
||||
$columnValue->setValue('Checking Account');
|
||||
$columnValue->setMappedValue(1);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->accountId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the account-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVAccountIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('account-id');
|
||||
$columnValue->setValue('1');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->accountId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the bill-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVBillIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('bill-id');
|
||||
$columnValue->setOriginalRole('bill-name');
|
||||
$columnValue->setValue('Some Bill');
|
||||
$columnValue->setMappedValue(2);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->billId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->billId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the bill-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVBillIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('bill-id');
|
||||
$columnValue->setValue('2');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->billId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->billId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the budget-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVBudgetIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('budget-id');
|
||||
$columnValue->setOriginalRole('budget-name');
|
||||
$columnValue->setValue('Some Budget');
|
||||
$columnValue->setMappedValue(3);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->budgetId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the budget-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVBudgetIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('budget-id');
|
||||
$columnValue->setValue('3');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->budgetId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the category-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVCategoryIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('category-id');
|
||||
$columnValue->setOriginalRole('category-name');
|
||||
$columnValue->setValue('Some category');
|
||||
$columnValue->setMappedValue(5);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->categoryId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the category-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVCategoryIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('category-id');
|
||||
$columnValue->setValue('5');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->categoryId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the currency-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVCurrencyIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('currency-id');
|
||||
$columnValue->setOriginalRole('currency-code');
|
||||
$columnValue->setValue('EUR');
|
||||
$columnValue->setMappedValue(4);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->currencyId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->currencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the currency-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVCurrencyIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('currency-id');
|
||||
$columnValue->setValue('4');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->currencyId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->currencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the foreign-currency-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVForeignCurrencyIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('foreign-currency-id');
|
||||
$columnValue->setOriginalRole('foreign-currency-code');
|
||||
$columnValue->setValue('USD');
|
||||
$columnValue->setMappedValue(6);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->foreignCurrencyId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->foreignCurrencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the category-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVForeignCurrencyIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('foreign-currency-id');
|
||||
$columnValue->setValue('6');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->foreignCurrencyId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->foreignCurrencyId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test what happens when you set the opposing-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVOpposingIdMapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('opposing-id');
|
||||
$columnValue->setOriginalRole('opposing-name');
|
||||
$columnValue->setValue('Some Opposing');
|
||||
$columnValue->setMappedValue(7);
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->opposingId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($columnValue->getMappedValue(), $importTransaction->opposingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when you set the opposing-id using a ColumnValue.
|
||||
* Since this field can be mapped. Test with both the mapped and unmapped variant.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVOpposingIdUnmapped(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('opposing-id');
|
||||
$columnValue->setValue('7');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals(0, $importTransaction->opposingId);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals((int)$columnValue->getValue(), $importTransaction->opposingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test various unmapped fields, and the result that the ImportTransaction should display.
|
||||
*
|
||||
* Put into one big test to save time.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testACVOtherValues(): void
|
||||
{
|
||||
$tests = [
|
||||
'account-iban' => 'accountIban',
|
||||
'account-name' => 'accountName',
|
||||
'account-bic' => 'accountBic',
|
||||
'account-number' => 'accountNumber',
|
||||
'amount_debit' => 'amountDebit',
|
||||
'amount_credit' => 'amountCredit',
|
||||
'amount' => 'amount',
|
||||
'amount_foreign' => 'foreignAmount',
|
||||
'bill-name' => 'billName',
|
||||
'budget-name' => 'budgetName',
|
||||
'category-name' => 'categoryName',
|
||||
'currency-code' => 'currencyCode',
|
||||
'currency-name' => 'currencyName',
|
||||
'currency-symbol' => 'currencySymbol',
|
||||
'external-id' => 'externalId',
|
||||
'foreign-currency-code' => 'foreignCurrencyCode',
|
||||
'date-transaction' => 'date',
|
||||
'opposing-iban' => 'opposingIban',
|
||||
'opposing-name' => 'opposingName',
|
||||
'opposing-bic' => 'opposingBic',
|
||||
'opposing-number' => 'opposingNumber',
|
||||
];
|
||||
foreach ($tests as $role => $field) {
|
||||
// generate random value
|
||||
$value = bin2hex(random_bytes(16));
|
||||
|
||||
// put into column value:
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole($role);
|
||||
$columnValue->setValue($value);
|
||||
|
||||
// first test should always return NULL
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertNull($importTransaction->$field);
|
||||
|
||||
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
// after setting, should return value.
|
||||
$this->assertEquals($value, $importTransaction->$field);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountBasic(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->amount = '1.23';
|
||||
try {
|
||||
$this->assertEquals('1.23', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountCredit(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->amountCredit = '1.56';
|
||||
try {
|
||||
$this->assertEquals('1.56', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountDebit(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->amountDebit = '1.01';
|
||||
try {
|
||||
$this->assertEquals('-1.01', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* With no amount data, object should return ''
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountEmpty(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
try {
|
||||
$this->assertEquals('', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic amount info with negative modifier (Rabobank D)
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountNeg(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->amount = '2.99';
|
||||
$importTransaction->modifiers['rabo-debit-credit'] = 'D';
|
||||
try {
|
||||
$this->assertEquals('-2.99', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic amount info with positive modifier (Rabobank C)
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testCalculateAmountPos(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->amount = '-2.17';
|
||||
$importTransaction->modifiers['rabo-debit-credit'] = 'C';
|
||||
try {
|
||||
$this->assertEquals('2.17', $importTransaction->calculateAmount());
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debit Credit indicator is special.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testDebitCredit(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('ing-debit-credit');
|
||||
$columnValue->setValue('Af');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertCount(0, $importTransaction->modifiers);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertCount(1, $importTransaction->modifiers);
|
||||
$this->assertEquals('Af', $importTransaction->modifiers['ing-debit-credit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description should be appended.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testDescription(): void
|
||||
{
|
||||
$one = new ColumnValue;
|
||||
$one->setRole('description');
|
||||
$one->setValue('A');
|
||||
|
||||
$two = new ColumnValue;
|
||||
$two->setRole('description');
|
||||
$two->setValue('B');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals('', $importTransaction->description);
|
||||
try {
|
||||
$importTransaction->addColumnValue($one);
|
||||
$importTransaction->addColumnValue($two);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals('A B', $importTransaction->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic foreign amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testForeignAmountBasic(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->foreignAmount = '1.23';
|
||||
$this->assertEquals('1.23', $importTransaction->calculateForeignAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic foreign amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testForeignAmountEmpty(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals('', $importTransaction->calculateForeignAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign amount with modifier that should make it negative again.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testForeignAmountModNeg(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->foreignAmount = '6.77';
|
||||
$importTransaction->modifiers['rabo-debit-credit'] = 'D';
|
||||
$this->assertEquals('-6.77', $importTransaction->calculateForeignAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign amount with modifier that should make it positive again.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testForeignAmountModPos(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->foreignAmount = '-5.77';
|
||||
$importTransaction->modifiers['rabo-debit-credit'] = 'C';
|
||||
$this->assertEquals('5.77', $importTransaction->calculateForeignAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic foreign amount info. Should return something like '1.0'.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testForeignAmountNeg(): void
|
||||
{
|
||||
$importTransaction = new ImportTransaction;
|
||||
$importTransaction->foreignAmount = '-4.56';
|
||||
$this->assertEquals('-4.56', $importTransaction->calculateForeignAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore field must be ignored.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testIgnore(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('_ignore');
|
||||
$columnValue->setValue('Bla bla bla');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a meta value, see what happens. Any will do.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testMetaValue(): void
|
||||
{
|
||||
$columnValue = new ColumnValue;
|
||||
$columnValue->setRole('date-process');
|
||||
$columnValue->setValue('2018-01-01');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertCount(0, $importTransaction->meta);
|
||||
try {
|
||||
$importTransaction->addColumnValue($columnValue);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertCount(1, $importTransaction->meta);
|
||||
$this->assertEquals($columnValue->getValue(), $importTransaction->meta['date-process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description should be appended.
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testNote(): void
|
||||
{
|
||||
$one = new ColumnValue;
|
||||
$one->setRole('note');
|
||||
$one->setValue('A');
|
||||
|
||||
$two = new ColumnValue;
|
||||
$two->setRole('note');
|
||||
$two->setValue('B');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertEquals('', $importTransaction->note);
|
||||
try {
|
||||
$importTransaction->addColumnValue($one);
|
||||
$importTransaction->addColumnValue($two);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals('A B', $importTransaction->note);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test tags with a comma separator
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testTagsComma(): void
|
||||
{
|
||||
$one = new ColumnValue;
|
||||
$one->setRole('tags-comma');
|
||||
$one->setValue('a,b,c');
|
||||
|
||||
$two = new ColumnValue;
|
||||
$two->setRole('tags-comma');
|
||||
$two->setValue('d,e,c');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertCount(0, $importTransaction->tags);
|
||||
try {
|
||||
$importTransaction->addColumnValue($one);
|
||||
$importTransaction->addColumnValue($two);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertCount(5, $importTransaction->tags);
|
||||
$this->assertEquals('a', $importTransaction->tags[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test tags with a space separator
|
||||
*
|
||||
* @covers \FireflyIII\Support\Import\Placeholder\ImportTransaction
|
||||
*/
|
||||
public function testTagsSpace(): void
|
||||
{
|
||||
$one = new ColumnValue;
|
||||
$one->setRole('tags-space');
|
||||
$one->setValue('a b c');
|
||||
|
||||
$two = new ColumnValue;
|
||||
$two->setRole('tags-space');
|
||||
$two->setValue('d e c');
|
||||
|
||||
$importTransaction = new ImportTransaction;
|
||||
$this->assertCount(0, $importTransaction->tags);
|
||||
try {
|
||||
$importTransaction->addColumnValue($one);
|
||||
$importTransaction->addColumnValue($two);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertCount(5, $importTransaction->tags);
|
||||
$this->assertEquals('a', $importTransaction->tags[0]);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportableCreatorTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Routine\File;
|
||||
|
||||
|
||||
use FireflyIII\Support\Import\Placeholder\ColumnValue;
|
||||
use FireflyIII\Support\Import\Placeholder\ImportTransaction;
|
||||
use FireflyIII\Support\Import\Routine\File\ImportableCreator;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ImportableCreatorTest
|
||||
*/
|
||||
class ImportableCreatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Routine\File\ImportableCreator
|
||||
*/
|
||||
public function testConvertSets(): void
|
||||
{
|
||||
$columnValue =new ColumnValue();
|
||||
$columnValue->setOriginalRole('account-name');
|
||||
$columnValue->setRole('account-id');
|
||||
$columnValue->setValue('Checking Account');
|
||||
$columnValue->setMappedValue(1);
|
||||
|
||||
$input = [
|
||||
[
|
||||
$columnValue
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$creator = new ImportableCreator;
|
||||
$result = $creator->convertSets($input);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertInstanceOf(ImportTransaction::class, $result[0]);
|
||||
$this->assertEquals(1, $result[0]->accountId);
|
||||
|
||||
}
|
||||
|
||||
}
|
102
tests/Unit/Support/Import/Routine/File/LineReaderTest.php
Normal file
102
tests/Unit/Support/Import/Routine/File/LineReaderTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* LineReaderTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Routine\File;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Import\Specifics\IngDescription;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Routine\File\LineReader;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class LineReaderTest
|
||||
*/
|
||||
class LineReaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Routine\File\LineReader
|
||||
*/
|
||||
public function testGetLines(): void
|
||||
{
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'linerA' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = [
|
||||
'specifics' => [
|
||||
'IngDescription' => 1,
|
||||
'BadSpecific' => 1,
|
||||
],
|
||||
'has-headers' => true,
|
||||
'delimiter' => ',',
|
||||
];
|
||||
$job->save();
|
||||
|
||||
$att = new Attachment;
|
||||
$att->filename = 'import_file';
|
||||
$att->user_id = $this->user()->id;
|
||||
$att->attachable_id = $job->id;
|
||||
$att->attachable_type = Attachment::class;
|
||||
$att->md5 = md5('hello');
|
||||
$att->mime = 'fake';
|
||||
$att->size = 3;
|
||||
$att->save();
|
||||
|
||||
// mock repositories:
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$attachments = $this->mock(AttachmentHelperInterface::class);
|
||||
$specific = $this->mock(IngDescription::class);
|
||||
|
||||
// fake file content:
|
||||
$content = "header1,header2,header3\ncolumn1,column2,column3\nA,B,C";
|
||||
$specifics = [['column1', 'column2', 'column3'], ['A', 'B', 'C']];
|
||||
|
||||
// mock calls and returns:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getAttachments')->once()->andReturn(new Collection([$att]));
|
||||
$attachments->shouldReceive('getAttachmentContent')->andReturn($content)->once();
|
||||
$repository->shouldReceive('getConfiguration')->once()->andReturn($job->configuration);
|
||||
|
||||
// expect the rows to be run throught the specific.
|
||||
$specific->shouldReceive('run')->withArgs([$specifics[0]])->andReturn($specifics[0])->once();
|
||||
$specific->shouldReceive('run')->withArgs([$specifics[1]])->andReturn($specifics[1])->once();
|
||||
|
||||
$lineReader = new LineReader;
|
||||
$lineReader->setImportJob($job);
|
||||
try {
|
||||
$lines = $lineReader->getLines();
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($specifics, $lines);
|
||||
}
|
||||
|
||||
}
|
154
tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
Normal file
154
tests/Unit/Support/Import/Routine/File/MappingConvergerTest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* MappingConvergerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Support\Import\Routine\File;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Support\Import\Routine\File\MappingConverger;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class MappingConvergerTest
|
||||
*/
|
||||
class MappingConvergerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Support\Import\Routine\File\MappingConverger
|
||||
*/
|
||||
public function testConverge(): void
|
||||
{
|
||||
|
||||
// configuration
|
||||
$config = [
|
||||
'column-roles' => [
|
||||
0 => 'account-name',
|
||||
1 => 'bill-name',
|
||||
2 => 'budget-name',
|
||||
3 => 'currency-code',
|
||||
4 => 'category-name',
|
||||
5 => 'foreign-currency-code',
|
||||
6 => 'opposing-number',
|
||||
7 => 'description',
|
||||
8 => 'opposing-iban',
|
||||
],
|
||||
'column-mapping-config' => [
|
||||
0 => [
|
||||
'Checking Account' => 1,
|
||||
],
|
||||
1 => [
|
||||
'BillX' => 2,
|
||||
],
|
||||
2 => [
|
||||
'BudgetX' => 2,
|
||||
],
|
||||
3 => [
|
||||
'EUR' => 7,
|
||||
],
|
||||
4 => [
|
||||
'CategoryX' => 2,
|
||||
],
|
||||
5 => [
|
||||
'USD' => 4,
|
||||
],
|
||||
6 => [
|
||||
'SomeNumber' => 3,
|
||||
],
|
||||
8 => [
|
||||
'IBANX' => 2,
|
||||
],
|
||||
],
|
||||
'column-do-mapping' => [
|
||||
0 => true,
|
||||
1 => true,
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => true,
|
||||
5 => true,
|
||||
6 => true,
|
||||
7 => false,
|
||||
8 => false,
|
||||
],
|
||||
];
|
||||
|
||||
// just one line to process (should hit everything).
|
||||
$lines = [
|
||||
[
|
||||
0 => 'Checking Account',
|
||||
1 => 'BillX',
|
||||
2 => 'BudgetX',
|
||||
3 => 'EUR',
|
||||
4 => 'CategoryX',
|
||||
5 => 'USD',
|
||||
6 => 'SomeNumber',
|
||||
7 => 'I am a description',
|
||||
8 => 'IBANX'
|
||||
],
|
||||
[
|
||||
0 => 'CheckingX Account',
|
||||
1 => 'BillXA',
|
||||
2 => 'BudgetBX',
|
||||
3 => 'EUD',
|
||||
4 => 'CategoryX',
|
||||
5 => 'USA',
|
||||
6 => 'SomeANumber',
|
||||
7 => 'I am X description',
|
||||
8 => 'IBANXX'
|
||||
],
|
||||
];
|
||||
|
||||
$job = new ImportJob;
|
||||
$job->user_id = $this->user()->id;
|
||||
$job->key = 'linerA' . random_int(1, 1000);
|
||||
$job->status = 'new';
|
||||
$job->stage = 'new';
|
||||
$job->provider = 'fake';
|
||||
$job->file_type = '';
|
||||
$job->configuration = $config;
|
||||
$job->save();
|
||||
|
||||
|
||||
$converger = new MappingConverger;
|
||||
$converger->setImportJob($job);
|
||||
try {
|
||||
$result = $converger->converge($lines);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
// do some comparing, we know what to expect.
|
||||
|
||||
// line 0, column 0 is the account name.
|
||||
$this->assertEquals($lines[0][0], $result[0][0]->getValue());
|
||||
$this->assertEquals($config['column-roles'][0], $result[0][0]->getOriginalRole());
|
||||
$this->assertEquals('account-id', $result[0][0]->getRole()); // role changed due to mapping.
|
||||
$this->assertEquals(1, $result[0][0]->getMappedValue()); // can see which value it was given.
|
||||
|
||||
// line 1, column 0 is the account name, but it could not be mapped.
|
||||
$this->assertEquals($lines[1][0], $result[1][0]->getValue());
|
||||
$this->assertEquals($config['column-roles'][0], $result[1][0]->getOriginalRole());
|
||||
$this->assertEquals($config['column-roles'][0], $result[1][0]->getRole()); // role did not change, no mapping.
|
||||
$this->assertEquals(0, $result[1][0]->getMappedValue()); // value of mapping is 0.
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user