Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update tests, fixes some bugs.
James Coleb4eac84097b2
diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.phpindex 54e886abab..8b234d3e36 100644--- a/app/Http/Controllers/Transaction/MassController.php+++ b/app/Http/Controllers/Transaction/MassController.php@@ -58,7 +58,7 @@ class MassController extends Controller** @return View*/- public function massDelete(Collection $journals)+ public function delete(Collection $journals){$subTitle = trans('firefly.mass_delete_journals');@@ -77,7 +77,7 @@ class MassController extends Controller** @return mixed*/- public function massDestroy(MassDeleteJournalRequest $request, JournalRepositoryInterface $repository)+ public function destroy(MassDeleteJournalRequest $request, JournalRepositoryInterface $repository){$ids = $request->get('confirm_mass_delete');$set = new Collection;@@ -114,7 +114,7 @@ class MassController extends Controller** @return View*/- public function massEdit(Collection $journals)+ public function edit(Collection $journals){$subTitle = trans('firefly.mass_edit_journals');@@ -187,7 +187,7 @@ class MassController extends Controller** @return mixed*/- public function massUpdate(MassEditJournalRequest $request, JournalRepositoryInterface $repository)+ public function update(MassEditJournalRequest $request, JournalRepositoryInterface $repository){$journalIds = $request->get('journals');$count = 0;diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.phpindex 0b90f476f8..451777784c 100644--- a/app/Http/breadcrumbs.php+++ b/app/Http/breadcrumbs.php@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\TransactionType;use FireflyIII\User;+use Illuminate\Support\Collection;/*** HOME@@ -652,6 +653,29 @@ Breadcrumbs::register(});+/**+ * MASS TRANSACTION EDIT / DELETE+ */+Breadcrumbs::register(+ 'transactions.mass.edit', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) {++ $journalIds = $journals->pluck('id')->toArray();+ $what = strtolower($journals->first()->transactionType->type);+ $breadcrumbs->parent('transactions.index', $what);+ $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));+}+);++Breadcrumbs::register(+ 'transactions.mass.delete', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) {++ $journalIds = $journals->pluck('id')->toArray();+ $what = strtolower($journals->first()->transactionType->type);+ $breadcrumbs->parent('transactions.index', $what);+ $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.delete', $journalIds));+}+);+/*** SPLITdiff --git a/app/Repositories/Journal/JournalTasker.php b/app/Repositories/Journal/JournalTasker.phpindex 16cc5a5f3a..eb77c77e6f 100644--- a/app/Repositories/Journal/JournalTasker.php+++ b/app/Repositories/Journal/JournalTasker.php@@ -113,8 +113,8 @@ class JournalTasker implements JournalTaskerInterface/** @var Transaction $entry */foreach ($set as $entry) {- $sourceBalance = $this->getBalance($entry->id);- $destinationBalance = $this->getBalance($entry->destination_id);+ $sourceBalance = $this->getBalance(intval($entry->id));+ $destinationBalance = $this->getBalance(intval($entry->destination_id));$budget = $entry->budgets->first();$category = $entry->categories->first();$transaction = [diff --git a/resources/views/transactions/mass-delete.twig b/resources/views/transactions/mass-delete.twigindex 6eec80dec5..f3525c1d6c 100644--- a/resources/views/transactions/mass-delete.twig+++ b/resources/views/transactions/mass-delete.twig@@ -1,11 +1,11 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journals) }}{% endblock %}{% block content %}- <form method="POST" action="{{ route('transactions.mass-destroy') }}" accept-charset="UTF-8" class="form-horizontal" id="destroy">+ <form method="POST" action="{{ route('transactions.mass.destroy') }}" accept-charset="UTF-8" class="form-horizontal" id="destroy"><input name="_token" type="hidden" value="{{ csrf_token() }}"><div class="row">diff --git a/resources/views/transactions/mass-edit.twig b/resources/views/transactions/mass-edit.twigindex 6489998547..1399aea9d4 100644--- a/resources/views/transactions/mass-edit.twig+++ b/resources/views/transactions/mass-edit.twig@@ -1,11 +1,11 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journals) }}{% endblock %}{% block content %}- <form method="POST" action="{{ route('transactions.mass-update') }}" accept-charset="UTF-8" class="form-horizontal" id="destroy">+ <form method="POST" action="{{ route('transactions.mass.update') }}" accept-charset="UTF-8" class="form-horizontal" id="destroy"><input name="_token" type="hidden" value="{{ csrf_token() }}"><div class="row">diff --git a/routes/web.php b/routes/web.phpindex e96979ecfe..f6dbed2f93 100755--- a/routes/web.php+++ b/routes/web.php@@ -228,9 +228,11 @@ Route::group(Route::get('expense', ['uses' => 'AccountController@expenseAccounts', 'as' => 'expense']);Route::get('revenue', ['uses' => 'AccountController@revenueAccounts', 'as' => 'revenue']);Route::get('report/{accountList}/{start_date}/{end_date}', ['uses' => 'AccountController@report', 'as' => 'report']);+ Route::get('all/{account}', ['uses' => 'AccountController@period', 'as' => 'all']); // TODORoute::get('single/{account}', ['uses' => 'AccountController@single', 'as' => 'single']);Route::get('period/{account}/{date}', ['uses' => 'AccountController@period', 'as' => 'period']);+Route::get('income-category/{account}/{start_date}/{end_date}', ['uses' => 'AccountController@incomeCategory', 'as' => 'income-category']);Route::get('expense-category/{account}/{start_date}/{end_date}', ['uses' => 'AccountController@expenseCategory', 'as' => 'expense-category']);Route::get('expense-budget/{account}/{start_date}/{end_date}', ['uses' => 'AccountController@expenseBudget', 'as' => 'expense-budget']);@@ -307,8 +309,8 @@ Route::group(* Chart\PiggyBank Controller*/Route::group(- ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/piggy-bank','as'=> 'chart.piggy-bank.'], function () {- Route::get('{piggyBank}', ['uses' => 'PiggyBankController@history','as' => 'history']);+ ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/piggy-bank', 'as' => 'chart.piggy-bank.'], function () {+ Route::get('{piggyBank}', ['uses' => 'PiggyBankController@history', 'as' => 'history']);});@@ -593,9 +595,11 @@ Route::group(*/Route::group(['middleware' => 'user-full-auth', 'prefix' => 'transactions', 'as' => 'transactions.'], function () {- Route::get('{what}', ['uses' => 'TransactionController@index', 'as' => 'index'])->where(['what' => 'withdrawal|deposit|transfers']);- Route::get('{what}/all', ['uses' => 'TransactionController@indexAll', 'as' => 'index.all'])->where(['what' => 'withdrawal|deposit|transfers']);- Route::get('{what}/{date}', ['uses' => 'TransactionController@indexByDate', 'as' => 'index.date'])->where(['what' => 'withdrawal|deposit|transfers']);+ Route::get('{what}', ['uses' => 'TransactionController@index', 'as' => 'index'])->where(['what' => 'withdrawal|deposit|transfers|transfer']);+ Route::get('{what}/all', ['uses' => 'TransactionController@indexAll', 'as' => 'index.all'])->where(['what' => 'withdrawal|deposit|transfers|transfer']);+ Route::get('{what}/{date}', ['uses' => 'TransactionController@indexByDate', 'as' => 'index.date'])->where(+ ['what' => 'withdrawal|deposit|transfers|transfer']+ );Route::get('show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'show']);Route::post('reorder', ['uses' => 'TransactionController@reorder', 'as' => 'reorder']);}diff --git a/tests/acceptance/Controllers/Transaction/MassControllerTest.php b/tests/acceptance/Controllers/Transaction/MassControllerTest.phpindex 4e51159a00..f5278bd6da 100644--- a/tests/acceptance/Controllers/Transaction/MassControllerTest.php+++ b/tests/acceptance/Controllers/Transaction/MassControllerTest.php@@ -30,58 +30,81 @@ class MassControllerTest extends TestCase}/**- * @covers \FireflyIII\Http\Controllers\Transaction\MassController::massDelete- * Implement testMassDelete().+ * @covers \FireflyIII\Http\Controllers\Transaction\MassController::delete*/- public function testMassDelete()+ public function testDelete(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('get', route('transactions.mass.delete', [561, 562]));+ $this->assertResponseStatus(200);+ $this->see('Delete a number of transactions');+ // has bread crumb+ $this->see('<ol class="breadcrumb">');}/**- * @covers \FireflyIII\Http\Controllers\Transaction\MassController::massDestroy- * Implement testMassDestroy().+ * @covers \FireflyIII\Http\Controllers\Transaction\MassController::destroy*/- public function testMassDestroy()+ public function testDestroy(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );- }+ $this->session(['transactions.mass-delete.url' => 'http://localhost']);++ $data = [+ 'confirm_mass_delete' => [56, 37],+ ];+ $this->be($this->user());+ $this->call('post', route('transactions.mass.destroy'), $data);+ $this->assertSessionHas('success');+ $this->assertResponseStatus(302);++ // visit them should give 404.+ $this->call('get', route('transactions.show', [56]));+ $this->assertResponseStatus(404);+- /**- * @covers \FireflyIII\Http\Controllers\Transaction\MassController::massEdit- * Implement testMassEdit().- */- public function testMassEdit()- {- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );}/**- * @covers \FireflyIII\Http\Controllers\Transaction\MassController::massUpdate- * Implement testMassUpdate().+ * @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit*/- public function testMassUpdate()+ public function testEdit(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('get', route('transactions.mass.delete', [132, 113]));+ $this->assertResponseStatus(200);+ $this->see('Edit a number of transactions');+ // has bread crumb+ $this->see('<ol class="breadcrumb">');}/**- * Tears down the fixture, for example, closes a network connection.- * This method is called after a test is executed.+ * @covers \FireflyIII\Http\Controllers\Transaction\MassController::update*/- protected function tearDown()+ public function testUpdate(){++ $this->session(['transactions.mass-edit.url' => 'http://localhost']);++ $data = [+ 'journals' => [132],+ 'description' => [132 => 'Updated salary thing'],+ 'amount' => [132 => 1600],+ 'amount_currency_id_amount_132' => 1,+ 'date' => [132 => '2014-07-24'],+ 'source_account_name' => [132 => 'Job'],+ 'destination_account_id' => [132 => 1],+ 'category' => [132 => 'Salary'],+ ];++ $this->be($this->user());+ $this->call('post', route('transactions.mass.update', [132]), $data);+ $this->assertSessionHas('success');+ $this->assertResponseStatus(302);++ // visit them should show updated content+ $this->call('get', route('transactions.show', [132]));+ $this->assertResponseStatus(200);+ $this->see('Updated salary thing');}+}diff --git a/tests/acceptance/Controllers/Transaction/SingleControllerTest.php b/tests/acceptance/Controllers/Transaction/SingleControllerTest.phpindex b653368754..172aa7d0d4 100644--- a/tests/acceptance/Controllers/Transaction/SingleControllerTest.php+++ b/tests/acceptance/Controllers/Transaction/SingleControllerTest.php@@ -11,6 +11,8 @@namespace Transaction;+use FireflyIII\Models\TransactionJournal;+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use TestCase;/**@@ -31,81 +33,110 @@ class SingleControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create- * Implement testCreate().*/public function testCreate(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('get', route('transactions.create', ['withdrawal']));+ $this->assertResponseStatus(200);+ // has bread crumb+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::delete- * Implement testDelete().*/public function testDelete(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('get', route('transactions.delete', [12]));+ $this->assertResponseStatus(200);+ // has bread crumb+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::destroy- * Implement testDestroy().*/public function testDestroy(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->session(['transactions.delete.url' => 'http://localhost']);+ $this->be($this->user());++ $repository = $this->mock(JournalRepositoryInterface::class);+ $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);+ $repository->shouldReceive('delete')->once();++ $this->call('post', route('transactions.destroy', [13]));+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');}/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit- * Implement testEdit().*/public function testEdit(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('get', route('transactions.edit', [13]));+ $this->assertResponseStatus(200);+ // has bread crumb+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store- * Implement testStore().*/public function testStore(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->session(['transactions.create.url' => 'http://localhost']);+ $this->be($this->user());++ $data = [+ 'what' => 'withdrawal',+ 'amount' => 10,+ 'amount_currency_id_amount' => 1,+ 'source_account_id' => 1,+ 'destination_account_name' => 'Some destination',+ 'date' => '2016-01-01',+ 'description' => 'Some description',+ ];+ $this->call('post', route('transactions.store', ['withdrawal']), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');}/*** @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update- * Implement testUpdate().*/public function testUpdate(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );- }+ $this->session(['transactions.edit.url' => 'http://localhost']);+ $this->be($this->user());+ $data = [+ 'id' => 123,+ 'what' => 'withdrawal',+ 'description' => 'Updated groceries',+ 'source_account_id' => 1,+ 'destination_account_name' => 'PLUS',+ 'amount' => 123,+ 'amount_currency_id_amount' => 1,+ 'budget_id' => 1,+ 'category' => 'Daily groceries',+ 'tags' => '',+ 'date' => '2016-01-01',+ ];++ $this->call('post', route('transactions.update', [123]), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');++ $this->call('get', route('transactions.show', [123]));+ $this->assertResponseStatus(200);+ $this->see('Updated groceries');+ // has bread crumb+ $this->see('<ol class="breadcrumb">');- /**- * Tears down the fixture, for example, closes a network connection.- * This method is called after a test is executed.- */- protected function tearDown()- {}+}