mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Included full home controller tests.
This commit is contained in:
@@ -32,6 +32,9 @@ class HomeController extends Controller
|
|||||||
Session::put('end', $end);
|
Session::put('end', $end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
public function flush()
|
public function flush()
|
||||||
{
|
{
|
||||||
Session::clear();
|
Session::clear();
|
||||||
@@ -58,7 +61,7 @@ class HomeController extends Controller
|
|||||||
$savings = $repository->getSavingsAccounts();
|
$savings = $repository->getSavingsAccounts();
|
||||||
|
|
||||||
// check if all books are correct.
|
// check if all books are correct.
|
||||||
$sum = floatval(Auth::user()->transactions()->sum('amount'));
|
$sum = $repository->sumOfEverything();
|
||||||
if ($sum != 0) {
|
if ($sum != 0) {
|
||||||
Session::flash(
|
Session::flash(
|
||||||
'error', 'Your transactions are unbalanced. This means a'
|
'error', 'Your transactions are unbalanced. This means a'
|
||||||
|
@@ -151,6 +151,13 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
|
->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function sumOfEverything() {
|
||||||
|
return floatval(Auth::user()->transactions()->sum('amount'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param int $page
|
* @param int $page
|
||||||
|
@@ -94,6 +94,11 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getLastActivity(Account $account);
|
public function getLastActivity(Account $account);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function sumOfEverything();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get savings accounts and the balance difference in the period.
|
* Get savings accounts and the balance difference in the period.
|
||||||
*
|
*
|
||||||
|
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class HelpControllerTest
|
||||||
|
*/
|
||||||
class HelpControllerTest extends TestCase
|
class HelpControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +85,6 @@ class HelpControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
// login
|
// login
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$content = ['title' => 'Bla', 'text' => 'Bla'];
|
|
||||||
|
|
||||||
$this->be($user);
|
$this->be($user);
|
||||||
// mock some stuff.
|
// mock some stuff.
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
|
* Class HomeControllerTest
|
||||||
*/
|
*/
|
||||||
class HomeControllerTest extends TestCase
|
class HomeControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -13,7 +16,6 @@ class HomeControllerTest extends TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Artisan::call('migrate');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +34,8 @@ class HomeControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$start = '2015-03-01';
|
$start = '2015-03-01';
|
||||||
$end = '2015-03-31';
|
$end = '2015-03-31';
|
||||||
$this->be(new FireflyIII\User);
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
|
||||||
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
|
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
|
||||||
@@ -43,6 +46,7 @@ class HomeControllerTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
|
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
|
||||||
*/
|
*/
|
||||||
@@ -50,37 +54,61 @@ class HomeControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$start = '2014-03-01';
|
$start = '2014-03-01';
|
||||||
$end = '2015-03-31';
|
$end = '2015-03-31';
|
||||||
$this->be(new FireflyIII\User);
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
|
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
|
|
||||||
$this->assertSessionHas('start');
|
$this->assertSessionHas('start');
|
||||||
$this->assertSessionHas('end');
|
$this->assertSessionHas('end');
|
||||||
$this->assertSessionHas('warning');
|
$this->assertSessionHas('warning');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testFlush()
|
||||||
|
{
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
$this->call('GET', '/flush');
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Http\Controllers\HomeController::index
|
* @covers FireflyIII\Http\Controllers\HomeController::index
|
||||||
*/
|
*/
|
||||||
public function testIndexLoggedIn()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
$this->be(new FireflyIII\User);
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
Amount::shouldReceive('getCurrencyCode')->andReturn('EUR');
|
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
|
$journals = new Collection([$journal]);
|
||||||
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
$accounts = new Collection([$account]);
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
$response = $this->call('GET', '/');
|
$this->be($user);
|
||||||
|
|
||||||
|
// mock ALL THE THINGS!
|
||||||
|
$repository->shouldReceive('countAccounts')->once()->andReturn(3);
|
||||||
|
Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($preference);
|
||||||
|
$repository->shouldReceive('getFrontpageAccounts')->once()->with($preference)->andReturn($accounts);
|
||||||
|
$repository->shouldReceive('getSavingsAccounts')->once()->andReturn($accounts);
|
||||||
|
$repository->shouldReceive('sumOfEverything')->once()->andReturn(1);
|
||||||
|
$repository->shouldReceive('getFrontpageTransactions')->once()->andReturn($journals);
|
||||||
|
|
||||||
|
|
||||||
|
Amount::shouldReceive('getCurrencyCode')->andReturn('EUR');
|
||||||
|
Amount::shouldReceive('format')->andReturn('xxx');
|
||||||
|
Amount::shouldReceive('formatJournal')->with($journal)->andReturn('xxx');
|
||||||
|
|
||||||
|
$this->call('GET', '/');
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers FireflyIII\Http\Controllers\HomeController::index
|
|
||||||
*/
|
|
||||||
public function testIndexNoLogin()
|
|
||||||
{
|
|
||||||
$response = $this->call('GET', '/');
|
|
||||||
$this->assertRedirectedTo('auth/login');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user