Fix tests and fix coverage.

This commit is contained in:
James Cole
2015-06-06 15:36:12 +02:00
parent 681167bc1b
commit db020db34b
19 changed files with 381 additions and 286 deletions

View File

@@ -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;

View File

@@ -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;
/**
@@ -219,36 +220,6 @@ class TransactionJournal extends Model
return $this->belongsToMany('FireflyIII\Models\Tag');
}
/**
* @return Account
*/
public function getAssetAccountAttribute()
{
// 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;
case 'Withdrawal':
return $this->transactions()->where('amount', '<', 0)->first()->account;
}
return $this->transactions()->first()->account;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* @return string
*/
@@ -265,6 +236,15 @@ class TransactionJournal extends Model
return '0';
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* @codeCoverageIgnore
* @return string[]
@@ -308,27 +288,6 @@ class TransactionJournal extends Model
return $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 Model
return $cache->get(); // @codeCoverageIgnore
}
$account = $this->transactions()->where('amount', '<', 0)->first()->account;
$cache->store($account);
return $account;

View File

@@ -53,10 +53,13 @@ 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'))
$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;
@@ -68,8 +71,7 @@ class EventServiceProvider extends ServiceProvider
try {
$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) {

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -36,7 +36,7 @@ class Amount
public function getCurrencySymbol()
{
if (defined('FFCURRENCYSYMBOL')) {
return FFCURRENCYSYMBOL;
return FFCURRENCYSYMBOL; // @codeCoverageIgnore
}
$currencyPreference = Prefs::get('currencyPreference', 'EUR');
@@ -149,7 +149,7 @@ class Amount
public function getCurrencyCode()
{
if (defined('FFCURRENCYCODE')) {
return FFCURRENCYCODE;
return FFCURRENCYCODE; // @codeCoverageIgnore
}

View File

@@ -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);

View File

@@ -36,7 +36,6 @@ class Preferences
return Cache::get($fullName);
}
$preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']);
if ($preference) {

View File

@@ -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');

View File

@@ -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);
}
}

View File

@@ -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');
// 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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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()
{

View File

@@ -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');

View 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);
}
}