Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New tests for the repeated expenses.
James Cole1f0e692ee23a
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.phpindex 525d6fd4b6..111ca5bb5f 100644--- a/app/database/seeds/TestContentSeeder.php+++ b/app/database/seeds/TestContentSeeder.php@@ -194,6 +194,41 @@ class TestContentSeeder extends Seeder]);+ // recurring transaction+ $recurring = PiggyBank::create(+ [+ 'account_id' => $savings->id,+ 'name' => 'Nieuwe kleding',+ 'targetamount' => 1000,+ 'startdate' => Carbon::now()->subMonth()->format('Y-m-d'),+ 'targetdate' => Carbon::now()->format('Y-m-d'),+ 'repeats' => 1,+ 'rep_length' => 'month',+ 'rep_every' => 0,+ 'rep_times' => 0,+ 'reminder' => 'month',+ 'reminder_skip' => 0,+ 'remind_me' => 1,+ 'order' => 0,+ ]+ );+ PiggyBankRepetition::create(+ [+ 'piggy_bank_id' => $recurring->id,+ 'startdate' => Carbon::now()->format('Y-m-d'),+ 'targetdate' => Carbon::now()->addMonth()->format('Y-m-d'),+ 'currentamount' => 0+ ]+ );+ PiggyBankRepetition::create(+ [+ 'piggy_bank_id' => $recurring->id,+ 'startdate' => Carbon::now()->subMonth()->format('Y-m-d'),+ 'targetdate' => Carbon::now()->format('Y-m-d'),+ 'currentamount' => 0+ ]+ );+// bill$firstBill = \Bill::create([diff --git a/app/models/Piggybank.php b/app/models/Piggybank.phpindex 9f5b6a942f..57f497fdac 100644--- a/app/models/Piggybank.php+++ b/app/models/Piggybank.php@@ -9,6 +9,9 @@ use Watson\Validating\ValidatingTrait;class PiggyBank extends Eloquent{use ValidatingTrait;+ public $fillable+ = ['account_id', 'name', 'targetamount', 'startdate', 'targetdate', 'repeats', 'rep_length', 'rep_every', 'rep_times', 'reminder', 'reminder_skip',+ 'remind_me', 'order'];protected $rules= ['account_id' => 'required|exists:accounts,id', // link to Account'name' => 'required|between:1,255', // name@@ -23,9 +26,6 @@ class PiggyBank extends Eloquent'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months?'remind_me' => 'required|boolean', 'order' => 'required:min:1', // not yet used.];- public $fillable- = ['account_id', 'name', 'targetamount', 'startdate', 'targetdate', 'repeats', 'rep_length', 'rep_every', 'rep_times', 'reminder', 'reminder_skip',- 'remind_me', 'order'];/*** @return \Illuminate\Database\Eloquent\Relations\BelongsTo@@ -95,7 +95,7 @@ class PiggyBank extends Eloquentreturn $rep;} else {- $query = $this->piggyBankRepetitions()->where(+ $query = $this->piggyBankRepetitions()->where(function ($q) {$q->where(@@ -105,28 +105,28 @@ class PiggyBank extends Eloquentfunction ($q) {$today = new Carbon;$q->whereNull('startdate');- $q->orWhere('startdate', '<=', $today->format('Y-m-d'));+ $q->orWhere('startdate', '<=', $today->format('Y-m-d 00:00:00'));})->where(function ($q) {$today = new Carbon;$q->whereNull('targetdate');- $q->orWhere('targetdate', '>=', $today->format('Y-m-d'));+ $q->orWhere('targetdate', '>=', $today->format('Y-m-d 00:00:00'));});})->orWhere(function ($q) {$today = new Carbon;- $q->where('startdate', '>=', $today->format('Y-m-d'));- $q->where('targetdate', '>=', $today->format('Y-m-d'));+ $q->where('startdate', '>=', $today->format('Y-m-d 00:00:00'));+ $q->where('targetdate', '>=', $today->format('Y-m-d 00:00:00'));});}- )- ->orderBy('startdate', 'ASC');- $result = $query->first(['piggy_bank_repetitions.*']);+ )->orderBy('startdate', 'ASC');+ $result = $query->first(['piggy_bank_repetitions.*']);+ \Log::debug('Result is null: ' . boolstr(is_null($result)));$this->currentRep = $result;\Log::debug('Found relevant rep in currentRelevantRep(): ' . $result->id);diff --git a/app/views/repeatedexpense/create.blade.php b/app/views/repeatedexpense/create.blade.phpindex 3a051bb0c4..374579360d 100644--- a/app/views/repeatedexpense/create.blade.php+++ b/app/views/repeatedexpense/create.blade.php@@ -1,7 +1,7 @@@extends('layouts.default')@section('content'){{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}-{{Form::open(['class' => 'form-horizontal','url' => route('repeated.store')])}}+{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('repeated.store')])}}<div class="row"><div class="col-lg-6 col-md-12 col-sm-6">diff --git a/tests/functional/RepeatedExpenseCest.php b/tests/functional/RepeatedExpenseCest.phpdeleted file mode 100644index a24bcf14f8..0000000000--- a/tests/functional/RepeatedExpenseCest.php+++ /dev/null@@ -1,23 +0,0 @@-<?php--/**- * Class RepeatedExpenseCest- */-class RepeatedExpenseCest {- /**- * @param FunctionalTester $I- */- public function _after(FunctionalTester $I)- {- }-- /**- * @param FunctionalTester $I- */- public function _before(FunctionalTester $I)- {- $I->amLoggedAs(['email' => '[email protected]', 'password' => 'james']);- }---}\ No newline at end of filediff --git a/tests/functional/RepeatedExpenseControllerCest.php b/tests/functional/RepeatedExpenseControllerCest.phpnew file mode 100644index 0000000000..75a44f5a85--- /dev/null+++ b/tests/functional/RepeatedExpenseControllerCest.php@@ -0,0 +1,151 @@+<?php++/**+ * Class RepeatedExpenseControllerCest+ */+class RepeatedExpenseControllerCest+{+ /**+ * @param FunctionalTester $I+ */+ public function _after(FunctionalTester $I)+ {+ }++ /**+ * @param FunctionalTester $I+ */+ public function _before(FunctionalTester $I)+ {+ $I->amLoggedAs(['email' => '[email protected]', 'password' => 'james']);+ }++ public function create(FunctionalTester $I)+ {+ $I->wantTo('create a recurring transaction');+ $I->amOnPage('/repeatedexpenses/create');+ $I->see('Create new repeated expense');+ }++ public function delete(FunctionalTester $I)+ {+ $I->wantTo('delete a recurring transaction');+ $I->amOnPage('/repeatedexpenses/delete/4');+ $I->see('Delete "Nieuwe kleding"');+ }++ public function destroy(FunctionalTester $I)+ {+ $I->wantTo('destroy a recurring transaction');+ $I->amOnPage('/repeatedexpenses/delete/4');+ $I->submitForm('#destroy', []);+ $I->dontSeeInDatabase('piggy_banks', ['id' => 5]);+ }++ public function edit(FunctionalTester $I)+ {+ $I->wantTo('edit a recurring transaction');+ $I->amOnPage('/repeatedexpenses/edit/4');+ $I->see('Edit repeated expense "Nieuwe kleding"');++ }++ public function index(FunctionalTester $I)+ {+ $I->wantTo('see all recurring transactions');+ $I->amOnPage('/repeatedexpenses');+ $I->see('Overview');+ $I->see('Nieuwe kleding');+ }++ public function show(FunctionalTester $I)+ {+ $I->wantTo('view a recurring transaction');+ $I->amOnPage('/repeatedexpenses/show/4');+ $I->see('Nieuwe kleding');+ }++ public function store(FunctionalTester $I)+ {+ $I->wantTo('store a recurring transaction');+ $I->amOnPage('/repeatedexpenses/create');+ $I->submitForm(+ '#store', [+ 'name' => 'TestRepeatedExpense',+ 'account_id' => 1,+ 'targetamount' => 1000,+ 'targetdate' => '2014-05-01',+ 'rep_length' => 'month',+ 'rep_every' => 0,+ 'rep_times' => 0,+ 'remind_me' => 1,+ 'reminder' => 'month',+ 'post_submit_action' => 'store',+ ]+ );+ $I->see('Piggy bank "TestRepeatedExpense" stored.');+ }++ public function update(FunctionalTester $I)+ {+ $I->wantTo('update a recurring transaction');+ $I->amOnPage('/repeatedexpenses/edit/4');+ $I->submitForm(+ '#update', [+ 'name' => 'Nieuwe kleding!',+ 'account_id' => 2,+ 'targetamount' => 1000.00,+ 'targetdate' => '2014-12-30',+ 'rep_length' => 'month',+ 'rep_every' => 0,+ 'rep_times' => 0,+ 'remind_me' => 1,+ 'reminder' => 'month',+ 'post_submit_action' => 'update',+ ]+ );+ $I->see('Repeated expense "Nieuwe kleding!" updated.');+ }++ public function updateAndReturnToEdit(FunctionalTester $I)+ {+ $I->wantTo('update a recurring transaction and return to edit screen');+ $I->amOnPage('/repeatedexpenses/edit/4');+ $I->submitForm(+ '#update', [+ 'name' => 'Nieuwe kleding!',+ 'account_id' => 2,+ 'targetamount' => 1000.00,+ 'targetdate' => '2014-12-30',+ 'rep_length' => 'month',+ 'rep_every' => 0,+ 'rep_times' => 0,+ 'remind_me' => 1,+ 'reminder' => 'month',+ 'post_submit_action' => 'return_to_edit',+ ]+ );+ $I->see('Repeated expense "Nieuwe kleding!" updated.');+ }++ public function updateFail(FunctionalTester $I)+ {+ $I->wantTo('try to update a recurring transaction and fail');+ $I->amOnPage('/repeatedexpenses/edit/4');+ $I->submitForm(+ '#update', [+ 'name' => '',+ 'account_id' => 2,+ 'targetamount' => 1000.00,+ 'targetdate' => '2014-12-30',+ 'rep_length' => 'month',+ 'rep_every' => 0,+ 'rep_times' => 0,+ 'remind_me' => 1,+ 'reminder' => 'month',+ 'post_submit_action' => 'update',+ ]+ );+ $I->see('The name field is required.');+ }+}\ No newline at end of file