Updated some tests, fixed some bugs.

This commit is contained in:
James Cole 2014-12-13 09:36:30 +01:00
parent 7350b1da1b
commit 7af55b7268
9 changed files with 193 additions and 66 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ tests/_output/*
testing.sqlite
c3.php
_ide_helper_models.php
clean.sqlite

View File

@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use Grumpydictator\Gchart\GChart as GChart;
/**
* Class GoogleChartController
@ -7,6 +8,18 @@ use Carbon\Carbon;
class GoogleChartController extends BaseController
{
/** @var GChart */
protected $_chart;
/**
* @param GChart $chart
*/
public function __construct(GChart $chart)
{
$this->_chart = $chart;
}
/**
* @param Account $account
* @param string $view
@ -15,55 +28,35 @@ class GoogleChartController extends BaseController
*/
public function accountBalanceChart(Account $account, $view = 'session')
{
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
$this->_chart->addColumn('Day of month', 'date');
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
$chart->addColumn('Day of month', 'date');
$chart->addColumn('Balance for ' . $account->name, 'number');
$start = Session::get('start');
$end = Session::get('end');
$count = $account->transactions()->count();
/*
* Loop the date, then loop the accounts, then add balance.
*/
switch ($view) {
default:
case 'session':
$start = Session::get('start');
$end = Session::get('end');
break;
case 'all':
$first = $account->transactionjournals()->orderBy('date', 'DESC')->first();
$last = $account->transactionjournals()->orderBy('date', 'ASC')->first();
if (is_null($first)) {
$start = Session::get('start');
} else {
$start = clone $first->date;
}
if (is_null($last)) {
$end = Session::get('end');
} else {
$end = clone $last->date;
}
break;
if ($view == 'all' && $count > 0) {
$first = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
'date', 'ASC'
)->first(['transaction_journals.date']);
$last = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
'date', 'DESC'
)->first(['transaction_journals.date']);
$start = new Carbon($first->date);
$end = new Carbon($last->date);
}
$current = clone $start;
while ($end >= $current) {
$row = [clone $current];
if ($current > Carbon::now()) {
$row[] = null;
} else {
$row[] = Steam::balance($account, $current);
}
$chart->addRowArray($row);
$this->_chart->addRow(clone $current, $current > Carbon::now() ? null : Steam::balance($account, $current));
$current->addDay();
}
$chart->generate();
$this->_chart->generate();
return Response::json($chart->getData());
return Response::json($this->_chart->getData());
}
/**

View File

@ -2,6 +2,9 @@
use Carbon\Carbon;
/**
* Class TestContentSeeder
*/
class TestContentSeeder extends Seeder
{
@ -27,6 +30,7 @@ class TestContentSeeder extends Seeder
// create two asset accounts.
$checking = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
$savings = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
$deleteMe = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
// create two budgets:
$groceriesBudget = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);

View File

@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) }}
{{Form::open(['class' => 'form-horizontal','url' => route('accounts.destroy',$account->id)])}}
{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('accounts.destroy',$account->id)])}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="panel panel-red">
@ -29,16 +29,5 @@
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<div class="col-sm-8">
</div>
</div>
</div>
</div>
{{Form::close()}}
@stop

View File

@ -23,7 +23,7 @@
"require": {
"laravel/framework": "4.2.*",
"davejamesmiller/laravel-breadcrumbs": "2.*",
"grumpydictator/gchart": "dev-master",
"grumpydictator/gchart": "1.*",
"michelf/php-markdown": "1.*",
"watson/validating": "0.10.*"
},

