Tests for reminders.

This commit is contained in:
James Cole 2014-12-29 21:49:43 +01:00
parent 593e799ca1
commit 89363ecfa3
6 changed files with 134 additions and 21 deletions

View File

@ -26,25 +26,22 @@ class ReminderController extends BaseController
public 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);
$class = get_class($reminder->remindersable);
return Redirect::route('transactions.create', 'transfer');
break;
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;

View File

@ -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]);

View File

@ -26,7 +26,7 @@ class Date
switch ($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);

View File

@ -257,7 +257,7 @@ Route::group(
// reminder controller
Route::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:

View File

@ -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>

View File

@ -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' => 'thegrumpydictator@gmail.com', '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.');
}
}