mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Some new tests and fixes. [skip ci]
This commit is contained in:
121
app/tests/controllers/BudgetControllerTest.php
Normal file
121
app/tests/controllers/BudgetControllerTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
|
||||
use \League\FactoryMuffin\Facade\FactoryMuffin;
|
||||
/**
|
||||
* Class BudgetControllerTest
|
||||
*/
|
||||
class BudgetControllerTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
// create some objects:
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
$limit = FactoryMuffin::create('Limit');
|
||||
$rep = FactoryMuffin::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($rep);
|
||||
$budget->limits()->save($limit);
|
||||
|
||||
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('get')->once()->andReturn([$budget]);
|
||||
|
||||
// call
|
||||
$this->call('GET', '/budgets/date');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexBudget()
|
||||
{
|
||||
// create some objects:
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
$limit = FactoryMuffin::create('Limit');
|
||||
$rep = FactoryMuffin::create('LimitRepetition');
|
||||
$limit->limitrepetitions()->save($rep);
|
||||
$budget->limits()->save($limit);
|
||||
|
||||
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('get')->once()->andReturn([$budget]);
|
||||
|
||||
// call
|
||||
$this->call('GET', '/budgets/budget');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
// call
|
||||
$this->call('GET', '/budget/create');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testStore()
|
||||
{
|
||||
$data = [
|
||||
'name' => 'X',
|
||||
'amount' => 100,
|
||||
'period' => 'monthly',
|
||||
'repeats' => 0
|
||||
];
|
||||
$return = $data;
|
||||
$return['repeat_freq'] = 'monthly';
|
||||
unset($return['period']);
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('store')->with($return)->once()->andReturn(true);
|
||||
|
||||
// call
|
||||
$this->call('POST', '/budget/store',$data);
|
||||
|
||||
// test
|
||||
$this->assertResponseStatus(302);
|
||||
$this->assertSessionHas('success');
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$budget = FactoryMuffin::create('Budget');
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
$transaction = FactoryMuffin::create('Transaction');
|
||||
$journal->transactions()->save($transaction);
|
||||
$budget->transactionjournals()->save($journal);
|
||||
|
||||
|
||||
// mock budget repository:
|
||||
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets->shouldReceive('find')->with($budget->id)->once()->andReturn($budget);
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/budget/show/'.$budget->id);
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -14,20 +14,21 @@ class ChartControllerTest extends TestCase
|
||||
public function testHomeAccount()
|
||||
{
|
||||
// mock preference:
|
||||
$pref = $this->mock('Preference');
|
||||
$pref->shouldReceive('getAttribute', 'data')->andReturn('1M');
|
||||
$pref2 = $this->mock('Preference');
|
||||
$pref2->shouldReceive('getAttribute', 'data')->andReturn([]);
|
||||
|
||||
// mock preferences helper:
|
||||
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
|
||||
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->once()->andReturn($pref2);
|
||||
|
||||
|
||||
// mock toolkit:
|
||||
$start = new Carbon\Carbon;
|
||||
$start->startOfMonth();
|
||||
$end = new \Carbon\Carbon;
|
||||
$end->endOfMonth();
|
||||
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->shouldReceive('getDateRange')->andReturn(null);
|
||||
$toolkit->shouldReceive('getDateRange')->with()->once()->andReturn([$start, $end]);
|
||||
|
||||
// create a semi-mocked collection of accounts:
|
||||
|
||||
@@ -55,22 +56,65 @@ class ChartControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testHomeAccountWithPref()
|
||||
{
|
||||
|
||||
// mock toolkit:
|
||||
$start = new Carbon\Carbon;
|
||||
$start->startOfMonth();
|
||||
$end = new \Carbon\Carbon;
|
||||
$end->endOfMonth();
|
||||
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->shouldReceive('getDateRange')->with()->once()->andReturn([$start, $end]);
|
||||
|
||||
// mock account(s)
|
||||
$personal = $this->mock('AccountType');
|
||||
$personal->shouldReceive('jsonSerialize')->andReturn('');
|
||||
|
||||
$one = $this->mock('Account');
|
||||
$one->shouldReceive('getAttribute')->andReturn($personal);
|
||||
$one->shouldReceive('balance')->andReturn(0);
|
||||
$one->shouldReceive('predict')->andReturn(null);
|
||||
|
||||
// collection:
|
||||
$c = new \Illuminate\Database\Eloquent\Collection([$one]);
|
||||
|
||||
// mock preference:
|
||||
$pref2 = $this->mock('Preference');
|
||||
$pref2->shouldReceive('getAttribute', 'data')->andReturn([$one->id]);
|
||||
|
||||
// mock preferences helper:
|
||||
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->once()->andReturn($pref2);
|
||||
|
||||
|
||||
// create a semi-mocked collection of accounts:
|
||||
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('getByIds')->andReturn($c);
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/chart/home/account');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testHomeAccountWithInput()
|
||||
{
|
||||
// save actual account:
|
||||
$account = FactoryMuffin::create('Account');
|
||||
|
||||
// mock preference:
|
||||
$pref = $this->mock('Preference');
|
||||
$pref->shouldReceive('getAttribute', 'data')->andReturn('week');
|
||||
|
||||
// mock preferences helper:
|
||||
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
|
||||
|
||||
// mock toolkit:
|
||||
$start = new Carbon\Carbon;
|
||||
$start->startOfMonth();
|
||||
$end = new \Carbon\Carbon;
|
||||
$end->endOfMonth();
|
||||
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->shouldReceive('getDateRange')->andReturn(null);
|
||||
$toolkit->shouldReceive('getDateRange')->with()->once()->andReturn([$start, $end]);
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
@@ -89,30 +133,17 @@ class ChartControllerTest extends TestCase
|
||||
$start = new \Carbon\Carbon;
|
||||
$end = new \Carbon\Carbon;
|
||||
|
||||
// mock preferences & pref:
|
||||
$pref = $this->mock('Preference');
|
||||
$pref->shouldReceive('getAttribute', 'data')->andReturn([]);
|
||||
// mock journals:
|
||||
$transaction = FactoryMuffin::create('Transaction');
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
$journal->transactions()->save($transaction);
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('getByDateRange')->once()->with($start, $end)->andReturn([$journal]);
|
||||
|
||||
|
||||
// mock toolkit
|
||||
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->shouldReceive('getDateRange')->andReturn([$start, $end]);
|
||||
//
|
||||
// // mock preference?
|
||||
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref);
|
||||
//
|
||||
//
|
||||
// // mock toolkit:
|
||||
//// $class = $this->getMockClass('Foo', array('baz'));
|
||||
//// $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
//// $toolkit::static ->shouldReceive('getDateRange')->once()->andReturn([$start, $end]);
|
||||
//
|
||||
//// // mock transaction journal
|
||||
//// $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
//// $tj->shouldReceive('getByDateRange')->with($start, $end)->andReturn([]);
|
||||
////
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/chart/home/categories');
|
||||
@@ -121,6 +152,64 @@ class ChartControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function testhomeCategoriesException()
|
||||
{
|
||||
$start = new \Carbon\Carbon;
|
||||
$end = new \Carbon\Carbon;
|
||||
|
||||
// mock journals:
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('getByDateRange')->once()->with($start, $end)->andReturn([$journal]);
|
||||
|
||||
|
||||
// mock toolkit
|
||||
$toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->shouldReceive('getDateRange')->andReturn([$start, $end]);
|
||||
|
||||
// call
|
||||
$this->call('GET', '/chart/home/categories');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testHomeAccountInfo()
|
||||
{
|
||||
$account = FactoryMuffin::create('Account');
|
||||
$second = FactoryMuffin::create('Account');
|
||||
$date = \Carbon\Carbon::createFromDate('2012','01','01');
|
||||
$transaction = FactoryMuffin::create('Transaction');
|
||||
$transaction->account()->associate($second);
|
||||
$journal = FactoryMuffin::create('TransactionJournal');
|
||||
$journal->transactions()->save($transaction);
|
||||
|
||||
// mock account repository:
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('findByName')->with($account->name)->andReturn($account);
|
||||
|
||||
// mock journal:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('getByAccountAndDate')->once()->andReturn([$journal]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// call
|
||||
$this->call('GET', '/chart/home/info/'.$account->name.'/'.$date->format('d/m/Y'));
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
|
||||
|
||||
} //($name, $day, $month, $year)
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
|
@@ -1,10 +1,17 @@
|
||||
<?php
|
||||
|
||||
use League\FactoryMuffin\Facade\FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class HomeControllerTest
|
||||
*/
|
||||
class HomeControllerTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('migrate');
|
||||
Artisan::call('db:seed');
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
@@ -12,12 +19,12 @@ class HomeControllerTest extends TestCase
|
||||
// mock:
|
||||
View::shouldReceive('share');
|
||||
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->with('count', 0)->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->with('transactions', [])->andReturn(\Mockery::self());
|
||||
|
||||
// pass another
|
||||
// pass another
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
|
||||
|
||||
@@ -40,6 +47,46 @@ class HomeControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndexWithAccounts()
|
||||
{
|
||||
// mock:
|
||||
View::shouldReceive('share');
|
||||
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->with('count', 1)->andReturn(\Mockery::self())
|
||||
->shouldReceive('with')->once() // Pass a 'with' parameter
|
||||
->with('transactions', [])->andReturn(\Mockery::self());
|
||||
|
||||
// pass another
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
|
||||
// make account:
|
||||
$account = FactoryMuffin::create('Account');
|
||||
|
||||
|
||||
// mock account repository
|
||||
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts->shouldReceive('count')->andReturn(1);
|
||||
$accounts->shouldReceive('getByIds')->with([$account->id])->andReturn([$account]);
|
||||
|
||||
// mock transaction journal repository:
|
||||
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$tj->shouldReceive('getByAccount')->with($account,15)->andReturn([]);
|
||||
|
||||
// mock preferences & pref:
|
||||
$pref = $this->mock('Preference');
|
||||
$pref->shouldReceive('getAttribute', 'data')->andReturn([$account->id]);
|
||||
|
||||
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->once()->andReturn($pref);
|
||||
|
||||
// call
|
||||
$this->call('GET', '/');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
|
Reference in New Issue
Block a user