From 8eae1750c178c2b6407244bb12e4fdabea16e2a5 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 Aug 2014 13:21:24 +0200 Subject: [PATCH] Bunch of new tests. --- app/controllers/ReportController.php | 1 + app/models/RecurringTransaction.php | 70 ++++---- app/routes.php | 3 + .../controllers/PreferencesControllerTest.php | 53 ++++++ .../controllers/RecurringControllerTest.php | 161 ++++++++++++++++++ .../controllers/ReportControllerTest.php | 27 +++ app/tests/controllers/UserControllerTes.php | 9 + 7 files changed, 295 insertions(+), 29 deletions(-) create mode 100644 app/tests/controllers/PreferencesControllerTest.php create mode 100644 app/tests/controllers/RecurringControllerTest.php create mode 100644 app/tests/controllers/ReportControllerTest.php create mode 100644 app/tests/controllers/UserControllerTes.php diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index efc703856d..85c94bbbc7 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -6,6 +6,7 @@ class ReportController extends BaseController public function index() { + } } \ No newline at end of file diff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.php index dbdac05da0..9dafdccac3 100644 --- a/app/models/RecurringTransaction.php +++ b/app/models/RecurringTransaction.php @@ -1,36 +1,37 @@ 'required|between:0,31', ]; - public static $factory - = [ - 'user_id' => 'factory|User', - 'name' => 'string', - 'data' => 'string' + public static function factory() + { + $date = new Carbon; + + return [ + 'user_id' => 'factory|User', + 'name' => 'string', + 'match' => 'string', + 'amount_max' => 100, + 'amount_min' => 50, + 'date' => $date, + 'active' => 1, + 'automatch' => 1, + 'repeat_freq' => 'monthly', + 'skip' => 0, ]; + } public function getDates() { diff --git a/app/routes.php b/app/routes.php index 0e167c8f0d..bf81fc53cb 100644 --- a/app/routes.php +++ b/app/routes.php @@ -156,6 +156,9 @@ Route::group(['before' => 'auth'], function () { Route::get('/recurring/edit/{recurring}',['uses' => 'RecurringController@edit','as' => 'recurring.edit']); Route::get('/recurring/delete/{recurring}',['uses' => 'RecurringController@delete','as' => 'recurring.delete']); + // report controller: + Route::get('/reports',['uses' => 'ReportController@index','as' => 'reports.index']); + // transaction controller: Route::get('/transactions/create/{what}', ['uses' => 'TransactionController@create', 'as' => 'transactions.create'])->where(['what' => 'withdrawal|deposit|transfer']); Route::get('/transaction/show/{tj}',['uses' => 'TransactionController@show','as' => 'transactions.show']); diff --git a/app/tests/controllers/PreferencesControllerTest.php b/app/tests/controllers/PreferencesControllerTest.php new file mode 100644 index 0000000000..19b4a38958 --- /dev/null +++ b/app/tests/controllers/PreferencesControllerTest.php @@ -0,0 +1,53 @@ +_user = m::mock('User', 'Eloquent'); + $this->_helper = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); + $this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); + + } + + public function tearDown() + { + m::close(); + } + + public function testIndex() + { + $viewRange = $this->mock('Preference'); + $viewRange->shouldReceive('getAttribute')->with('data')->andReturn('1M'); + + $this->_accounts->shouldReceive('getDefault')->andReturn([]); + $this->_helper->shouldReceive('get')->with('viewRange','1M')->andReturn($viewRange); + $this->_helper->shouldReceive('get')->with('frontpageAccounts',[])->andReturn([]); + + + $this->action('GET', 'PreferencesController@index'); + $this->assertResponseOk(); + } + + public function testPostIndex() + { + $this->_helper->shouldReceive('set')->with('frontpageAccounts',[1]); + $this->_helper->shouldReceive('set')->with('viewRange','1M'); + $this->action('POST', 'PreferencesController@postIndex',['frontpageAccounts' => [1],'viewRange' => '1M']); + $this->assertResponseStatus(302); + } +} \ No newline at end of file diff --git a/app/tests/controllers/RecurringControllerTest.php b/app/tests/controllers/RecurringControllerTest.php new file mode 100644 index 0000000000..93742695a0 --- /dev/null +++ b/app/tests/controllers/RecurringControllerTest.php @@ -0,0 +1,161 @@ +_user = m::mock('User', 'Eloquent'); + $this->_repository = $this->mock( + 'Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface' + ); + + } + + public function tearDown() + { + m::close(); + } + + public function testCreate() + { + $this->action('GET', 'RecurringController@create'); + $this->assertResponseOk(); + } + + public function testDelete() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); + + + $this->action('GET', 'RecurringController@delete',$recurringTransaction->id); + $this->assertResponseOk(); + } + + public function testDestroy() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); + $this->_repository->shouldReceive('destroy')->andReturn(true); + + $this->action('POST', 'RecurringController@destroy',$recurringTransaction->id); + $this->assertResponseStatus(302); + } + + public function testDestroyFails() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); + $this->_repository->shouldReceive('destroy')->andReturn(false); + + $this->action('POST', 'RecurringController@destroy',$recurringTransaction->id); + $this->assertResponseStatus(302); + } + + public function testEdit() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); + + $this->action('GET', 'RecurringController@edit',$recurringTransaction->id); + $this->assertResponseOk(); + } + + public function testIndex() + { + + $this->_repository->shouldReceive('get')->andReturn([]); + + $this->action('GET', 'RecurringController@index'); + $this->assertResponseOk(); + } + + public function testShow() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); + + + $this->action('GET', 'RecurringController@show',$recurringTransaction->id); + $this->assertResponseOk(); + } + + public function testStore() + { + $recurringTransaction = f::create('RecurringTransaction'); + + $this->_repository->shouldReceive('store')->andReturn($recurringTransaction); + $this->action('POST', 'RecurringController@store'); + $this->assertResponseStatus(302); + } + + public function testStoreRedirect() + { + $recurringTransaction = f::create('RecurringTransaction'); + + $this->_repository->shouldReceive('store')->andReturn($recurringTransaction); + $this->action('POST', 'RecurringController@store',['create' => '1']); + $this->assertResponseStatus(302); + } + + public function testStoreFails() + { + $recurringTransaction = f::create('RecurringTransaction'); + unset($recurringTransaction->id); + + $this->_repository->shouldReceive('store')->andReturn($recurringTransaction); + $this->action('POST', 'RecurringController@store',['create' => '1']); + $this->assertResponseStatus(302); + } + + public function testUpdate() + { + $recurringTransaction = f::create('RecurringTransaction'); + + // for binding + Auth::shouldReceive('user')->andReturn($this->_user); + Auth::shouldReceive('check')->andReturn(true); + $this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); + + + $this->action('POST', 'RecurringController@update',$recurringTransaction->id); + $this->assertResponseOk(); + } +} \ No newline at end of file diff --git a/app/tests/controllers/ReportControllerTest.php b/app/tests/controllers/ReportControllerTest.php new file mode 100644 index 0000000000..e548e8e88e --- /dev/null +++ b/app/tests/controllers/ReportControllerTest.php @@ -0,0 +1,27 @@ +action('GET', 'ReportController@index'); + $this->assertResponseOk(); + } + +} \ No newline at end of file diff --git a/app/tests/controllers/UserControllerTes.php b/app/tests/controllers/UserControllerTes.php new file mode 100644 index 0000000000..26a93f57f2 --- /dev/null +++ b/app/tests/controllers/UserControllerTes.php @@ -0,0 +1,9 @@ +assertTrue(true); + } +} \ No newline at end of file