25
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "248937553255d85014e6ec3b32115848",
"hash": "4149e5d1a8b58787b3e9f68fc8cf40b9",
"packages": [
{
"name": "classpreloader/classpreloader",
@ -195,7 +195,7 @@
},
{
"name": "grumpydictator/gchart",
"version": "dev-master",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/JC5/gchart.git",
@ -324,16 +324,16 @@
},
{
"name": "laravel/framework",
"version": "v4.2.11",
"version": "v4.2.12",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "e29253c7f29e3b1ca716de7fe309b272e3ddf47d"
"reference": "70a60f2ff9b96b3fcd88a68ef5382557733fe671"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/e29253c7f29e3b1ca716de7fe309b272e3ddf47d",
"reference": "e29253c7f29e3b1ca716de7fe309b272e3ddf47d",
"url": "https://api.github.com/repos/laravel/framework/zipball/70a60f2ff9b96b3fcd88a68ef5382557733fe671",
"reference": "70a60f2ff9b96b3fcd88a68ef5382557733fe671",
"shasum": ""
},
"require": {
@ -435,7 +435,7 @@
"framework",
"laravel"
],
"time": "2014-10-04 18:48:27"
"time": "2014-12-11 17:14:36"
},
{
"name": "michelf/php-markdown",
@ -2828,16 +2828,16 @@
},
{
"name": "guzzlehttp/ringphp",
"version": "1.0.4",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/guzzle/RingPHP.git",
"reference": "9187999f80720b9494692d2167d75144acb2ad05"
"reference": "a903f51b692427318bc813217c0e6505287e79a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/RingPHP/zipball/9187999f80720b9494692d2167d75144acb2ad05",
"reference": "9187999f80720b9494692d2167d75144acb2ad05",
"url": "https://api.github.com/repos/guzzle/RingPHP/zipball/a903f51b692427318bc813217c0e6505287e79a4",
"reference": "a903f51b692427318bc813217c0e6505287e79a4",
"shasum": ""
},
"require": {
@ -2874,7 +2874,7 @@
"homepage": "https://github.com/mtdowling"
}
],
"time": "2014-12-02 05:01:22"
"time": "2014-12-11 05:50:32"
},
{
"name": "guzzlehttp/streams",
@ -4162,7 +4162,6 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"grumpydictator/gchart": 20,
"barryvdh/laravel-debugbar": 0,
"barryvdh/laravel-ide-helper": 0,
"satooshi/php-coveralls": 20,

View File

@ -1,8 +1,24 @@
<?php
// This is global bootstrap for autoloading
$db = realpath(__DIR__ . '/_data') . '/testing.sqlite';
$db = realpath(__DIR__ . '/_data') . '/testing.sqlite';
if (!file_exists($db)) {
exec('touch ' . $db);
exec('php artisan migrate --seed --env=testing');
}
exec('cp ' . $db . ' ' . realpath(__DIR__ . '/_data') . '/clean.sqlite');
/**
* Class resetToClean
* @SuppressWarnings("CamelCase")
*/
class resetToClean
{
/**
*
*/
static public function clean()
{
exec('cp ' . realpath(__DIR__ . '/_data') . '/clean.sqlite ' . realpath(__DIR__ . '/_data') . '/testing.sqlite');
}
}

View File

@ -0,0 +1,106 @@
<?php
use Carbon\Carbon;
/**
* Class AccountControllerCest
*/
class AccountControllerCest
{
/**
* @param FunctionalTester $I
*/
public function _after(FunctionalTester $I)
{
}
/**
* @param FunctionalTester $I
*/
public function _before(FunctionalTester $I)
{
$I->amLoggedAs(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james']);
Session::put('start', new Carbon);
Session::put('end', new Carbon);
}
/**
* @param FunctionalTester $I
*/
public function create(FunctionalTester $I)
{
// @codingStandardsIgnoreStart
$I->wantTo('create a new asset account');
$I->amOnPage('/accounts/create/asset');
$I->see('Create a new asset account');
}
/**
* @param FunctionalTester $I
*/
public function delete(FunctionalTester $I)
{
$I->wantTo('delete an asset account');
$I->amOnPage('/accounts/delete/3');
$I->see('Delete account "Delete me"');
}
/**
* @param FunctionalTester $I
*/
public function destroy(FunctionalTester $I)
{
$I->wantTo('destroy an asset account');
}
/**
* @param FunctionalTester $I
*/
public function edit(FunctionalTester $I)
{
$I->wantTo('delete an asset account');
$I->amOnPage('/accounts/edit/3');
$I->see('Edit asset account "Delete me"');
}
/**
* @param FunctionalTester $I
*/
public function index(FunctionalTester $I)
{
$I->wantTo('see a list of accounts');
$I->amOnPage('/accounts/asset');
$I->see('Checking account');
$I->see('Delete me');
}
/**
* @param FunctionalTester $I
*/
public function show(FunctionalTester $I)
{
$I->wantTo('see one account');
#$I->amOnPage('/accounts/show/3');
#$I->see('Details for');
#$I->see('Delete me');
}
/**
* @param FunctionalTester $I
*/
public function store(FunctionalTester $I)
{
$I->wantTo('store a new asset account');
}
/**
* @param FunctionalTester $I
*/
public function update(FunctionalTester $I)
{
$I->wantTo('update an asset account');
}
}

View File

@ -1,5 +1,11 @@
<?php
/**
* Class UserControllerCest
*
* @SuppressWarnings("CamelCase")
* @SuppressWarnings("short")
*/
class UserControllerCest
{
/**
@ -24,11 +30,24 @@ class UserControllerCest
$I->wantTo('login');
$I->amOnPage('/login');
$I->see('Sign In');
$I->submitForm('#login', ['email' => 'functional@example.com','password' => 'functional']);
$I->submitForm('#login', ['email' => 'functional@example.com', 'password' => 'functional']);
$I->see('functional@example.com');
}
/**
* @param FunctionalTester $I
*/
public function loginFails(FunctionalTester $I)
{
$I->wantTo('fail the login');
$I->amOnPage('/login');
$I->see('Sign In');
$I->submitForm('#login', ['email' => 'functional@example.com', 'password' => 'wrong']);
$I->see('No good');
}
/**
* @param FunctionalTester $I
*/
@ -57,7 +76,7 @@ class UserControllerCest
$I->wantTo('post-register a new account');
$I->amOnPage('/register');
$token = $I->grabValueFrom('input[name=_token]');
$I->submitForm('#register', ['email' => 'noreply@gmail.com','_token' => $token]);
$I->submitForm('#register', ['email' => 'noreply@gmail.com', '_token' => $token]);
$I->see('Password sent!');
$I->seeRecord('users', ['email' => 'noreply@gmail.com']);
// @codingStandardsIgnoreEnd