Expand test coverage.

This commit is contained in:
James Cole
2018-03-03 14:24:06 +01:00
parent 99d116f4ce
commit 9dc4c50527
17 changed files with 311 additions and 56 deletions

View File

@@ -91,9 +91,10 @@ class ReconcileControllerTest extends TestCase
*/
public function testOverview()
{
$transactions = $this->user()->transactions()->inRandomOrder()->take(3)->get();
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->andReturn(new TransactionJournal);
$repository->shouldReceive('getTransactionsById')->andReturn(new Collection())->twice();
$repository->shouldReceive('getTransactionsById')->andReturn($transactions)->twice();
$parameters = [
'startBalance' => '0',

View File

@@ -214,6 +214,23 @@ class AccountControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::show
* @expectedExceptionMessage End is after start!
*/
public function testShowBrokenBadDates()
{
// mock
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->session(['start' => '2018-01-01', 'end' => '2017-12-01']);
$this->be($this->user());
$account = $this->user()->accounts()->where('account_type_id', 3)->orderBy('id', 'ASC')->whereNull('deleted_at')->first();
$response = $this->get(route('accounts.show', [$account->id, '2018-01-01', '2017-12-01']));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::show
* @covers \FireflyIII\Http\Controllers\AccountController::redirectToOriginalAccount
@@ -234,7 +251,6 @@ class AccountControllerTest extends TestCase
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\AccountController::show
* @dataProvider dateRangeProvider

View File

@@ -139,8 +139,10 @@ class LinkControllerTest extends TestCase
*/
public function testIndex()
{
$linkTypes = LinkType::inRandomOrder()->take(3)->get();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn(new Collection);
$repository->shouldReceive('get')->andReturn($linkTypes);
$repository->shouldReceive('countJournals')->andReturn(3);
$this->be($this->user());
$response = $this->get(route('admin.links.index'));
$response->assertStatus(200);

View File

@@ -116,7 +116,6 @@ class BillControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\BillController::index
* @covers \FireflyIII\Http\Controllers\BillController::__construct
* @covers \FireflyIII\Http\Controllers\BillController::lastPaidDate
*/
public function testIndex()
{

View File

@@ -39,8 +39,17 @@ class OperationsControllerTest extends TestCase
*/
public function testExpenses()
{
$return = [
1 => [
'id' => 1,
'name' => 'Some name',
'sum' => '5',
'average' => '5',
'count' => 1,
]
];
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('getExpenseReport')->andReturn([]);
$tasker->shouldReceive('getExpenseReport')->andReturn($return);
$this->be($this->user());
$response = $this->get(route('report-data.operations.expenses', ['1', '20160101', '20160131']));
@@ -65,9 +74,19 @@ class OperationsControllerTest extends TestCase
*/
public function testOperations()
{
$return = [
1 => [
'id' => 1,
'name' => 'Some name',
'sum' => '5',
'average' => '5',
'count' => 1,
]
];
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('getExpenseReport')->andReturn([]);
$tasker->shouldReceive('getIncomeReport')->andReturn([]);
$tasker->shouldReceive('getExpenseReport')->andReturn($return);
$tasker->shouldReceive('getIncomeReport')->andReturn($return);
$this->be($this->user());
$response = $this->get(route('report-data.operations.operations', ['1', '20160101', '20160131']));

View File

@@ -93,11 +93,12 @@ class MassControllerTest extends TestCase
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
$transfersArray = $transfers->pluck('id')->toArray();
$source = $this->user()->accounts()->first();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// mock data for edit page:
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$source]));
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
$journalRepos->shouldReceive('getFirstPosTransaction')->andReturn($transfers->first()->transactions()->first());

View File

@@ -114,6 +114,62 @@ class SingleControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::__construct
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
*/
public function testCreateDepositWithSource()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accounts = $this->user()->accounts()->where('account_type_id', 3)->get();
Steam::shouldReceive('phpBytes')->andReturn(2048);
$accountRepos->shouldReceive('getActiveAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn($accounts);
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
$piggyRepos->shouldReceive('getPiggyBanksWithAmount')->andReturn(new Collection)->once();
$this->be($this->user());
$response = $this->get(route('transactions.create', ['deposit']) . '?source=1');
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::__construct
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedActiveAccountList
*/
public function testCreateWithSource()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accounts = $this->user()->accounts()->where('account_type_id', 3)->get();
Steam::shouldReceive('phpBytes')->andReturn(2048);
$accountRepos->shouldReceive('getActiveAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn($accounts);
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
$piggyRepos->shouldReceive('getPiggyBanksWithAmount')->andReturn(new Collection)->once();
$this->be($this->user());
$response = $this->get(route('transactions.create', ['withdrawal']) . '?source=1');
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::delete
*/
@@ -174,7 +230,7 @@ class SingleControllerTest extends TestCase
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$account = $this->user()->accounts()->first();
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]));
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
@@ -351,6 +407,26 @@ class SingleControllerTest extends TestCase
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
*/
public function testEditRedirectOpening()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$this->be($this->user());
$journalRepos->shouldReceive('getTransactionType')->andReturn('Opening balance');
$journalRepos->shouldReceive('countTransactions')->andReturn(3);
$response = $this->get(route('transactions.edit', [1]));
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedAccountList
@@ -400,6 +476,51 @@ class SingleControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedAccountList
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::isSplitJournal
*/
public function testEditWithForeign()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$account = $this->user()->accounts()->first();
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
$transaction = new Transaction;
$transaction->foreign_amount = '1';
$transaction->foreign_currency_id = 2;
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
$journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal')->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->once();
$journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
$journalRepos->shouldReceive('getFirstPosTransaction')->andReturn($transaction)->once();
$journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
$journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
$journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
$journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
$journalRepos->shouldReceive('getTags')->once()->andReturn([]);
$this->be($this->user());
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::groupedAccountList

View File

@@ -67,6 +67,8 @@ class SplitControllerTest extends TestCase
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$array = $transactions->toArray();
$array[0]['category'] = '';
$journalRepos->shouldReceive('first')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
@@ -78,13 +80,14 @@ class SplitControllerTest extends TestCase
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$journalRepos->shouldReceive('getJournalTotal')->andReturn('0');
$journalRepos->shouldReceive('getJournalCategoryName')->andReturn('Some');
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection([$account]))->once();
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
$tasker->shouldReceive('getTransactionsOverview')->andReturn($array);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$deposit->id]));