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 testing.sqlite
c3.php c3.php
_ide_helper_models.php _ide_helper_models.php
clean.sqlite

View File

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

View File

@ -1,7 +1,7 @@
@extends('layouts.default') @extends('layouts.default')
@section('content') @section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) }} {{ 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="row">
<div class="col-lg-6 col-md-12 col-sm-12"> <div class="col-lg-6 col-md-12 col-sm-12">
<div class="panel panel-red"> <div class="panel panel-red">
@ -29,16 +29,5 @@
</div> </div>
</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()}} {{Form::close()}}
@stop @stop

View File

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

View File

@ -6,3 +6,19 @@ if (!file_exists($db)) {
exec('touch ' . $db); exec('touch ' . $db);
exec('php artisan migrate --seed --env=testing'); 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 <?php
/**
* Class UserControllerCest
*
* @SuppressWarnings("CamelCase")
* @SuppressWarnings("short")
*/
class UserControllerCest class UserControllerCest
{ {
/** /**
@ -29,6 +35,19 @@ class UserControllerCest
} }
/**
* @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 * @param FunctionalTester $I
*/ */