mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 08:21:08 -06:00
Fixed some basic tests.
This commit is contained in:
parent
3f89057528
commit
3b11bd0593
@ -3,6 +3,7 @@
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Redirect;
|
||||
@ -51,9 +52,10 @@ class HomeController extends Controller
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$count = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count();
|
||||
|
||||
$count = $repository->countAssetAccounts();
|
||||
$title = 'Firefly';
|
||||
$subTitle = 'What\'s playing?';
|
||||
$mainTitleIcon = 'fa-fire';
|
||||
@ -61,26 +63,10 @@ class HomeController extends Controller
|
||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
|
||||
if ($frontPage->data == []) {
|
||||
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
} else {
|
||||
$accounts = Auth::user()->accounts()->whereIn('id', $frontPage->data)->get(['accounts.*']);
|
||||
}
|
||||
$accounts = $repository->getFrontpageAccounts($frontPage);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$set = Auth::user()
|
||||
->transactionjournals()
|
||||
->with(['transactions', 'transactioncurrency', 'transactiontype'])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->take(10)
|
||||
->get(['transaction_journals.*']);
|
||||
$set = $repository->getFrontpageTransactions($account, $start, $end);
|
||||
if (count($set) > 0) {
|
||||
$transactions[] = [$set, $account];
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Session;
|
||||
|
||||
@ -25,6 +27,14 @@ use Session;
|
||||
class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countAssetAccounts()
|
||||
{
|
||||
return Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
@ -37,6 +47,44 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getFrontpageAccounts(Preference $preference)
|
||||
{
|
||||
if ($preference->data == []) {
|
||||
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
} else {
|
||||
$accounts = Auth::user()->accounts()->whereIn('id', $preference->data)->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
}
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
return Auth::user()
|
||||
->transactionjournals()
|
||||
->with(['transactions', 'transactioncurrency', 'transactiontype'])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->take(10)
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param int $page
|
||||
|
@ -4,7 +4,9 @@ namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
use FireflyIII\Models\Preference;
|
||||
use Illuminate\Support\Collection;
|
||||
use Carbon\Carbon;
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
*
|
||||
@ -19,6 +21,27 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function destroy(Account $account);
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countAssetAccounts();
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getFrontpageAccounts(Preference $preference);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $range
|
||||
|
@ -45,12 +45,12 @@ class Preferences
|
||||
if (is_null($pref)) {
|
||||
$pref = new Preference;
|
||||
$pref->name = $name;
|
||||
$pref->user()->associate(Auth::user());
|
||||
|
||||
}
|
||||
$pref->data = $value;
|
||||
$pref->save();
|
||||
|
||||
if (!is_null(Auth::user()->id)) {
|
||||
$pref->user()->associate(Auth::user());
|
||||
$pref->save();
|
||||
}
|
||||
|
||||
return $pref;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
@ -21,9 +21,11 @@
|
||||
</filter>
|
||||
|
||||
<!-- code coverage -->
|
||||
<!--
|
||||
<logging>
|
||||
<log type="coverage-clover" target="./storage/coverage/clover.xml" charset="UTF-8" />
|
||||
</logging>
|
||||
-->
|
||||
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
|
@ -13,7 +13,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__ . '/../../bootstrap/app.php';
|
||||
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||
|
||||
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
|
||||
|
||||
|
68
tests/controllers/HomeControllerTest.php
Normal file
68
tests/controllers/HomeControllerTest.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
|
||||
*/
|
||||
class HomeControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
|
||||
*/
|
||||
public function testDateRange()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete('This test has not been implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::flush
|
||||
*/
|
||||
public function testFlush()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete('This test has not been implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::index
|
||||
*/
|
||||
public function testIndexNoLogin()
|
||||
{
|
||||
$response = $this->call('GET', '/');
|
||||
$this->assertRedirectedTo('auth/login');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::index
|
||||
*/
|
||||
public function testIndexLoggedIn()
|
||||
{
|
||||
$this->be(new FireflyIII\User);
|
||||
$response = $this->call('GET', '/');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user