Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fixed some basic tests.
James Cole3b11bd0593e2
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex 627fbf4d0c..a2926001fb 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -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];}diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 7cb8e23608..506f0b9ddd 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -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 AccountRepositoryInterfacereturn 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 $pagediff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex 644f67744d..020ae41b69 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -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 $rangediff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex 98cab769c9..185fea9512 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -45,12 +45,12 @@ class Preferencesif (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;diff --git a/phpunit.xml b/phpunit.xmlindex a440863019..7fd14d7b0c 100644--- a/phpunit.xml+++ b/phpunit.xml@@ -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"/>diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 76bcb54c16..971e451ea7 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -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();diff --git a/tests/controllers/HomeControllerTest.php b/tests/controllers/HomeControllerTest.phpnew file mode 100644index 0000000000..cb03ff6fbd--- /dev/null+++ b/tests/controllers/HomeControllerTest.php@@ -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();++ }++}