From 230bd6e40ad0aaa2fae5303ef933ba0d80b20cf7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 25 Dec 2014 08:00:09 +0100 Subject: [PATCH] Tests for the recurring transaction controller. --- app/controllers/RecurringController.php | 2 +- tests/functional/PiggyBankControllerCest.php | 7 +- tests/functional/RecurringControllerCest.php | 134 +++++++++++++++++++ 3 files changed, 140 insertions(+), 3 deletions(-) diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php index d3a730a5c9..01bb85db08 100644 --- a/app/controllers/RecurringController.php +++ b/app/controllers/RecurringController.php @@ -195,7 +195,7 @@ class RecurringController extends BaseController } // go back to update screen. - return Redirect::route('piggy_banks.edit', $recurringTransaction->id)->withInput(['post_submit_action' => 'return_to_edit']); + return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput(['post_submit_action' => 'return_to_edit']); } } \ No newline at end of file diff --git a/tests/functional/PiggyBankControllerCest.php b/tests/functional/PiggyBankControllerCest.php index c47862c21a..b657ff6f14 100644 --- a/tests/functional/PiggyBankControllerCest.php +++ b/tests/functional/PiggyBankControllerCest.php @@ -210,7 +210,8 @@ class PiggyBankControllerCest 'post_submit_action' => 'create_another', 'remind_me' => 0, 'order' => 3, - 'account_id' => 1, 'targetamount' => 1000] + 'account_id' => 1, + 'targetamount' => 1000] ); $I->see('Piggy bank "Some new piggy bank" stored.'); } @@ -229,7 +230,9 @@ class PiggyBankControllerCest 'reminder_skip' => 0, 'remind_me' => 0, 'order' => 3, - 'account_id' => 1, 'targetamount' => 1000] + 'account_id' => 1, + 'post_submit_action' => 'store', + 'targetamount' => 1000] ); $I->see('Name is too short'); } diff --git a/tests/functional/RecurringControllerCest.php b/tests/functional/RecurringControllerCest.php index e2b296d679..54a5524dc8 100644 --- a/tests/functional/RecurringControllerCest.php +++ b/tests/functional/RecurringControllerCest.php @@ -100,6 +100,7 @@ class RecurringControllerCest { $I->wantTo('show a recurring transaction'); $I->amOnPage('/recurring/show/1'); + $I->see('Huur'); } /** @@ -109,6 +110,84 @@ class RecurringControllerCest { $I->wantTo('store a recurring transaction'); $I->amOnPage('/recurring/create'); + $I->submitForm( + '#store', [ + 'name' => 'Some recurring', + 'match' => 'one,two', + 'amount_min' => 10, + 'amount_max' => 20, + 'post_submit_action' => 'store', + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0 + ] + ); + $I->see('Recurring transaction "Some recurring" stored.'); + } + + /** + * @param FunctionalTester $I + */ + public function storeFail(FunctionalTester $I) + { + $I->wantTo('store a recurring transaction and fail'); + $I->amOnPage('/recurring/create'); + $I->submitForm( + '#store', [ + 'name' => 'Some recurring', + 'match' => '', + 'amount_min' => 10, + 'amount_max' => 20, + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0 + ] + ); + $I->dontSeeInDatabase('recurring_transactions', ['name' => 'Some recurring']); + $I->see('Could not store recurring transaction'); + } + + public function storeRecreate(FunctionalTester $I) + { + $I->wantTo('validate a recurring transaction and create another one'); + $I->amOnPage('/recurring/create'); + $I->submitForm( + '#store', [ + 'name' => 'Some recurring', + 'match' => 'one,two', + 'amount_min' => 10, + 'amount_max' => 20, + 'post_submit_action' => 'create_another', + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0, + + ] + ); + $I->see('Recurring transaction "Some recurring" stored.'); + } + + /** + * @param FunctionalTester $I + */ + public function storeValidate(FunctionalTester $I) + { + $I->wantTo('validate a recurring transaction'); + $I->amOnPage('/recurring/create'); + $I->submitForm( + '#store', [ + 'name' => 'Some recurring', + 'match' => 'one,two', + 'amount_min' => 10, + 'amount_max' => 20, + 'post_submit_action' => 'validate_only', + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0, + + ] + ); + $I->see('form-group has-success has-feedback'); } /** @@ -118,6 +197,61 @@ class RecurringControllerCest { $I->wantTo('update a recurring transaction'); $I->amOnPage('/recurring/edit/1'); + $I->submitForm( + '#update', [ + 'name' => 'Some recurring', + 'match' => 'bla,bla', + 'amount_min' => 10, + 'amount_max' => 20, + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0 + ] + ); + $I->see('Recurring transaction "Some recurring" updated.'); + } + + /** + * @param FunctionalTester $I + */ + public function updateReturn(FunctionalTester $I) + { + $I->wantTo('update a recurring transaction and return to edit it'); + $I->amOnPage('/recurring/edit/1'); + $I->submitForm( + '#update', [ + 'name' => 'Some recurring', + 'match' => 'bla,bla', + 'amount_min' => 10, + 'amount_max' => 20, + 'post_submit_action' => 'return_to_edit', + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0 + ] + ); + $I->see('Recurring transaction "Some recurring" updated.'); + } + + /** + * @param FunctionalTester $I + */ + public function updateFail(FunctionalTester $I) + { + $I->wantTo('update a recurring transaction and fail'); + $I->amOnPage('/recurring/edit/1'); + $I->submitForm( + '#update', [ + 'name' => 'Some recurring', + 'match' => '', + 'amount_min' => 10, + 'amount_max' => 20, + 'date' => date('Y-m-d'), + 'repeat_freq' => 'monthly', + 'skip' => 0 + ] + ); + $I->see('Could not update recurring transaction'); } } \ No newline at end of file