Skip to content

Firefly III: a personal finances manager

More tests! Yay!

James Colece27e97b9259
diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php
index 84be23917a..d3a730a5c9 100644
--- a/app/controllers/RecurringController.php
+++ b/app/controllers/RecurringController.php
@@ -1,6 +1,6 @@
<?php
+use FireflyIII\Database\RecurringTransaction\RecurringTransaction as Repository;
use FireflyIII\Exception\FireflyException;
-use Illuminate\Support\MessageBag;
/**
* Class RecurringController
@@ -8,11 +8,16 @@ use Illuminate\Support\MessageBag;
*/
class RecurringController extends BaseController
{
+
+ /** @var Repository */
+ protected $_repository;
+
/**
- *
+ * @param Repository $repository
*/
- public function __construct()
+ public function __construct(Repository $repository)
{
+ $this->_repository = $repository;
View::share('title', 'Recurring transactions');
View::share('mainTitleIcon', 'fa-rotate-right');
@@ -47,17 +52,8 @@ class RecurringController extends BaseController
*/
public function destroy(RecurringTransaction $recurringTransaction)
{
- //Event::fire('recurring.destroy', [$recurringTransaction]);
-
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repository */
- $repository = App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
-
- $result = $repository->destroy($recurringTransaction);
- if ($result === true) {
- Session::flash('success', 'The recurring transaction was deleted.');
- } else {
- Session::flash('error', 'Could not delete the recurring transaction. Check the logs to be sure.');
- }
+ $this->_repository->destroy($recurringTransaction);
+ Session::flash('success', 'The recurring transaction was deleted.');
return Redirect::route('recurring.index');
@@ -82,10 +78,7 @@ class RecurringController extends BaseController
*/
public function index()
{
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repos */
- $repos = App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
-
- $recurring = $repos->get();
+ $recurring = $this->_repository->get();
return View::make('recurring.index', compact('recurring'));
}
@@ -100,16 +93,14 @@ class RecurringController extends BaseController
if (intval($recurringTransaction->active) == 0) {
Session::flash('warning', 'Inactive recurring transactions cannot be scanned.');
- return Redirect::back();
+ return Redirect::intended('/');
}
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repos */
- $repos = App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
- $repos->scanEverything($recurringTransaction);
+ $this->_repository->scanEverything($recurringTransaction);
Session::flash('success', 'Rescanned everything.');
- return Redirect::back();
+ return Redirect::intended('/');
}
/**
@@ -134,45 +125,35 @@ class RecurringController extends BaseController
*/
public function store()
{
- $data = Input::except('_token');
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repos */
- $repos = App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
-
- switch ($data['post_submit_action']) {
- default:
- throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
- break;
- case 'create_another':
- case 'store':
- $messages = $repos->validate($data);
- /** @var MessageBag $messages ['errors'] */
- if ($messages['errors']->count() > 0) {
- Session::flash('warnings', $messages['warnings']);
- Session::flash('successes', $messages['successes']);
- Session::flash('error', 'Could not save recurring transaction: ' . $messages['errors']->first());
-
- return Redirect::route('recurring.create')->withInput()->withErrors($messages['errors']);
- }
- // store!
- $repos->store($data);
- Session::flash('success', 'New recurring transaction stored!');
-
- if ($data['post_submit_action'] == 'create_another') {
- return Redirect::route('recurring.create')->withInput();
- } else {
- return Redirect::route('recurring.index');
- }
- break;
- case 'validate_only':
- $messageBags = $repos->validate($data);
- Session::flash('warnings', $messageBags['warnings']);
- Session::flash('successes', $messageBags['successes']);
- Session::flash('errors', $messageBags['errors']);
-
- return Redirect::route('recurring.create')->withInput();
- break;
+ $data = Input::all();
+ $data['user_id'] = Auth::user()->id;
+
+
+ // always validate:
+ $messages = $this->_repository->validate($data);
+
+ // flash messages:
+ Session::flash('warnings', $messages['warnings']);
+ Session::flash('successes', $messages['successes']);
+ Session::flash('errors', $messages['errors']);
+ if ($messages['errors']->count() > 0) {
+ Session::flash('error', 'Could not store recurring transaction: ' . $messages['errors']->first());
+ }
+
+ // return to create screen:
+ if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ return Redirect::route('recurring.create')->withInput();
+ }
+
+ // store:
+ $this->_repository->store($data);
+ Session::flash('success', 'Recurring transaction "' . e($data['name']) . '" stored.');
+ if ($data['post_submit_action'] == 'store') {
+ return Redirect::route('recurring.index');
}
+ return Redirect::route('recurring.create')->withInput();
+
}
/**
@@ -183,45 +164,38 @@ class RecurringController extends BaseController
*/
public function update(RecurringTransaction $recurringTransaction)
{
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repos */
- $repos = App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
$data = Input::except('_token');
$data['active'] = isset($data['active']) ? 1 : 0;
$data['automatch'] = isset($data['automatch']) ? 1 : 0;
+ $data['user_id'] = Auth::user()->id;
+
+ // always validate:
+ $messages = $this->_repository->validate($data);
- switch (Input::get('post_submit_action')) {
- default:
- throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
- break;
- case 'create_another':
- case 'update':
- $messages = $repos->validate($data);
- /** @var MessageBag $messages ['errors'] */
- if ($messages['errors']->count() > 0) {
- Session::flash('warnings', $messages['warnings']);
- Session::flash('successes', $messages['successes']);
- Session::flash('error', 'Could not save recurring transaction: ' . $messages['errors']->first());
-
- return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput()->withErrors($messages['errors']);
- }
- // store!
- $repos->update($recurringTransaction, $data);
- Session::flash('success', 'Recurring transaction updated!');
-
- if ($data['post_submit_action'] == 'create_another') {
- return Redirect::route('recurring.edit', $recurringTransaction->id);
- } else {
- return Redirect::route('recurring.index');
- }
- case 'validate_only':
- $messageBags = $repos->validate($data);
- Session::flash('warnings', $messageBags['warnings']);
- Session::flash('successes', $messageBags['successes']);
- Session::flash('errors', $messageBags['errors']);
-
- return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput();
- break;
+ // flash messages:
+ Session::flash('warnings', $messages['warnings']);
+ Session::flash('successes', $messages['successes']);
+ Session::flash('errors', $messages['errors']);
+ if ($messages['errors']->count() > 0) {
+ Session::flash('error', 'Could not update recurring transaction: ' . $messages['errors']->first());
}
+ // return to update screen:
+ if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
+ return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput();
+ }
+
+ // update
+ $this->_repository->update($recurringTransaction, $data);
+ Session::flash('success', 'Recurring transaction "' . e($data['name']) . '" updated.');
+
+ // go back to list
+ if ($data['post_submit_action'] == 'update') {
+ return Redirect::route('recurring.index');
+ }
+
+ // go back to update screen.
+ return Redirect::route('piggy_banks.edit', $recurringTransaction->id)->withInput(['post_submit_action' => 'return_to_edit']);
+
}
}
\ No newline at end of file
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.php
index a6aba6edbf..93e5fee98e 100644
--- a/app/database/seeds/TestContentSeeder.php
+++ b/app/database/seeds/TestContentSeeder.php
@@ -160,7 +160,7 @@ class TestContentSeeder extends Seeder
'amount_min' => 500,
'amount_max' => 700,
'date' => '2014-01-12',
- 'active' => 1,
+ 'active' => 0,
'automatch' => 1,
'repeat_freq' => 'monthly',
'skip' => 0,
diff --git a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
index 289810fb34..796aa17272 100644
--- a/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
+++ b/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php
@@ -36,6 +36,7 @@ class PiggyBank implements CUD, CommonDatabaseCalls, PiggyBankInterface
public function destroy(Eloquent $model)
{
$model->delete();
+
}
/**
diff --git a/app/views/recurring/create.blade.php b/app/views/recurring/create.blade.php
index ef42865842..a14eaf114d 100644
--- a/app/views/recurring/create.blade.php
+++ b/app/views/recurring/create.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}
-{{Form::open(['class' => 'form-horizontal','url' => route('recurring.store')])}}
+{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('recurring.store')])}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">
diff --git a/app/views/recurring/delete.blade.php b/app/views/recurring/delete.blade.php
index a2013a65e4..261d505d12 100644
--- a/app/views/recurring/delete.blade.php
+++ b/app/views/recurring/delete.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $recurringTransaction) }}
-{{Form::open(['class' => 'form-horizontal','url' => route('recurring.destroy',$recurringTransaction->id)])}}
+{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('recurring.destroy',$recurringTransaction->id)])}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="panel panel-red">
diff --git a/app/views/recurring/edit.blade.php b/app/views/recurring/edit.blade.php
index d7bf99bc25..5824b10655 100644
--- a/app/views/recurring/edit.blade.php
+++ b/app/views/recurring/edit.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $recurringTransaction) }}
-{{Form::model($recurringTransaction, ['class' => 'form-horizontal','url' => route('recurring.update', $recurringTransaction->id)])}}
+{{Form::model($recurringTransaction, ['class' => 'form-horizontal','id' => 'update','url' => route('recurring.update', $recurringTransaction->id)])}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">
diff --git a/tests/functional/PiggyBankControllerCest.php b/tests/functional/PiggyBankControllerCest.php
index c86b35f53a..c47862c21a 100644
--- a/tests/functional/PiggyBankControllerCest.php
+++ b/tests/functional/PiggyBankControllerCest.php
@@ -52,6 +52,7 @@ class PiggyBankControllerCest
$I->wantTo('delete a piggy bank');
$I->amOnPage('/piggy_banks/delete/1');
$I->see('Delete &quot;New camera&quot;');
+
}
/**
@@ -64,6 +65,7 @@ class PiggyBankControllerCest
$I->see('Delete &quot;New camera&quot;');
$I->submitForm('#destroy', []);
$I->see('Piggy bank &quot;New camera&quot; deleted.');
+
}
/**
@@ -242,13 +244,13 @@ class PiggyBankControllerCest
$I->see('Edit piggy bank "New camera"');
$I->submitForm(
'#update', [
- 'name' => 'Updated camera',
- 'account_id' => 2,
- 'targetamount' => 2000,
- 'targetdate' => '',
- 'reminder' => 'week',
- 'post_submit_action' => 'update',
- ]
+ 'name' => 'Updated camera',
+ 'account_id' => 2,
+ 'targetamount' => 2000,
+ 'targetdate' => '',
+ 'reminder' => 'week',
+ 'post_submit_action' => 'update',
+ ]
);
$I->see('Piggy bank &quot;Updated camera&quot; updated.');
@@ -311,13 +313,13 @@ class PiggyBankControllerCest
$I->see('Edit piggy bank "New camera"');
$I->submitForm(
'#update', [
- 'name' => '',
- 'account_id' => 2,
- 'targetamount' => 2000,
- 'targetdate' => '',
- 'reminder' => 'week',
- 'post_submit_action' => 'update',
- ]
+ 'name' => '',
+ 'account_id' => 2,
+ 'targetamount' => 2000,
+ 'targetdate' => '',
+ 'reminder' => 'week',
+ 'post_submit_action' => 'update',
+ ]
);
$I->see('Name is too short');
$I->seeInDatabase('piggy_banks', ['name' => 'New camera']);
diff --git a/tests/functional/RecurringControllerCest.php b/tests/functional/RecurringControllerCest.php
new file mode 100644
index 0000000000..e2b296d679
--- /dev/null
+++ b/tests/functional/RecurringControllerCest.php
@@ -0,0 +1,123 @@
+<?php
+
+/**
+ * Class RecurringControllerCest
+ */
+class RecurringControllerCest
+{
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function _after(FunctionalTester $I)
+ {
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function _before(FunctionalTester $I)
+ {
+ $I->amLoggedAs(['email' => '[email protected]', 'password' => 'james']);
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function create(FunctionalTester $I)
+ {
+ $I->wantTo('create a recurring transaction');
+ $I->amOnPage('/recurring/create');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function delete(FunctionalTester $I)
+ {
+ $I->wantTo('delete a recurring transaction');
+ $I->amOnPage('/recurring/delete/1');
+ $I->see('Delete "Huur"');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function destroy(FunctionalTester $I)
+ {
+ $I->wantTo('destroy a recurring transaction');
+ $I->amOnPage('/recurring/delete/1');
+ $I->see('Delete "Huur"');
+ $I->submitForm('#destroy', []);
+ $I->see('The recurring transaction was deleted.');
+
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function edit(FunctionalTester $I)
+ {
+ $I->wantTo('edit a recurring transaction');
+ $I->amOnPage('/recurring/edit/1');
+
+
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function index(FunctionalTester $I)
+ {
+ $I->wantTo('see all recurring transactions');
+ $I->amOnPage('/recurring');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function rescan(FunctionalTester $I)
+ {
+ $I->wantTo('rescan a recurring transaction');
+ $I->amOnPage('/recurring/rescan/1');
+ $I->see('Rescanned everything.');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function rescanInactive(FunctionalTester $I)
+ {
+ $I->wantTo('rescan an inactive recurring transaction');
+ $I->amOnPage('/recurring/rescan/2');
+ $I->see('Inactive recurring transactions cannot be scanned.');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function show(FunctionalTester $I)
+ {
+ $I->wantTo('show a recurring transaction');
+ $I->amOnPage('/recurring/show/1');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function store(FunctionalTester $I)
+ {
+ $I->wantTo('store a recurring transaction');
+ $I->amOnPage('/recurring/create');
+ }
+
+ /**
+ * @param FunctionalTester $I
+ */
+ public function update(FunctionalTester $I)
+ {
+ $I->wantTo('update a recurring transaction');
+ $I->amOnPage('/recurring/edit/1');
+ }
+
+}
\ No newline at end of file