mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix tests and fix coverage.
This commit is contained in:
@@ -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');
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
use 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()
|
||||
{
|
||||
|
@@ -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');
|
||||
|
281
tests/support/AmountSupportTest.php
Normal file
281
tests/support/AmountSupportTest.php
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user