Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Tests for reminders.
James Cole89363ecfa3b1
diff --git a/app/controllers/ReminderController.php b/app/controllers/ReminderController.phpindex 873ac2b7eb..9760dedced 100644--- a/app/controllers/ReminderController.php+++ b/app/controllers/ReminderController.php@@ -26,25 +26,22 @@ class ReminderController extends BaseControllerpublic function act(Reminder $reminder){- switch (get_class($reminder->remindersable)) {- default:- throw new FireflyException('Cannot act on reminder for ' . get_class($reminder->remindersable));- break;- break;- case 'PiggyBank':- $amount = Reminders::amountForReminder($reminder);- $preFilled = [- 'amount' => round($amount, 2),- 'description' => 'Money for ' . $reminder->remindersable->name,- 'piggy_bank_id' => $reminder->remindersable_id,- 'account_to_id' => $reminder->remindersable->account_id- ];- Session::flash('preFilled', $preFilled);-- return Redirect::route('transactions.create', 'transfer');- break;+ $class = get_class($reminder->remindersable);+ if ($class == 'PiggyBank') {+ $amount = Reminders::amountForReminder($reminder);+ $preFilled = [+ 'amount' => round($amount, 2),+ 'description' => 'Money for ' . $reminder->remindersable->name,+ 'piggy_bank_id' => $reminder->remindersable_id,+ 'account_to_id' => $reminder->remindersable->account_id+ ];+ Session::flash('preFilled', $preFilled);++ return Redirect::route('transactions.create', 'transfer');}++ return View::make('error')->with('message', 'This reminder has an invalid class connected to it.');}/**@@ -66,7 +63,7 @@ class ReminderController extends BaseController** @return \Illuminate\Http\RedirectResponse*/- public function notnow(Reminder $reminder)+ public function notNow(Reminder $reminder){$reminder->active = 0;$reminder->notnow = 1;diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.phpindex 1d43dc075d..bc68264062 100644--- a/app/database/seeds/TestContentSeeder.php+++ b/app/database/seeds/TestContentSeeder.php@@ -97,6 +97,8 @@ class TestContentSeeder extends Seeder'order' => 0,]);++PiggyBankEvent::create(['piggy_bank_id' => 1, 'date' => $startDate->format('Y-m-d'), 'amount' => 100]);PiggyBankRepetition::create([@@ -136,6 +138,59 @@ class TestContentSeeder extends Seeder]);+ // weekly reminder piggy bank+ $weekly = PiggyBank::create(+ [+ 'account_id' => $savings->id,+ 'name' => 'Weekly reminder for clothes',+ 'targetamount' => 2000,+ 'startdate' => Carbon::now()->format('Y-m-d'),+ 'targetdate' => Carbon::now()->addYear()->subDay()->format('Y-m-d'),+ 'repeats' => 0,+ 'rep_length' => null,+ 'rep_every' => 0,+ 'rep_times' => null,+ 'reminder' => 'week',+ 'reminder_skip' => 0,+ 'remind_me' => 1,+ 'order' => 0,+ ]+ );+ PiggyBankRepetition::create(+ [+ 'piggy_bank_id' => $weekly->id,+ 'startdate' => Carbon::now()->format('Y-m-d'),+ 'targetdate' => Carbon::now()->addYear()->subDay()->format('Y-m-d'),+ 'currentamount' => 0+ ]+ );++ // a fake reminder for this piggy bank:+ Reminder::create(+ [+ 'user_id' => $user->id,+ 'startdate' => $startDate->format('Y-m-d'),+ 'enddate' => Carbon::now()->addWeek()->format('Y-m-d'),+ 'active' => 1,+ 'notnow' => 0,+ 'remindersable_id' => $weekly->id,+ 'remindersable_type' => 'PiggyBank'+ ]+ );++ // a fake reminder for this piggy bank:+ Reminder::create(+ [+ 'user_id' => $user->id,+ 'startdate' => $startDate->format('Y-m-d'),+ 'enddate' => Carbon::now()->addWeek()->format('Y-m-d'),+ 'active' => 1,+ 'notnow' => 0,+ 'remindersable_id' => 40,+ 'remindersable_type' => 'Transaction'+ ]+ );+// bill$firstBill = \Bill::create([@@ -168,6 +223,7 @@ class TestContentSeeder extends Seeder]);+// create some expense accounts.$albert = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'Albert Heijn', 'active' => 1]);$plus = Account::create(['user_id' => $user->id, 'account_type_id' => $expenseType->id, 'name' => 'PLUS', 'active' => 1]);diff --git a/app/lib/FireflyIII/Shared/Toolkit/Date.php b/app/lib/FireflyIII/Shared/Toolkit/Date.phpindex 5ec5af4148..09ee90cabe 100644--- a/app/lib/FireflyIII/Shared/Toolkit/Date.php+++ b/app/lib/FireflyIII/Shared/Toolkit/Date.php@@ -26,7 +26,7 @@ class Dateswitch ($repeatFreq) {default:- throw new FireflyException('Cannot do addPeriod for $repeat_freq ' . $repeatFreq);+ throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"');break;case 'daily':$date->addDays($add);diff --git a/app/routes.php b/app/routes.phpindex d68c319738..efaf3ee653 100644--- a/app/routes.php+++ b/app/routes.php@@ -257,7 +257,7 @@ Route::group(// reminder controllerRoute::get('/reminders/{reminder}', ['uses' => 'ReminderController@show', 'as' => 'reminders.show']);Route::get('/reminders/{reminder}/dismiss', ['uses' => 'ReminderController@dismiss', 'as' => 'reminders.dismiss']);- Route::get('/reminders/{reminder}/notnow', ['uses' => 'ReminderController@notnow', 'as' => 'reminders.notnow']);+ Route::get('/reminders/{reminder}/notNow', ['uses' => 'ReminderController@notNow', 'as' => 'reminders.notNow']);Route::get('/reminders/{reminder}/act', ['uses' => 'ReminderController@act', 'as' => 'reminders.act']);// search controller:diff --git a/app/views/reminders/show.blade.php b/app/views/reminders/show.blade.phpindex a01b3a8882..115c9aaf24 100644--- a/app/views/reminders/show.blade.php+++ b/app/views/reminders/show.blade.php@@ -6,7 +6,7 @@<div class="panel panel-primary"><div class="panel-heading">A reminder about- @if(get_class($reminder->remindersable) == 'Piggybank')+ @if(get_class($reminder->remindersable) == 'PiggyBank')your piggy bank labelled "{{{$reminder->remindersable->name}}}"@endif</div>@@ -22,7 +22,7 @@<p><a href="{{route('reminders.act',$reminder->id)}}" class="btn btn-primary"><i class="fa fa-fw fa-thumbs-o-up"></i> I want to do this</a><a href="{{route('reminders.dismiss',$reminder->id)}}" class="btn btn-success"><i class="fa fa-smile-o fa-fw"></i> I already did this</a>- <a href="{{route('reminders.notnow',$reminder->id)}}" class="btn btn-danger"><i class="fa fa-fw fa-clock-o"></i> Not this time</a>+ <a href="{{route('reminders.notNow',$reminder->id)}}" class="btn btn-danger"><i class="fa fa-fw fa-clock-o"></i> Not this time</a></p></div>diff --git a/tests/functional/ReminderControllerCest.php b/tests/functional/ReminderControllerCest.phpnew file mode 100644index 0000000000..3415dd1ad5--- /dev/null+++ b/tests/functional/ReminderControllerCest.php@@ -0,0 +1,60 @@+<?php++/**+ * Class ReminderControllerCest+ */+class ReminderControllerCest+{++ /**+ * @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 act(FunctionalTester $I)+ {+ $I->wantTo('act on a reminder');+ $I->amOnPage('/reminders/1/act');+ $I->see('Money for Weekly reminder for clothes');+ }++ public function dismiss(FunctionalTester $I)+ {+ $I->wantTo('dismiss a reminder');+ $I->amOnPage('/reminders/1/dismiss');+ $I->see('Reminder dismissed');+ }++ public function notNow(FunctionalTester $I)+ {+ $I->wantTo('ignore a reminder');+ $I->amOnPage('/reminders/1/notNow');+ $I->see('Reminder dismissed');+ }++ public function show(FunctionalTester $I)+ {+ $I->wantTo('see a reminder');+ $I->amOnPage('/reminders/1');+ $I->see('A reminder about');+ $I->see('your piggy bank labelled "Weekly reminder for clothes"');+ }++ public function actOnInvalid(FunctionalTester $I)+ {+ $I->wantTo('act on an invalid reminder');+ $I->amOnPage('/reminders/2/act');+ $I->see('This reminder has an invalid class connected to it.');+ }++}\ No newline at end of file