Fixed the account controller and tests.

This commit is contained in:
James Cole 2014-08-02 12:12:03 +02:00
parent 99500d6201
commit 913b5fd267
11 changed files with 119 additions and 1762 deletions

View File

@ -1,14 +1,19 @@
<?php <?php
use Mockery as m; use Carbon\Carbon;
use \League\FactoryMuffin\Facade\FactoryMuffin as f;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Mockery as m;
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
/**
* Class AccountControllerTest
*/
class AccountControllerTest extends TestCase class AccountControllerTest extends TestCase
{ {
protected $_repository; protected $_repository;
protected $_user; protected $_user;
protected $_accounts; protected $_accounts;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
@ -16,8 +21,8 @@ class AccountControllerTest extends TestCase
Artisan::call('db:seed'); Artisan::call('db:seed');
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); $this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface'); $this->_accounts = $this->mock('Firefly\Helper\Controllers\AccountInterface');
$this->_user = m::mock('User','Eloquent'); $this->_user = m::mock('User', 'Eloquent');
$this->app->instance('User', $this->_user); // $this->app->instance('User', $this->_user);
} }
@ -37,21 +42,28 @@ class AccountControllerTest extends TestCase
{ {
$account = f::create('Account'); $account = f::create('Account');
// for successful binding:
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email); $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
$this->action('GET', 'AccountController@delete',$account->id); $this->action('GET', 'AccountController@delete', $account->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }
public function testDestroy() public function testDestroy()
{ {
$account = f::create('Account'); $account = f::create('Account');
// for successful binding:
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user);
$this->_repository->shouldReceive('destroy')->once()->with("")->andReturn(true); Auth::shouldReceive('check')->andReturn(true);
$this->action('POST', 'AccountController@destroy',$account->id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
$this->action('POST', 'AccountController@destroy', $account->id);
$this->assertRedirectedToRoute('accounts.index'); $this->assertRedirectedToRoute('accounts.index');
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
@ -59,8 +71,14 @@ class AccountControllerTest extends TestCase
public function testDestroyFails() public function testDestroyFails()
{ {
$account = f::create('Account'); $account = f::create('Account');
$this->_repository->shouldReceive('destroy')->once()->with("")->andReturn(false);
$this->action('POST', 'AccountController@destroy',$account->id); // for successful binding:
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_repository->shouldReceive('destroy')->once()->andReturn(false);
$this->action('POST', 'AccountController@destroy', $account->id);
$this->assertRedirectedToRoute('accounts.index'); $this->assertRedirectedToRoute('accounts.index');
$this->assertSessionHas('error'); $this->assertSessionHas('error');
} }
@ -69,13 +87,20 @@ class AccountControllerTest extends TestCase
{ {
$account = f::create('Account'); $account = f::create('Account');
// for successful binding.
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email); $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
// Auth::shouldReceive('user')->andReturn($this->_user);
// Auth::shouldReceive('check')->andReturn(true);
// $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
// $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
$this->_accounts->shouldReceive('openingBalanceTransaction')->once()->andReturn(null); $this->_accounts->shouldReceive('openingBalanceTransaction')->once()->andReturn(null);
$this->action('GET', 'AccountController@edit',$account->id); $this->action('GET', 'AccountController@edit', $account->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }
@ -102,20 +127,97 @@ class AccountControllerTest extends TestCase
{ {
$account = f::create('Account'); $account = f::create('Account');
// for successful binding.
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email); $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
$this->_accounts->shouldReceive('paginate')->with($account,40)->once()->andReturn(); $this->session(['start' => new Carbon, 'end' => new Carbon]);
$this->action('GET', 'AccountController@show',$account->id); // some more mockery
$paginator = \Paginator::make([], 0, 10);
$data = [
'statistics' => [
'period' => [
'in' => 0,
'out' => 0,
'diff' => 0,
't_in' => 0,
't_out' => 0,
't_diff' => 0
],
'categories' => [],
'budgets' => [],
'accounts' => []
],
'journals' => $paginator,
];
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
//$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
// Auth::shouldReceive('user')->andReturn($this->_user);
// Auth::shouldReceive('check')->andReturn(true);
// $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
// $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($account->email);
// $this->_accounts->shouldReceive('paginate')->with($account,40)->once()->andReturn();
$this->action('GET', 'AccountController@show', $account->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }
public function testStore() public function testStore()
{ {
// $this->action('POST', 'AccountController@store'); $account = f::create('Account');
// $this->assertResponseOk(); $this->_repository->shouldReceive('store')->andReturn($account);
$this->action('POST', 'AccountController@store');
$this->assertRedirectedToRoute('accounts.index');
}
public function testStoreRecreate()
{
$account = f::create('Account');
$this->_repository->shouldReceive('store')->andReturn($account);
$this->action('POST', 'AccountController@store',['create' => '1']);
$this->assertRedirectedToRoute('accounts.create');
}
public function testStoreFails()
{
$account = f::create('Account');
unset($account->id);
$this->_repository->shouldReceive('store')->andReturn($account);
$this->action('POST', 'AccountController@store');
$this->assertRedirectedToRoute('accounts.create');
}
public function testUpdate()
{
$account = f::create('Account');
// for successful binding.
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_repository->shouldReceive('update')->andReturn($account);
$this->action('POST', 'AccountController@update',$account->id);
$this->assertRedirectedToRoute('accounts.index');
}
public function testUpdateFails()
{
$account = f::create('Account');
unset($account->name);
// for successful binding.
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
$this->_repository->shouldReceive('update')->andReturn($account);
$this->action('POST', 'AccountController@update',$account->id);
$this->assertRedirectedToRoute('accounts.edit',$account->id);
} }
@ -204,7 +306,5 @@ class AccountControllerTest extends TestCase
//// } //// }
//// ////
public function testUpdate()
{
}
} }

View File

@ -1,120 +0,0 @@
<?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();
}
}

View File

@ -1,212 +0,0 @@
<?php
use League\FactoryMuffin\Facade\FactoryMuffin;
class ChartControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
}
public function testHomeAccount()
{
// mock preference:
$pref2 = $this->mock('Preference');
$pref2->shouldReceive('getAttribute', 'data')->andReturn([]);
// mock preferences helper:
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$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')->with()->once()->andReturn([$start, $end]);
// create a semi-mocked collection of accounts:
// 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 account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefault')->andReturn($c);
// call
$this->call('GET', '/chart/home/account');
// test
$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 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 repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('find')->with(1)->andReturn($account);
// call
$this->call('GET', '/chart/home/account/' . $account->id);
// test
$this->assertResponseOk();
}
public function testhomeCategories()
{
$start = new \Carbon\Carbon;
$end = new \Carbon\Carbon;
// 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]);
// call
$this->call('GET', '/chart/home/categories');
// test
$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();
}
}

