Fixed the tests.

This commit is contained in:
James Cole 2015-04-02 22:39:31 +02:00
parent 5362231efa
commit f301da83c6
5 changed files with 87 additions and 6 deletions

View File

@ -3,6 +3,8 @@
use Auth;
use FireflyIII\Http\Requests;
use FireflyIII\Http\Requests\BillFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@ -21,12 +23,59 @@ use View;
class BillController extends Controller
{
/**
*
*/
public function __construct()
{
View::share('title', 'Bills');
View::share('mainTitleIcon', 'fa-calendar-o');
}
/**
* @param Bill $bill
*
* @return \Illuminate\Http\RedirectResponse
*/
public function add(Bill $bill)
{
$matches = explode(',', $bill->match);
$description = [];
$expense = null;
// get users expense accounts:
$type = AccountType::where('type', 'Expense account')->first();
$accounts = Auth::user()->accounts()->where('account_type_id', $type->id)->get();
foreach ($matches as $match) {
$match = strtolower($match);
// find expense account for each word if not found already:
if (is_null($expense)) {
/** @var Account $account */
foreach ($accounts as $account) {
$name = strtolower($account->name);
if (!(strpos($name, $match) === false)) {
$expense = $account;
break;
}
}
}
if (is_null($expense)) {
$description[] = $match;
}
}
$parameters = [
'description' => ucfirst(join(' ', $description)),
'expense_account' => is_null($expense) ? '' : $expense->name,
'amount' => round(($bill->amount_min + $bill->amount_max), 2),
];
Session::put('preFilled', $parameters);
return Redirect::to(route('transactions.create', 'withdrawal'));
}
/**
* @return $this
*/

View File

@ -167,6 +167,7 @@ Route::group(
Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching.
Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']);
Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']);
Route::get('/bills/add/{bill}', ['uses' => 'BillController@add', 'as' => 'bills.add']);
Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']);
Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']);

View File

@ -514,6 +514,27 @@ class TestDataSeeder extends Seeder
return null;
}
/**
* @param $name
*
* @return PiggyBank|null
*/
protected function findPiggyBank($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->first();
/** @var Budget $budget */
foreach (PiggyBank::get() as $piggyBank) {
$account = $piggyBank->account()->first();
if ($piggyBank->name == $name && $user->id == $account->user_id) {
return $piggyBank;
break;
}
}
return null;
}
/**
* @param $name
*
@ -638,13 +659,13 @@ class TestDataSeeder extends Seeder
// piggy bank event
// add money to this piggy bank
// create a piggy bank event to match:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();
$checking = $this->findAccount('Checking account');
$savings = $this->findAccount('Savings account');
$transfer = TransactionType::whereType('Transfer')->first();
$euro = TransactionCurrency::whereCode('EUR')->first();
$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();
$house = Category::whereName('House')->orderBy('id', 'DESC')->first();
$piggyBank = PiggyBank::whereName('New camera')->orderBy('id', 'DESC')->first();
$groceries = $this->findBudget('Groceries');
$house = $this->findCategory('House');
$piggyBank = $this->findPiggyBank('New camera');
$intoPiggy = $this->createJournal(
['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy',
'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]

View File

@ -9,6 +9,7 @@
<th>Is active</th>
<th>Will be automatched</th>
<th>Repeats every</th>
<th>&nbsp;</th>
</tr>
@foreach($bills as $entry)
<tr>
@ -66,6 +67,11 @@
skips over {{$entry->skip}}
@endif
</td>
<td>
@if($entry->active)
<a href="{{route('bills.add',$entry->id)}}" class="btn btn-success btn-xs"><i class="fa fa-fw fa-plus-circle"></i></a>
@endif
</td>
</tr>
@endforeach

View File

@ -1,5 +1,6 @@
<?php
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
/**
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
@ -35,8 +36,11 @@ class AccountControllerTest extends TestCase
$pref = new Preference;
$pref->data = '1M';
// CURRENCY:
$currency = new TransactionCurrency;
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);
Amount::shouldReceive('getDefaultCurrency')->andReturn(null);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
$response = $this->call('GET', '/accounts/create/asset');
$this->assertResponseOk();