Skip to content

Firefly III: a personal finances manager

This fixes most of the tests.

James Cole500243b0b38c
diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.php
index bed0cb6b0a..43873f9070 100644
--- a/app/Helpers/Csv/Importer.php
+++ b/app/Helpers/Csv/Importer.php
@@ -187,7 +187,7 @@ class Importer
// some debug info:
$journalId = $journal->id;
- $type = $journal->getTransactionType();
+ $type = $journal->transaction_type_type ?? $journal->transactionType->type;
/** @var Account $asset */
$asset = $this->importData['asset-account-object'];
/** @var Account $opposing */
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index e17b254012..d9444f8182 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -99,7 +99,7 @@ class TransactionController extends Controller
*/
public function delete(TransactionJournal $journal)
{
- $what = strtolower($journal->getTransactionType());
+ $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);
// put previous url in session
@@ -141,6 +141,9 @@ class TransactionController extends Controller
*/
public function edit(ARI $repository, TransactionJournal $journal)
{
+ // get journal again:
+ /** @var TransactionJournal $journal */
+ $journal = TransactionJournal::expanded()->where('transaction_journals.id', $journal->id)->first(TransactionJournal::QUERYFIELDS);
// cannot edit opening balance
if ($journal->isOpeningBalance()) {
throw new FireflyException('Cannot edit this transaction (#' . $journal->id . '). Edit the account instead!');
@@ -150,7 +153,7 @@ class TransactionController extends Controller
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
- $what = strtolower($journal->getTransactionType());
+ $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
$budgets[0] = trans('form.noBudget');
@@ -183,15 +186,19 @@ class TransactionController extends Controller
$preFilled['amount'] = $journal->amount_positive;
if ($journal->isWithdrawal()) {
- $preFilled['account_id'] = $journal->source_account->id;
- $preFilled['expense_account'] = $journal->destination_account->name_for_editform;
+ $preFilled['account_id'] = $journal->source_account_id;
+ if ($journal->destination_account_type != 'Cash account') {
+ $preFilled['expense_account'] = $journal->destination_account_name;
+ }
} else {
- $preFilled['account_id'] = $journal->destination_account->id;
- $preFilled['revenue_account'] = $journal->source_account->name_for_editform;
+ $preFilled['account_id'] = $journal->destination_account_id;
+ if ($journal->source_account_type != 'Cash account') {
+ $preFilled['revenue_account'] = $journal->source_account_name;
+ }
}
- $preFilled['account_from_id'] = $journal->source_account->id;
- $preFilled['account_to_id'] = $journal->destination_account->id;
+ $preFilled['account_from_id'] = $journal->source_account_id;
+ $preFilled['account_to_id'] = $journal->destination_account_id;
Session::flash('preFilled', $preFilled);
Session::flash('gaEventCategory', 'transactions');
@@ -279,8 +286,8 @@ class TransactionController extends Controller
$t->after = bcadd($t->before, $t->amount);
}
);
- $what = strtolower($journal->getTransactionType());
- $subTitle = trans('firefly.' . $journal->getTransactionType()) . ' "' . e($journal->description) . '"';
+ $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
+ $subTitle = trans('firefly.' . $journal->transaction_type_type ?? $journal->transactionType->type) . ' "' . e($journal->description) . '"';
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what'));
}
@@ -314,7 +321,6 @@ class TransactionController extends Controller
if (count($att->getMessages()->get('attachments')) > 0) {
Session::flash('info', $att->getMessages()->get('attachments'));
}
- Log::debug('Before event. From account name is: ' . $journal->source_account->name);
event(new TransactionJournalStored($journal, intval($request->get('piggy_bank_id'))));
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 1a03020f3a..f779600bc9 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -44,6 +44,19 @@ use Watson\Validating\ValidatingTrait;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal after($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal before($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal transactionTypes($types)
+ *
+ * @property-read string $transaction_type_type
+ * @property-read string $transaction_currency_code
+ * @property-read string $destination_amount
+ * @property-read string $destination_account_id
+ * @property-read string $destination_account_name
+ * @property-read string $destination_account_type
+ * @property-read string $source_amount
+ * @property-read string $source_account_id
+ * @property-read string $source_account_name
+ * @property-read string $source_account_type
+
+ *
*/
class TransactionJournal extends BaseModel
{
diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php
index 73937fbb53..0bfc4f8aed 100644
--- a/app/Rules/Triggers/FromAccountIs.php
+++ b/app/Rules/Triggers/FromAccountIs.php
@@ -53,7 +53,8 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal)
{
- $fromAccountName = strtolower($journal->source_account->name);
+ $sourceAccount = $journal->transactions()->where('amount', '<', 0)->first()->account;
+ $fromAccountName = strtolower($sourceAccount->name);
$search = strtolower($this->triggerValue);
if ($fromAccountName == $search) {
diff --git a/phpunit.xml b/phpunit.xml
index 2664543d0a..31ac89bcfe 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
- stopOnFailure="false">
+ stopOnFailure="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
diff --git a/tests/acceptance/Controllers/ReportControllerTest.php b/tests/acceptance/Controllers/ReportControllerTest.php
index b5a7c4c8bf..60246642b0 100644
--- a/tests/acceptance/Controllers/ReportControllerTest.php
+++ b/tests/acceptance/Controllers/ReportControllerTest.php
@@ -7,13 +7,14 @@
* of the MIT license. See the LICENSE file for details.
*/
+use FireflyIII\Helpers\Collection\Account as AccountCollection;
+use FireflyIII\Helpers\Collection\Balance;
use FireflyIII\Helpers\Collection\Bill as BillCollection;
+use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
use FireflyIII\Helpers\Collection\Expense;
use FireflyIII\Helpers\Collection\Income;
-use FireflyIII\Helpers\Collection\Account as AccountCollection;
-use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
-use FireflyIII\Helpers\Collection\Balance;
+use Illuminate\Support\Collection;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:28.
@@ -48,12 +49,11 @@ class ReportControllerTest extends TestCase
{
// mock some stuff.
$accountHelper = $this->mock('FireflyIII\Helpers\Report\AccountReportHelperInterface');
- $budgetHelper = $this->mock('FireflyIII\Helpers\Report\BudgetReportHelperInterface');
+ $budgetHelper = $this->mock('FireflyIII\Helpers\Report\BudgetReportHelperInterface');
$balanceHelper = $this->mock('FireflyIII\Helpers\Report\BalanceReportHelperInterface');
$defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
-
$accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
$defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
$defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
@@ -79,6 +79,22 @@ class ReportControllerTest extends TestCase
public function testReportDefaultMultiYear($range)
{
$this->be($this->user());
+
+ // mock some stuff.
+ $accountHelper = $this->mock('FireflyIII\Helpers\Report\AccountReportHelperInterface');
+ $defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
+ $budgetRepos = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
+ $categoryRepos = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
+
+ $budgetRepos->shouldReceive('getActiveBudgets')->once()->andReturn(new Collection);
+ $categoryRepos->shouldReceive('listCategories')->once()->andReturn(new Collection);
+
+
+ $accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
+ $defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
+ $defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
+ $defaultHelper->shouldReceive('tagReport')->once()->andReturn([]);
+
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/reports/report/default/20160101/20171231/1,2');
$this->assertResponseStatus(200);
@@ -93,6 +109,18 @@ class ReportControllerTest extends TestCase
*/
public function testReportDefaultYear($range)
{
+
+ // mock some stuff.
+ $accountHelper = $this->mock('FireflyIII\Helpers\Report\AccountReportHelperInterface');
+ $defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
+
+
+ $accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
+ $defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
+ $defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
+ $defaultHelper->shouldReceive('tagReport')->once()->andReturn([]);
+
+
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/reports/report/default/20160101/20161231/1,2');