View File

@ -1,94 +0,0 @@
<?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()
{
// mock:
View::shouldReceive('share');
View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once() // Pass a 'with' parameter
->with('count', 0)->andReturn(\Mockery::self())
->shouldReceive('with')->once() // Pass a 'with' parameter
->with('transactions', [])->andReturn(\Mockery::self());
// pass another
Auth::shouldReceive('check')->andReturn(true);
// mock account repository
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('count')->andReturn(0);
$accounts->shouldReceive('getActiveDefault')->andReturn([]);
// mock preferences & pref:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn([]);
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->once()->andReturn($pref);
// call
$this->call('GET', '/');
// test
$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();
}
}

View File

@ -1,46 +0,0 @@
<?php
class JsonControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testBeneficiaries()
{
$obj = new stdClass;
$obj->name = 'Bla bla';
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getBeneficiaries')->andReturn([$obj]);
$this->call('GET', '/json/beneficiaries');
// test
$this->assertResponseOk();
}
public function testCategories()
{
$obj = new stdClass;
$obj->name = 'Bla bla';
// mock category repository:
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('get')->andReturn([$obj]);
$this->call('GET', '/json/categories');
// test
$this->assertResponseOk();
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,27 +0,0 @@
<?php
class MigrationControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testIndex()
{
// mock:
View::shouldReceive('share');
View::shouldReceive('make')->with('migrate.index');
// call
$this->call('GET', '/migrate');
// test
$this->assertResponseOk();
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,65 +0,0 @@
<?php
class PreferencesControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testIndex()
{
// mock preferences helper:
$pref = $this->mock('Preference');
$pref->shouldReceive('getAttribute', 'data')->andReturn([]);
$viewPref = $this->mock('Preference');
$viewPref->shouldReceive('getAttribute', 'data')->andReturn('1M');
// mock view:
View::shouldReceive('share');
View::shouldReceive('make')->with('preferences.index')->once()->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('accounts', [])->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('viewRange', '1M')->andReturn(\Mockery::self())
->shouldReceive('with')->once()->with('frontpageAccounts', $pref)->andReturn(\Mockery::self());
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('get')->with('frontpageAccounts', [])->andReturn($pref);
$preferences->shouldReceive('get')->with('viewRange', '1M')->andReturn($viewPref);
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('accounts')->andReturn([]);
$accounts->shouldReceive('getDefault')->andReturn([]);
// call
$this->call('GET', '/preferences');
// test
$this->assertResponseOk();
}
public function testPostIndex()
{
// mock
$preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$preferences->shouldReceive('set')->with('frontpageAccounts', [1])->andReturn(true);
$preferences->shouldReceive('set')->with('viewRange', '1M')->andReturn(true);
// call
$this->call('POST', '/preferences', ['frontpageAccounts' => [1], 'viewRange' => '1M']);
// test
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('preferences');
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,148 +0,0 @@
<?php
class ProfileControllerTest extends TestCase
{
public function testIndex()
{
// mock:
View::shouldReceive('share');
View::shouldReceive('make')->with('profile.index');
// call
$this->call('GET', '/profile');
// test
$this->assertResponseOk();
}
public function testChangePassword()
{
// mock:
View::shouldReceive('share');
View::shouldReceive('make')->with('profile.change-password');
// call
$this->call('GET', '/profile/change-password');
// test
$this->assertResponseOk();
}
public function testOldNoMatch()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(false);
$data = [
'old' => 'lala',
'new1' => 'a',
'new2' => 'a',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'Invalid current password!');
}
public function testNewEmpty()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
$data = [
'old' => 'lala',
'new1' => '',
'new2' => '',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'Do fill in a password!');
}
public function testOldSame()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$data = [
'old' => 'a',
'new1' => 'a',
'new2' => 'a',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'The idea is to change your password.');
}
public function testNewNoMatch()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$data = [
'old' => 'b',
'new1' => 'c',
'new2' => 'd',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertResponseOk();
$this->assertSessionHas('error', 'New passwords do not match!');
}
public function testPostChangePassword()
{
Auth::shouldReceive('check')->andReturn(true);
Auth::shouldReceive('user')->andReturn(new User);
Hash::shouldReceive('check')->andReturn(true);
Hash::shouldReceive('make')->andReturn('blala');
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$repository->shouldReceive('updatePassword')->once()->andReturn(true);
$data = [
'old' => 'b',
'new1' => 'c',
'new2' => 'c',
];
// call
$this->call('POST', '/profile/change-password', $data);
// test
$this->assertRedirectedToRoute('profile');
$this->assertSessionHas('success', 'Password changed!');
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,562 +0,0 @@
<?php
use League\FactoryMuffin\Facade\FactoryMuffin;
class TransactionControllerTest extends TestCase
{
/**
* Default preparation for each test
*/
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* Migrate the database
*/
private function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
public function testCreateWithdrawal()
{
$set = [0 => '(no budget)'];
View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self())
->shouldReceive('with')->once()
->with('what', 'withdrawal')
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('accounts', [])
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('budgets', $set)->andReturn(Mockery::self());
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// mock budget repository:
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('getAsSelectList')->andReturn($set);
// call
$this->call('GET', '/transactions/create/withdrawal');
// test
$this->assertResponseOk();
}
public function testCreateDeposit()
{
$set = [0 => '(no budget)'];
View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self())
->shouldReceive('with')->once()
->with('what', 'deposit')
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('accounts', [])
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('budgets', $set)->andReturn(Mockery::self());
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// mock budget repository:
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('getAsSelectList')->andReturn($set);
// call
$this->call('GET', '/transactions/create/deposit');
// test
$this->assertResponseOk();
}
public function testCreateTransfer()
{
$set = [0 => '(no budget)'];
View::shouldReceive('share');
View::shouldReceive('make')->with('transactions.create')->andReturn(\Mockery::self())
->shouldReceive('with')->once()
->with('what', 'transfer')
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('accounts', [])
->andReturn(Mockery::self())
->shouldReceive('with')->once()
->with('budgets', $set)->andReturn(Mockery::self());
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// mock budget repository:
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('getAsSelectList')->andReturn($set);
// call
$this->call('GET', '/transactions/create/transfer');
// test
$this->assertResponseOk();
}
public function testPostCreateWithdrawal()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$budget = FactoryMuffin::create('Budget');
// data to send:
$data = [
'beneficiary' => $beneficiary->name,
'category' => $category->name,
'budget_id' => $budget->id,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with($beneficiary->name)->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
$budgets->shouldReceive('find')->andReturn($budget);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
// call
$this->call('POST', '/transactions/store/withdrawal', $data);
// test
$this->assertRedirectedToRoute('index');
}
public function testPostCreateDeposit()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
// data to send:
$data = [
'beneficiary' => $beneficiary->name,
'category' => $category->name,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with($beneficiary->name)->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with('')->andReturn(null);
$budgets->shouldReceive('find')->andReturn(null);
// call
$this->call('POST', '/transactions/store/deposit', $data);
// test
$this->assertRedirectedToRoute('index');
}
public function testPostCreateTransfer()
{
// create objects.
$from = FactoryMuffin::create('Account');
$to = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
// data to send:
$data = [
'category' => $category->name,
'account_from_id' => $from->id,
'account_to_id' => $to->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
$accounts->shouldReceive('find')->with($to->id)->andReturn($to);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with('')->andReturn(null);
$budgets->shouldReceive('find')->andReturn(null);
// call
$this->call('POST', '/transactions/store/transfer', $data);
// test
$this->assertRedirectedToRoute('index');
}
public function testPostCreateWithdrawalEmptyBeneficiary()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$budget = FactoryMuffin::create('Budget');
// data to send:
$data = [
'beneficiary' => '',
'category' => $category->name,
'budget_id' => $budget->id,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
$budgets->shouldReceive('find')->andReturn($budget);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
// call
$this->call('POST', '/transactions/store/withdrawal', $data);
// test
$this->assertRedirectedToRoute('index');
}
public function testPostCreateDepositEmptyBeneficiary()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$budget = FactoryMuffin::create('Budget');
// data to send:
$data = [
'beneficiary' => '',
'category' => $category->name,
'budget_id' => $budget->id,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
$budgets->shouldReceive('find')->andReturn($budget);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->once()->andReturn($journal);
// call
$this->call('POST', '/transactions/store/deposit', $data);
// test
$this->assertRedirectedToRoute('index');
}
/**
* @expectedException Firefly\Exception\FireflyException;
*/
public function testPostCreateWithdrawalException()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$budget = FactoryMuffin::create('Budget');
// data to send:
$data = [
'beneficiary' => '',
'category' => $category->name,
'budget_id' => $budget->id,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
$budgets->shouldReceive('find')->andReturn($budget);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
// call
$this->call('POST', '/transactions/store/withdrawal', $data);
// test
$this->assertRedirectedToRoute('transactions.create', ['what' => 'withdrawal']);
}
/**
* @expectedException Firefly\Exception\FireflyException;
*/
public function testPostCreateDepositException()
{
// create objects.
$account = FactoryMuffin::create('Account');
$beneficiary = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$budget = FactoryMuffin::create('Budget');
// data to send:
$data = [
'beneficiary' => '',
'category' => $category->name,
'budget_id' => $budget->id,
'account_id' => $account->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
$journal = FactoryMuffin::create('TransactionJournal');
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('createOrFindBeneficiary')->with('')->andReturn(null);
$accounts->shouldReceive('getCashAccount')->andReturn($beneficiary);
$accounts->shouldReceive('find')->andReturn($account);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with($budget->name)->andReturn($budget);
$budgets->shouldReceive('find')->andReturn($budget);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
// call
$this->call('POST', '/transactions/store/deposit', $data);
// test
$this->assertRedirectedToRoute('transactions.create', ['what' => 'deposit']);
}
/**
* @expectedException Firefly\Exception\FireflyException;
*/
public function testPostCreateTransferException()
{
// create objects.
$from = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
// data to send:
$data = [
'category' => $category->name,
'account_from_id' => $from->id,
'account_to_id' => $from->id,
'description' => 'Bla',
'amount' => 1.2,
'date' => '2012-01-01'
];
// mock account repository:
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
$accounts->shouldReceive('find')->with($from->id)->andReturn($from);
// mock category repository
$categories = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$categories->shouldReceive('createOrFind')->with($category->name)->andReturn($category);
// mock budget repository
$budgets = $this->mock('Firefly\Storage\Budget\BudgetRepositoryInterface');
$budgets->shouldReceive('createOrFind')->with('')->andReturn(null);
$budgets->shouldReceive('find')->andReturn(null);
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('createSimpleJournal')->andThrow('Firefly\Exception\FireflyException');
// call
$this->call('POST', '/transactions/store/transfer', $data);
// test
$this->assertRedirectedToRoute('transactions.create', ['what' => 'transfer']);
}
public function testShow()
{
$journal = FactoryMuffin::create('TransactionJournal');
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('find')->with($journal->id)->andReturn($journal);
// call
$this->call('GET', '/transaction/show/' . $journal->id);
// test
$this->assertResponseOk();
}
public function testShowError()
{
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('find')->with(1)->andReturn(null);
// call
$this->call('GET', '/transaction/show/1');
// test
$this->assertResponseOk();
$this->assertViewHas('message');
}
public function testEdit()
{
$journal = FactoryMuffin::create('TransactionJournal');
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('find')->with($journal->id)->andReturn($journal);
// mock account repository
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
$accounts->shouldReceive('getActiveDefaultAsSelectList')->andReturn([]);
// call
$this->call('GET', '/transaction/edit/' . $journal->id);
// test
$this->assertResponseOk();
}
public function testEditError()
{
// mock transaction journal:
$tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$tj->shouldReceive('find')->with(1)->andReturn(null);
// call
$this->call('GET', '/transaction/edit/1');
// test
$this->assertResponseOk();
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,246 +0,0 @@
<?php
class UserControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testLogin()
{
// mock:
View::shouldReceive('make')->with('user.login');
// call
$this->call('GET', '/login');
// test
$this->assertResponseOk();
}
public function testPostLogin()
{
// data:
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx', 'remember_me' => '1'];
// mock
Auth::shouldReceive('attempt')->once()->andReturn(true);
// test
$this->call('POST', '/login', $data);
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('index');
}
public function testPostFalseLogin()
{
// data
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx', 'remember_me' => '1'];
// mock
Auth::shouldReceive('attempt')->once()->andReturn(false);
View::shouldReceive('make')->with('user.login')->once();
// test
$this->call('POST', '/login', $data);
$this->assertSessionHas('error');
}
public function testRegister()
{
// no mock for config! :(
Config::set('auth.allow_register', true);
// test
$this->call('GET', '/register');
$this->assertResponseOk();
}
public function testRegisterNotAllowed()
{
// no mock for config! :(
Config::set('auth.allow_register', false);
// test
$this->call('GET', '/register');
$this->assertResponseStatus(200);
$this->assertViewHas('message', 'Not possible');
}
/**
* Register and verify:
*/
public function testPostRegisterAllowed()
{
// no mock for config! :(
Config::set('auth.verify_mail', true);
Config::set('auth.allow_register', true);
// mock repository:
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('register')->once()->andReturn(new User);
$email->shouldReceive('sendVerificationMail')->once()->andReturn(true);
// data:
$data = [
'email' => 'bla@bla'
];
// test
$crawler = $this->client->request('POST', '/register', $data);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Verification pending")'));
}
/**
* Register and verify FAILED:
*/
public function testPostRegisterAllowedFailed()
{
// no mock for config! :(
Config::set('auth.verify_mail', true);
Config::set('auth.allow_register', true);
// mock repository:
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('register')->once()->andReturn(null);
// test
$crawler = $this->client->request('POST', '/register');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Register")'));
}
/**
* Register and NO verify:
*/
public function testPostRegisterNoVerifyAllowed()
{
// no mock for config! :(
Config::set('auth.verify_mail', false);
Config::set('auth.allow_register', true);
// mock repository:
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('register')->once()->andReturn(new User);
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
// data:
$data = [
'email' => 'bla@bla'
];
// test
$crawler = $this->client->request('POST', '/register', $data);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
}
public function testLogout()
{
Auth::shouldReceive('logout');
$this->call('GET', '/logout');
}
public function testRemindme()
{
$this->call('GET', '/remindme');
$this->assertResponseOk();
}
public function testPostRemindmeWithVerification()
{
Config::set('auth.verify_reset', true);
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('findByEmail')->once()->andReturn(new User);
$email->shouldReceive('sendResetVerification')->once()->andReturn(true);
$this->call('POST', '/remindme');
$this->assertResponseOk();
}
public function testPostRemindmeWithoutVerification()
{
Config::set('auth.verify_reset', false);
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('findByEmail')->once()->andReturn(new User);
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
$this->call('POST', '/remindme');
$this->assertResponseOk();
}
public function testPostRemindmeFails()
{
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$repository->shouldReceive('findByEmail')->once()->andReturn(null);
$this->call('POST', '/remindme');
$this->assertResponseOk();
$this->assertSessionHas('error', 'No good!');
}
public function testPostRegisterNotAllowed()
{
// no mock for config! :(
Config::set('auth.verify_mail', true);
Config::set('auth.verify_reset', true);
Config::set('auth.allow_register', false);
// mock repository:
$data = [
'email' => 'bla@bla'
];
// test
$this->call('POST', '/register', $data);
$this->assertResponseStatus(200);
$this->assertViewHas('message', 'Not possible');
}
public function testReset()
{
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
$repository->shouldReceive('findByReset')->once()->andReturn(new User);
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
// test
$crawler = $this->client->request('GET', '/reset/blabla');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
}
public function testResetFails()
{
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
$repository->shouldReceive('findByReset')->once()->andReturn(null);
// test
$crawler = $this->client->request('GET', '/reset/blabla');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('h1:contains("Error")'));
$this->assertViewHas('message');
}
public function tearDown()
{
Mockery::close();
}
}

View File

@ -1,223 +0,0 @@
<?php
use League\FactoryMuffin\Facade\FactoryMuffin;
class AllModelsTest extends TestCase
{
/**
* Default preparation for each test
*/
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* Migrate the database
*/
private function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
/**
* User tests
*/
public function testUser()
{
$user = FactoryMuffin::create('User');
$pref = FactoryMuffin::create('Preference');
$account = FactoryMuffin::create('Account');
// some more stuff:
$component = FactoryMuffin::create('Component');
$budget = FactoryMuffin::create('Budget');
$category = FactoryMuffin::create('Category');
$account->user()->associate($user);
$pref->user()->associate($user);
$user->accounts()->save($account);
$user->preferences()->save($pref);
$user->components()->save($component);
$user->budgets()->save($budget);
$user->categories()->save($category);
$this->assertEquals($account->user_id, $user->id);
$this->assertEquals($pref->user_id, $user->id);
$this->assertEquals($budget->user_id, $user->id);
$this->assertEquals($category->user_id, $user->id);
$this->assertEquals($component->user_id, $user->id);
// test pref?
$pref->data = 'Blabla';
$this->assertEquals($pref->data, 'Blabla');
$this->assertCount(1, $user->accounts()->get());
$this->assertCount(1, $user->preferences()->get());
$this->assertTrue(true);
}
/**
* Account tests
*/
public function testUserAccounts()
{
$this->assertTrue(true);
}
/**
* Transaction journal tests.
*/
public function testTransactionJournals()
{
$tj = FactoryMuffin::create('TransactionJournal');
$t1 = FactoryMuffin::create('Transaction');
$t2 = FactoryMuffin::create('Transaction');
$t3 = FactoryMuffin::create('Transaction');
$user = FactoryMuffin::create('User');
$tj->transactions()->save($t1);
$tj->transactions()->save($t2);
$tj->transactions()->save($t3);
$budget = FactoryMuffin::create('Budget');
$category = FactoryMuffin::create('Category');
$tj->components()->save($budget);
$tj->components()->save($category);
$user->transactionjournals()->save($tj);
$tj->user()->associate($user);
$this->assertEquals($tj->user_id, $user->id);
$this->assertCount(2, $tj->components()->get());
$this->assertCount(1, $tj->budgets()->get());
$this->assertCount(1, $tj->categories()->get());
$this->assertCount(1, $user->transactionjournals()->get());
$this->assertCount(3, $tj->transactions()->get());
$this->assertTrue($tj->validate());
$this->assertEquals($tj->transaction_type_id, $tj->transactionType()->first()->id);
$this->assertEquals($tj->transaction_currency_id, $tj->transactionCurrency()->first()->id);
}
public function testTransactionJournalScope()
{
$tj = FactoryMuffin::create('TransactionJournal');
$tj->date = new \Carbon\Carbon('2012-01-02');
$set = $tj->after(new \Carbon\Carbon)->before(new \Carbon\Carbon)->get();
$this->assertCount(0, $set);
}
public function testTransactionType()
{
$j1 = FactoryMuffin::create('TransactionJournal');
$j2 = FactoryMuffin::create('TransactionJournal');
$type = FactoryMuffin::create('TransactionType');
$type->transactionjournals()->save($j1);
$type->transactionjournals()->save($j2);
$this->assertCount(2, $type->transactionjournals()->get());
}
public function testTransactionCurrency()
{
$j1 = FactoryMuffin::create('TransactionJournal');
$j2 = FactoryMuffin::create('TransactionJournal');
$currency = FactoryMuffin::create('TransactionCurrency');
$currency->transactionjournals()->save($j1);
$currency->transactionjournals()->save($j2);
$this->assertCount(2, $currency->transactionjournals()->get());
}
public function testAccountTypes()
{
$type = FactoryMuffin::create('AccountType');
$a1 = FactoryMuffin::create('Account');
$a2 = FactoryMuffin::create('Account');
$type->accounts()->save($a1);
$type->accounts()->save($a2);
$a1->accounttype()->associate($type);
$this->assertEquals($a1->account_type_id, $type->id);
$this->assertCount(2, $type->accounts()->get());
}
public function testBalance()
{
$account = FactoryMuffin::create('Account');
$this->assertEquals(0.0, $account->balance());
}
public function testTransactions()
{
$transaction = FactoryMuffin::create('Transaction');
$budget = FactoryMuffin::create('Budget');
$account = FactoryMuffin::create('Account');
$category = FactoryMuffin::create('Category');
$journal = FactoryMuffin::create('TransactionJournal');
$transaction->components()->save($budget);
$transaction->components()->save($category);
$transaction->account()->associate($account);
$transaction->transactionjournal()->associate($journal);
$account->transactions()->save($transaction);
$this->assertEquals($transaction->account_id, $account->id);
$this->assertCount(1, $transaction->transactionjournal()->get());
$this->assertCount(1, $transaction->account()->get());
$this->assertCount(2, $transaction->components()->get());
$this->assertCount(1, $transaction->budgets()->get());
$this->assertCount(1, $transaction->categories()->get());
}
public function testComponents()
{
$component = FactoryMuffin::create('Component');
$user = FactoryMuffin::create('User');
$transaction = FactoryMuffin::create('Transaction');
$journal = FactoryMuffin::create('TransactionJournal');
$component->transactionjournals()->save($journal);
$component->user()->associate($user);
$component->transactions()->save($transaction);
$this->assertCount(1, $component->transactionjournals()->get());
$this->assertCount(1, $component->user()->get());
$this->assertCount(1, $component->transactions()->get());
}
public function tearDown()
{
Mockery::close();
}
}