Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix tests and fix coverage.
James Coledb020db34bca
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.phpindex 575d35c383..59cbb56219 100644--- a/app/Http/Controllers/TransactionController.php+++ b/app/Http/Controllers/TransactionController.php@@ -157,7 +157,7 @@ class TransactionController extends Controller}$preFilled['amount'] = $journal->actual_amount;- $preFilled['account_id'] = $journal->asset_account->id;+ $preFilled['account_id'] = $journal->destination_account->id;$preFilled['expense_account'] = $transactions[0]->account->name;$preFilled['revenue_account'] = $transactions[1]->account->name;$preFilled['account_from_id'] = $transactions[1]->account->id;diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex 8b2a5f68c6..73de69784b 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Database\Eloquent\SoftDeletes;+use Log;use Watson\Validating\ValidatingTrait;/**@@ -71,7 +72,7 @@ use Watson\Validating\ValidatingTrait;* @property-read mixed $correct_amount* @method static \FireflyIII\Models\TransactionJournal orderBy* @method static \FireflyIII\Models\TransactionJournal|null first- * @property-read mixed $source_account+ * @property-read mixed $source_account*/class TransactionJournal extends Model{@@ -220,24 +221,19 @@ class TransactionJournal extends Model}/**- * @return Account+ * @return string*/- public function getAssetAccountAttribute()+ public function getCorrectAmountAttribute(){- // if it's a deposit, it's the one thats positive- // if it's a withdrawal, it's the one thats negative- // otherwise, it's either (return first one):switch ($this->transactionType->type) {case 'Deposit':- return $this->transactions()->where('amount', '>', 0)->first()->account;+ return $this->transactions()->where('amount', '>', 0)->first()->amount;case 'Withdrawal':- return $this->transactions()->where('amount', '<', 0)->first()->account;-+ return $this->transactions()->where('amount', '<', 0)->first()->amount;}- return $this->transactions()->first()->account;-+ return '0';}/**@@ -249,22 +245,6 @@ class TransactionJournal extends Modelreturn $this->hasMany('FireflyIII\Models\Transaction');}- /**- * @return string- */- public function getCorrectAmountAttribute()- {-- switch ($this->transactionType->type) {- case 'Deposit':- return $this->transactions()->where('amount', '>', 0)->first()->amount;- case 'Withdrawal':- return $this->transactions()->where('amount', '<', 0)->first()->amount;- }-- return '0';- }-/*** @codeCoverageIgnore* @return string[]@@ -308,27 +288,6 @@ class TransactionJournal extends Modelreturn $account;}- /**- * @return Account- */- public function getExpenseAccountAttribute()- {- // if it's a deposit, it's the one thats negative- // if it's a withdrawal, it's the one thats positive- // otherwise, it's either (return first one):-- switch ($this->transactionType->type) {- case 'Deposit':- return $this->transactions()->where('amount', '<', 0)->first()->account;- case 'Withdrawal':- return $this->transactions()->where('amount', '>', 0)->first()->account;-- }-- return $this->transactions()->first()->account;-- }-/*** @return Account*/@@ -341,6 +300,7 @@ class TransactionJournal extends Modelreturn $cache->get(); // @codeCoverageIgnore}$account = $this->transactions()->where('amount', '<', 0)->first()->account;+$cache->store($account);return $account;diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex 3e01105bd5..626b3f6ea2 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -53,11 +53,14 @@ class EventServiceProvider extends ServiceProvider$this->registerCreateEvents();BudgetLimit::saved(function(BudgetLimit $budgetLimit) {+ Log::debug('Saved!');$end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0);$end->subDay();- $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))- ->get();+ $set = $budgetLimit->limitrepetitions()+ ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00'))+ ->where('enddate', $end->format('Y-m-d 00:00:00'))+ ->get();if ($set->count() == 0) {$repetition = new LimitRepetition;$repetition->startdate = $budgetLimit->startdate;@@ -68,8 +71,7 @@ class EventServiceProvider extends ServiceProvidertry {$repetition->save();} catch (QueryException $e) {- Log::error('Trying to save new LimitRepetition failed!');- Log::error($e->getMessage());+ Log::error('Trying to save new LimitRepetition failed: '.$e->getMessage()); // @codeCoverageIgnore}} else {if ($set->count() == 1) {diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex 54ee071c66..3aa4a34b6f 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -265,7 +265,7 @@ class BillRepository implements BillRepositoryInterface$amountMatch = false;$wordMatch = false;$matches = explode(',', $bill->match);- $description = strtolower($journal->description) . ' ' . strtolower($journal->expense_account->name);+ $description = strtolower($journal->description) . ' ' . strtolower($journal->destination_account->name);$count = 0;foreach ($matches as $word) {if (!(strpos($description, strtolower($word)) === false)) {diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.phpindex a7fb12f50a..9e1758310b 100644--- a/app/Repositories/Journal/JournalRepository.php+++ b/app/Repositories/Journal/JournalRepository.php@@ -48,11 +48,6 @@ class JournalRepository implements JournalRepositoryInterface*/public function delete(TransactionJournal $journal){- // delete transactions first:- /** @var Transaction $transaction */- foreach ($journal->transactions()->get() as $transaction) {- $transaction->delete();- }$journal->delete();return true;diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.phpindex 5f02c0ce5a..276f190821 100644--- a/app/Repositories/Tag/TagRepository.php+++ b/app/Repositories/Tag/TagRepository.php@@ -318,7 +318,7 @@ class TagRepository implements TagRepositoryInterface$match = true;/** @var TransactionJournal $check */foreach ($tag->transactionjournals as $check) {- if ($check->asset_account->id != $journal->asset_account->id) {+ if ($check->source_account->id != $journal->source_account->id) {$match = false;}}diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex c492e5471a..0d4c2a6534 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -36,7 +36,7 @@ class Amountpublic function getCurrencySymbol(){if (defined('FFCURRENCYSYMBOL')) {- return FFCURRENCYSYMBOL;+ return FFCURRENCYSYMBOL; // @codeCoverageIgnore}$currencyPreference = Prefs::get('currencyPreference', 'EUR');@@ -149,7 +149,7 @@ class Amountpublic function getCurrencyCode(){if (defined('FFCURRENCYCODE')) {- return FFCURRENCYCODE;+ return FFCURRENCYCODE; // @codeCoverageIgnore}diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.phpindex f210309c59..f0e1c760ee 100644--- a/app/Support/CacheProperties.php+++ b/app/Support/CacheProperties.php@@ -9,6 +9,7 @@ use Carbon\Carbon;use Illuminate\Database\Eloquent\Collection as EloquentCollection;use Illuminate\Support\Collection;use Preferences as Prefs;+use Log;/*** Class CacheProperties@@ -62,6 +63,9 @@ class CacheProperties*/public function has(){+ if(getenv('APP_ENV') == 'testing') {+ return false;+ }$this->md5();return Cache::has($this->md5);diff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex 0fd7d8a184..0a1d287566 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -36,7 +36,6 @@ class Preferencesreturn Cache::get($fullName);}-$preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']);if ($preference) {diff --git a/tests/controllers/TransactionControllerTest.php b/tests/controllers/TransactionControllerTest.phpindex 9c672ac1cc..c778f49de2 100644--- a/tests/controllers/TransactionControllerTest.php+++ b/tests/controllers/TransactionControllerTest.php@@ -97,6 +97,8 @@ class TransactionControllerTest extends TestCase*/public function testEdit(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);// make complete journal:$accountType = FactoryMuffin::create('FireflyIII\Models\AccountType');$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.phpindex 23e547620c..307584cb84 100644--- a/tests/models/TransactionJournalModelTest.php+++ b/tests/models/TransactionJournalModelTest.php@@ -235,103 +235,6 @@ class TransactionJournalModelTest extends TestCase}- /**- * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute- */- public function testGetAssetAccountAttributeDeposit()- {- FactoryMuffin::create('FireflyIII\Models\TransactionType');-- // make withdrawal- $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');- $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $deposit->transaction_type_id = $depositType->id;- $deposit->save();-- // make accounts- FactoryMuffin::create('FireflyIII\Models\Account');- $revenue = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-- // update transactions- $deposit->transactions[0]->account_id = $asset->id;- $deposit->transactions[0]->amount = 300;- $deposit->transactions[0]->save();-- $deposit->transactions[1]->account_id = $revenue->id;- $deposit->transactions[1]->amount = -300;- $deposit->transactions[1]->save();--- // get asset account:- $result = $deposit->asset_account;-- $this->assertEquals($asset->id, $result->id);- }-- /**- * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute- */- public function testGetAssetAccountAttributeFallback()- {-- FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal- FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit-- // make accounts- FactoryMuffin::create('FireflyIII\Models\Account');- $revenue = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-- // make withdrawal- $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer- $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $transfer->transaction_type_id = $transferType->id;- $transfer->save();-- $transfer->transactions[0]->account_id = $asset->id;- $transfer->transactions[0]->amount = 300;- $transfer->transactions[0]->save();-- $transfer->transactions[1]->account_id = $revenue->id;- $transfer->transactions[1]->amount = -300;- $transfer->transactions[1]->save();-- // get asset account:- $result = $transfer->asset_account;-- $this->assertEquals($asset->id, $result->id);- }-- /**- * @covers FireflyIII\Models\TransactionJournal::getAssetAccountAttribute- */- public function testGetAssetAccountAttributeWithdrawal()- {- // make accounts- $expense = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-- // make withdrawal- $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');- $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $withdrawal->transaction_type_id = $withdrawalType->id;- $withdrawal->save();--- $withdrawal->transactions[0]->account_id = $asset->id;- $withdrawal->transactions[0]->amount = -300;- $withdrawal->transactions[0]->save();-- $withdrawal->transactions[1]->account_id = $expense->id;- $withdrawal->transactions[1]->amount = 300;- $withdrawal->transactions[1]->save();-- // get asset account:- $result = $withdrawal->asset_account;-- $this->assertEquals($asset->id, $result->id);- }/*** @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute@@ -434,6 +337,8 @@ class TransactionJournalModelTest extends TestCase*/public function testGetDestinationAccountAttribute(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);FactoryMuffin::create('FireflyIII\Models\TransactionType');$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');@@ -462,8 +367,10 @@ class TransactionJournalModelTest extends TestCase/*** @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute*/- public function testGetDestinationAccountAttributeFallback()+ public function testGetSourceAccountAttribute(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);FactoryMuffin::create('FireflyIII\Models\TransactionType');$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');@@ -475,36 +382,6 @@ class TransactionJournalModelTest extends TestCase$revenue = FactoryMuffin::create('FireflyIII\Models\Account');$asset = FactoryMuffin::create('FireflyIII\Models\Account');- $deposit->transactions[0]->account_id = $asset->id;- $deposit->transactions[0]->amount = -300;- $deposit->transactions[0]->save();-- $deposit->transactions[1]->account_id = $revenue->id;- $deposit->transactions[1]->amount = -300;- $deposit->transactions[1]->save();-- // get asset account:- $result = $deposit->destination_account;-- $this->assertEquals($asset->id, $result->id);- }-- /**- * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute- */- public function testGetExpenseAccountAttribute()- {- FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal- $depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit- $deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $deposit->transaction_type_id = $depositType->id;- $deposit->save();-- // make accounts- FactoryMuffin::create('FireflyIII\Models\Account');- $revenue = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-$deposit->transactions[0]->account_id = $asset->id;$deposit->transactions[0]->amount = 300;$deposit->transactions[0]->save();@@ -514,69 +391,9 @@ class TransactionJournalModelTest extends TestCase$deposit->transactions[1]->save();// get asset account:- $result = $deposit->expense_account;+ $result = $deposit->source_account;$this->assertEquals($revenue->id, $result->id);}- /**- * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute- */- public function testGetExpenseAccountAttributeFallback()- {- FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal- FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit- $transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer- $transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $transfer->transaction_type_id = $transferType->id;- $transfer->save();-- // make accounts- FactoryMuffin::create('FireflyIII\Models\Account');- $revenue = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-- $transfer->transactions[0]->account_id = $asset->id;- $transfer->transactions[0]->amount = 300;- $transfer->transactions[0]->save();-- $transfer->transactions[1]->account_id = $revenue->id;- $transfer->transactions[1]->amount = -300;- $transfer->transactions[1]->save();-- // get asset account:- $result = $transfer->expense_account;-- $this->assertEquals($asset->id, $result->id);- }-- /**- * @covers FireflyIII\Models\TransactionJournal::getExpenseAccountAttribute- */- public function testGetExpenseAccountAttributeWithdrawal()- {- $withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal- $withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $withdrawal->transaction_type_id = $withdrawalType->id;- $withdrawal->save();-- // make accounts- FactoryMuffin::create('FireflyIII\Models\Account');- $revenue = FactoryMuffin::create('FireflyIII\Models\Account');- $asset = FactoryMuffin::create('FireflyIII\Models\Account');-- $withdrawal->transactions[0]->account_id = $asset->id;- $withdrawal->transactions[0]->amount = 300;- $withdrawal->transactions[0]->save();-- $withdrawal->transactions[1]->account_id = $revenue->id;- $withdrawal->transactions[1]->amount = -300;- $withdrawal->transactions[1]->save();-- // get asset account:- $result = $withdrawal->expense_account;-- $this->assertEquals($asset->id, $result->id);- }-}diff --git a/tests/repositories/AccountRepositoryTest.php b/tests/repositories/AccountRepositoryTest.phpindex 876a5c4286..6a17b5d564 100644--- a/tests/repositories/AccountRepositoryTest.php+++ b/tests/repositories/AccountRepositoryTest.php@@ -51,11 +51,21 @@ class AccountRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\Account\AccountRepository::destroy+ * @covers FireflyIII\Providers\EventServiceProvider::boot+ * @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents*/public function testDestroy(){// create account:- $account = FactoryMuffin::create('FireflyIII\Models\Account');+ $account = FactoryMuffin::create('FireflyIII\Models\Account');++ // create some transactions and attach them to the account:+ for ($i = 0; $i < 5; $i++) {+ $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction');+ $transaction->account_id = $account->id;+ $transaction->save();+ }+$accountId = $account->id;$this->be($account->user);@@ -462,7 +472,7 @@ class AccountRepositoryTest extends TestCase/** Transfers can go either way (see the amount)*/- if($i < 4) {+ if ($i < 4) {$amount = 100;} else {$amount = -100;diff --git a/tests/repositories/BillRepositoryTest.php b/tests/repositories/BillRepositoryTest.phpindex 2e22d58e7a..57ef8932e0 100644--- a/tests/repositories/BillRepositoryTest.php+++ b/tests/repositories/BillRepositoryTest.php@@ -303,6 +303,8 @@ class BillRepositoryTest extends TestCase*/public function testScanMatch(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);$bill = FactoryMuffin::create('FireflyIII\Models\Bill');$bill->date = new Carbon('2012-01-07');$bill->repeat_freq = 'monthly';@@ -319,24 +321,6 @@ class BillRepositoryTest extends TestCase$journal->user_id = $bill->user_id;$journal->save();- // two transactions:- $account1 = FactoryMuffin::create('FireflyIII\Models\Account');- $account2 = FactoryMuffin::create('FireflyIII\Models\Account');- Transaction::create(- [- 'account_id' => $account1->id,- 'transaction_journal_id' => $journal->id,- 'amount' => 100,- ]- );- Transaction::create(- [- 'account_id' => $account2->id,- 'transaction_journal_id' => $journal->id,- 'amount' => 100,- ]- );-$this->object->scan($bill, $journal);$newJournal = TransactionJournal::find($journal->id);diff --git a/tests/repositories/BudgetRepositoryTest.php b/tests/repositories/BudgetRepositoryTest.phpindex d52716c89f..f172274f1e 100644--- a/tests/repositories/BudgetRepositoryTest.php+++ b/tests/repositories/BudgetRepositoryTest.php@@ -38,6 +38,7 @@ class BudgetRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\Budget\BudgetRepository::cleanupBudgets+ * @covers FireflyIII\Providers\EventServiceProvider::boot*/public function testCleanupBudgets(){@@ -155,6 +156,8 @@ class BudgetRepositoryTest extends TestCase*/public function testGetCurrentRepetition(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);/** @var Budget $budget */$budget = FactoryMuffin::create('FireflyIII\Models\Budget');$rep = $this->object->getCurrentRepetition($budget, new Carbon);@@ -210,6 +213,9 @@ class BudgetRepositoryTest extends TestCase*/public function testGetJournals(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');$set = $this->object->getJournals($repetition->budgetlimit->budget, $repetition);@@ -294,6 +300,9 @@ class BudgetRepositoryTest extends TestCase*/public function testSpentInPeriodCorrected(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$budget = FactoryMuffin::create('FireflyIII\Models\Budget');$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, false);@@ -306,6 +315,9 @@ class BudgetRepositoryTest extends TestCase*/public function testSpentInPeriodCorrectedShared(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$budget = FactoryMuffin::create('FireflyIII\Models\Budget');$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, true);diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.phpindex 07f553fbc6..63ed85ee83 100644--- a/tests/repositories/CategoryRepositoryTest.php+++ b/tests/repositories/CategoryRepositoryTest.php@@ -212,6 +212,8 @@ class CategoryRepositoryTest extends TestCase*/public function testSpentInPeriodSumCorrected(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);$category = FactoryMuffin::create('FireflyIII\Models\Category');$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, false);@@ -226,6 +228,8 @@ class CategoryRepositoryTest extends TestCase*/public function testSpentInPeriodSumCorrectedShared(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);$category = FactoryMuffin::create('FireflyIII\Models\Category');$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, true);diff --git a/tests/repositories/JournalRepositoryTest.php b/tests/repositories/JournalRepositoryTest.phpindex a5e32593a7..9216dc9662 100644--- a/tests/repositories/JournalRepositoryTest.php+++ b/tests/repositories/JournalRepositoryTest.php@@ -54,19 +54,13 @@ class JournalRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\Journal\JournalRepository::delete+ * @covers FireflyIII\Providers\EventServiceProvider::boot+ * @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents*/public function testDelete(){$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');- $account = FactoryMuffin::create('FireflyIII\Models\Account');- $transaction = Transaction::create(- [- 'account_id' => $account->id,- 'transaction_journal_id' => $journal->id,- 'amount' => 100,- ]- );-+ $transaction = $journal->transactions[0];$this->object->delete($journal);$this->assertEquals(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->count());diff --git a/tests/repositories/PiggyBankRepositoryTest.php b/tests/repositories/PiggyBankRepositoryTest.phpindex 79fd026f59..e032384047 100644--- a/tests/repositories/PiggyBankRepositoryTest.php+++ b/tests/repositories/PiggyBankRepositoryTest.php@@ -1,7 +1,7 @@<?phpuse Carbon\Carbon;use FireflyIII\Models\PiggyBank;-use FireflyIII\Models\PiggyBankRepetition;+use FireflyIII\Models\Reminder;use FireflyIII\Repositories\PiggyBank\PiggyBankRepository;use League\FactoryMuffin\Facade as FactoryMuffin;@@ -49,14 +49,23 @@ class PiggyBankRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::destroy+ * @covers FireflyIII\Providers\EventServiceProvider::boot+ * @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents*/public function testDestroy(){$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');+ $reminder = FactoryMuffin::create('FireflyIII\Models\Reminder');++ // attach reminders to the piggy bank:+ $reminder->remindersable_id = $piggyBank->id;+ $reminder->remindersable_type = 'FireflyIII\Models\PiggyBank';+ $reminder->save();$this->object->destroy($piggyBank);$this->assertCount(0, PiggyBank::where('id', $piggyBank->id)->whereNull('deleted_at')->get());+ $this->assertCount(0, Reminder::where('id', $reminder->id)->whereNull('deleted_at')->get());}@@ -125,6 +134,8 @@ class PiggyBankRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store+ * @covers FireflyIII\Providers\EventServiceProvider::boot+ * @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents*/public function testStore(){@@ -147,6 +158,8 @@ class PiggyBankRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store+ * @covers FireflyIII\Providers\EventServiceProvider::boot+ * @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents*/public function testStoreRedirect(){diff --git a/tests/repositories/TagRepositoryTest.php b/tests/repositories/TagRepositoryTest.phpindex 7bfd0744dc..23d736d5c0 100644--- a/tests/repositories/TagRepositoryTest.php+++ b/tests/repositories/TagRepositoryTest.php@@ -176,6 +176,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentMultipleMatch(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');@@ -232,6 +235,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentNoMatch(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');@@ -289,6 +295,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentOneTransfer(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');@@ -316,6 +325,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentOneWithdrawal(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');@@ -343,6 +355,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentTwoWithdrawals(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');@@ -375,6 +390,9 @@ class TagRepositoryTest extends TestCase*/public function testConnectPaymentTwoWithdrawalsSameAccounts(){+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');FactoryMuffin::create('FireflyIII\Models\TransactionType');diff --git a/tests/support/AmountSupportTest.php b/tests/support/AmountSupportTest.phpnew file mode 100644index 0000000000..9100965109--- /dev/null+++ b/tests/support/AmountSupportTest.php@@ -0,0 +1,281 @@+<?php+use FireflyIII\Models\Preference;+use FireflyIII\Models\TransactionCurrency;+use FireflyIII\Support\Amount;+use League\FactoryMuffin\Facade as FactoryMuffin;++/**+ * @SuppressWarnings(PHPMD.TooManyMethods)+ * Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 16:33:55.+ */+class AmountSupportTest extends TestCase+{+ /**+ * @var Amount+ */+ protected $object;++ /**+ * Sets up the fixture, for example, opens a network connection.+ * This method is called before a test is executed.+ */+ public function setUp()+ {+ parent::setUp();+ $this->object = new Amount;+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);+ }++ /**+ * Tears down the fixture, for example, closes a network connection.+ * This method is called after a test is executed.+ */+ public function tearDown()+ {+ parent::tearDown();+ }++ /**+ * @covers FireflyIII\Support\Amount::formatJournal+ */+ public function testFormatJournalColouredTransfer()+ {+++ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit+ /** @var \FireflyIII\Models\TransactionJournal $journal */+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $symbol = $journal->transactionCurrency->symbol;++ $result = $this->object->formatJournal($journal, true);++ // transfer is blue:+ $this->assertTrue(str_contains($result, '<span class="text-info">'));+ // transfer contains currency code:+ $this->assertTrue(str_contains($result, $symbol));+ // all amounts are 100.+ $this->assertTrue(str_contains($result, '100'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatJournal+ */+ public function testFormatJournalUncolouredTransfer()+ {+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit+ /** @var \FireflyIII\Models\TransactionJournal $journal */+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $symbol = $journal->transactionCurrency->symbol;++ $result = $this->object->formatJournal($journal, false);++ // transfer is not blue:+ $this->assertFalse(str_contains($result, '<span class="text-info">'));+ // transfer contains currency code:+ $this->assertTrue(str_contains($result, $symbol));+ // all amounts are 100.+ $this->assertTrue(str_contains($result, '100'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatJournal+ */+ public function testFormatJournalWithSymbol()+ {+ FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal+ /** @var \FireflyIII\Models\TransactionJournal $journal */+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $symbol = $journal->transactionCurrency->symbol;+ $journal->symbol = $symbol;++ $result = $this->object->formatJournal($journal, true);++ // transfer is not blue:+ $this->assertFalse(str_contains($result, '<span class="text-danger">'));+ // transfer contains currency code:+ $this->assertTrue(str_contains($result, $symbol));+ // all amounts are 100.+ $this->assertTrue(str_contains($result, '100'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatJournal+ */+ public function testFormatJournalWithdrawal()+ {+ /** @var \FireflyIII\Models\TransactionJournal $journal */+ $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');+ $symbol = $journal->transactionCurrency->symbol;++ $result = $this->object->formatJournal($journal, true);++ // transfer is not blue:+ $this->assertFalse(str_contains($result, '<span class="text-success">'));+ // transfer contains currency code:+ $this->assertTrue(str_contains($result, $symbol));+ // all amounts are 100.+ $this->assertTrue(str_contains($result, '100'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatTransaction+ */+ public function testFormatTransaction()+ {+ // is a withdrawal.+ $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction');+ $transaction->amount = -100;+ $transaction->save();+ $result = $this->object->formatTransaction($transaction, true);+++ // withdrawal is red:+ $this->assertTrue(str_contains($result, '<span class="text-danger">'));+ // all amounts are 100.+ $this->assertTrue(str_contains($result, '100'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatWithSymbol+ */+ public function testFormatWithSymbolColouredAboveZero()+ {+ $amount = 123;+ $symbol = 'top';+ $coloured = true;++ $result = $this->object->formatWithSymbol($symbol, $amount, $coloured);++ // has colour:+ $this->assertTrue(str_contains($result, '<span class="text-success">'));+ // has symbol:+ $this->assertTrue(str_contains($result, $symbol));+ // has amount:+ $this->assertTrue(str_contains($result, '123'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatWithSymbol+ */+ public function testFormatWithSymbolColouredBelowZero()+ {+ $amount = -123;+ $symbol = 'top';+ $coloured = true;++ $result = $this->object->formatWithSymbol($symbol, $amount, $coloured);++ // has colour:+ $this->assertTrue(str_contains($result, '<span class="text-danger">'));+ // has symbol:+ $this->assertTrue(str_contains($result, $symbol));+ // has amount:+ $this->assertTrue(str_contains($result, '123'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatWithSymbol+ */+ public function testFormatWithSymbolColouredZero()+ {+ $amount = 0.0;+ $symbol = 'top';+ $coloured = true;++ $result = $this->object->formatWithSymbol($symbol, $amount, $coloured);++ // has colour:+ $this->assertTrue(str_contains($result, '#999'));+ // has symbol:+ $this->assertTrue(str_contains($result, $symbol));+ // has amount:+ $this->assertTrue(str_contains($result, '0'));+ }++ /**+ * @covers FireflyIII\Support\Amount::formatWithSymbol+ */+ public function testFormatWithSymbolNotColoured()+ {+ $amount = 0;+ $symbol = 'top';+ $coloured = false;++ $result = $this->object->formatWithSymbol($symbol, $amount, $coloured);++ // has symbol:+ $this->assertTrue(str_contains($result, $symbol));+ // has amount:+ $this->assertTrue(str_contains($result, '0'));+ }++ /**+ * @covers FireflyIII\Support\Amount::getAllCurrencies+ */+ public function testGetAllCurrencies()+ {+ $size = TransactionCurrency::count();+ $list = $this->object->getAllCurrencies();+ $this->assertCount($size, $list);+ }++ /**+ * @covers FireflyIII\Support\Amount::getCurrencyCode+ */+ public function testGetCurrencyCode()+ {+ $code = $this->object->getCurrencyCode();+ $this->assertEquals('EUR', $code);+ }++ /**+ * @covers FireflyIII\Support\Amount::getCurrencyCode+ */+ public function testGetCurrencyCodeNoSuchCurrency()+ {+ $user = FactoryMuffin::create('FireflyIII\User');+ $this->be($user);++ // delete any currency preferences:+ Preference::where('user_id', $user->id)->delete();++ // delete transaction currencies:+ foreach (TransactionCurrency::get() as $c) {+ $c->delete();+ }++ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->user_id = $user->id;+ $preference->name = 'currencyPreference';+ $preference->data = 'SOM';+ $preference->save();++ Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($preference);++ $code = $this->object->getCurrencyCode();+ $this->assertEquals('EUR', $code);+ }++ /**+ * @covers FireflyIII\Support\Amount::getCurrencySymbol+ */+ public function testGetCurrencySymbol()+ {+ $result = $this->object->getCurrencySymbol();+ $this->assertEquals('Xi', $result);+ }++ /**+ * @covers FireflyIII\Support\Amount::getDefaultCurrency+ */+ public function testGetDefaultCurrency()+ {+ $result = $this->object->getCurrencySymbol();+ $this->assertEquals('Xi', $result);+ }+++}