Skip to content

Firefly III: a personal finances manager

Expanded test coverage.

James Cole5135be300027
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index b0f99940ef..190df02a5d 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -191,12 +191,8 @@ class AccountController extends BaseController
if ($data['post_submit_action'] == 'store') {
return Redirect::route('accounts.index', $data['what']);
}
- // create another.
- if ($data['post_submit_action'] == 'create_another') {
- return Redirect::route('accounts.create', $data['what'])->withInput();
- }
- return Redirect::route('accounts.index', $data['what']);
+ return Redirect::route('accounts.create', $data['what'])->withInput();
}
/**
@@ -235,11 +231,8 @@ class AccountController extends BaseController
if ($data['post_submit_action'] == 'update') {
return Redirect::route('accounts.index', $data['what']);
}
- // go back to update screen.
- if ($data['post_submit_action'] == 'return_to_edit') {
- return Redirect::route('accounts.edit', $account->id)->withInput(['post_submit_action' => 'return_to_edit']);
- }
- return Redirect::route('accounts.index', $data['what']);
+ // go back to update screen.
+ return Redirect::route('accounts.edit', $account->id)->withInput(['post_submit_action' => 'return_to_edit']);
}
}
\ No newline at end of file
diff --git a/app/views/accounts/create.blade.php b/app/views/accounts/create.blade.php
index ac7ec268f8..d3a9e376d2 100644
--- a/app/views/accounts/create.blade.php
+++ b/app/views/accounts/create.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) }}
-{{Form::open(['class' => 'form-horizontal','route' => 'accounts.store'])}}
+{{Form::open(['class' => 'form-horizontal','id' => 'store','route' => 'accounts.store'])}}
{{Form::hidden('what',$what)}}
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
diff --git a/app/views/accounts/edit.blade.php b/app/views/accounts/edit.blade.php
index 8b02f2d20f..cfa7c3357a 100644
--- a/app/views/accounts/edit.blade.php
+++ b/app/views/accounts/edit.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) }}
-{{Form::model($account, ['class' => 'form-horizontal','url' => route('accounts.update',$account->id)])}}
+{{Form::model($account, ['class' => 'form-horizontal','id' => 'update','url' => route('accounts.update',$account->id)])}}
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-primary">
diff --git a/tests/functional/AccountControllerCest.php b/tests/functional/AccountControllerCest.php
index 1a3cc4f215..5eb4630822 100644
--- a/tests/functional/AccountControllerCest.php
+++ b/tests/functional/AccountControllerCest.php
@@ -54,7 +54,6 @@ class AccountControllerCest
$I->amOnPage('/accounts/delete/3');
$I->see('Delete account "Delete me"');
$I->submitForm('#destroy', []);
- // TODO I dont believe this actually works.
$I->dontSeeRecord('accounts', ['id' => 3, 'deleted_at' => null]);
resetToClean::clean();
}
@@ -64,7 +63,7 @@ class AccountControllerCest
*/
public function edit(FunctionalTester $I)
{
- $I->wantTo('delete an asset account');
+ $I->wantTo('edit an asset account');
$I->amOnPage('/accounts/edit/3');
$I->see('Edit asset account "Delete me"');
}
@@ -96,7 +95,55 @@ class AccountControllerCest
*/
public function store(FunctionalTester $I)
{
+ $I->amOnPage('/accounts/create/asset');
$I->wantTo('store a new asset account');
+ $I->see('Create a new asset account');
+ $I->submitForm('#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'store']);
+ $I->seeRecord('accounts', ['name' => 'New through tests.']);
+ resetToClean::clean();
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function storeValidateOnly(FunctionalTester $I)
+ {
+ $I->amOnPage('/accounts/create/asset');
+ $I->wantTo('store a new asset account');
+ $I->see('Create a new asset account');
+ $I->submitForm(
+ '#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']
+ );
+ $I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
+ resetToClean::clean();
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function storeAndCreateAnother(FunctionalTester $I)
+ {
+ $I->amOnPage('/accounts/create/asset');
+ $I->wantTo('store a new asset account and create another');
+ $I->see('Create a new asset account');
+ $I->submitForm(
+ '#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'create_another']
+ );
+ $I->seeRecord('accounts', ['name' => 'New through tests.']);
+ resetToClean::clean();
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function storeFail(FunctionalTester $I)
+ {
+ $I->amOnPage('/accounts/create/asset');
+ $I->wantTo('make storing a new asset account fail.');
+ $I->see('Create a new asset account');
+ $I->submitForm('#store', ['name' => null, 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']);
+ $I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
+ resetToClean::clean();
}
/**
@@ -105,6 +152,56 @@ class AccountControllerCest
public function update(FunctionalTester $I)
{
$I->wantTo('update an asset account');
+ $I->amOnPage('/accounts/edit/3');
+ $I->see('Edit asset account "Delete me"');
+ $I->submitForm('#update', ['name' => 'Update me', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'update']);
+ $I->seeRecord('accounts', ['name' => 'Update me']);
+ resetToClean::clean();
+
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function failUpdate(FunctionalTester $I)
+ {
+ $I->wantTo('update an asset account and fail');
+ $I->amOnPage('/accounts/edit/3');
+ $I->see('Edit asset account "Delete me"');
+ $I->submitForm('#update', ['name' => '', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'update']);
+ $I->seeRecord('accounts', ['name' => 'Delete me']);
+
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function validateUpdateOnly(FunctionalTester $I)
+ {
+ $I->wantTo('update an asset account and validate only');
+ $I->amOnPage('/accounts/edit/2');
+ $I->see('Edit asset account "Savings account"');
+ $I->submitForm(
+ '#update', ['name' => 'Savings accountXX', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']
+ );
+ $I->dontSeeRecord('accounts', ['name' => 'Savings accountXX']);
+
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function updateAndReturn(FunctionalTester $I)
+ {
+ $I->wantTo('update an asset account and return to form');
+ $I->amOnPage('/accounts/edit/2');
+ $I->see('Edit asset account "Savings account"');
+ $I->submitForm(
+ '#update', ['name' => 'Savings accountXX', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'return_to_edit']
+ );
+ $I->seeRecord('accounts', ['name' => 'Savings accountXX']);
+ resetToClean::clean();
+
}
}
\ No newline at end of file