Update tests, fixes some bugs.

This commit is contained in:
James Cole
2016-12-11 10:38:06 +01:00
parent ec3b356f86
commit b4eac84097
8 changed files with 169 additions and 87 deletions

View File

@@ -58,7 +58,7 @@ class MassController extends Controller
* *
* @return View * @return View
*/ */
public function massDelete(Collection $journals) public function delete(Collection $journals)
{ {
$subTitle = trans('firefly.mass_delete_journals'); $subTitle = trans('firefly.mass_delete_journals');
@@ -77,7 +77,7 @@ class MassController extends Controller
* *
* @return mixed * @return mixed
*/ */
public function massDestroy(MassDeleteJournalRequest $request, JournalRepositoryInterface $repository) public function destroy(MassDeleteJournalRequest $request, JournalRepositoryInterface $repository)
{ {
$ids = $request->get('confirm_mass_delete'); $ids = $request->get('confirm_mass_delete');
$set = new Collection; $set = new Collection;
@@ -114,7 +114,7 @@ class MassController extends Controller
* *
* @return View * @return View
*/ */
public function massEdit(Collection $journals) public function edit(Collection $journals)
{ {
$subTitle = trans('firefly.mass_edit_journals'); $subTitle = trans('firefly.mass_edit_journals');
@@ -187,7 +187,7 @@ class MassController extends Controller
* *
* @return mixed * @return mixed
*/ */
public function massUpdate(MassEditJournalRequest $request, JournalRepositoryInterface $repository) public function update(MassEditJournalRequest $request, JournalRepositoryInterface $repository)
{ {
$journalIds = $request->get('journals'); $journalIds = $request->get('journals');
$count = 0; $count = 0;

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection;
/** /**
* HOME * 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));
}
);
/** /**
* SPLIT * SPLIT

View File

@@ -113,8 +113,8 @@ class JournalTasker implements JournalTaskerInterface
/** @var Transaction $entry */ /** @var Transaction $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$sourceBalance = $this->getBalance($entry->id); $sourceBalance = $this->getBalance(intval($entry->id));
$destinationBalance = $this->getBalance($entry->destination_id); $destinationBalance = $this->getBalance(intval($entry->destination_id));
$budget = $entry->budgets->first(); $budget = $entry->budgets->first();
$category = $entry->categories->first(); $category = $entry->categories->first();
$transaction = [ $transaction = [

View File

@@ -1,11 +1,11 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journals) }}
{% endblock %} {% endblock %}
{% block content %} {% 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() }}"> <input name="_token" type="hidden" value="{{ csrf_token() }}">
<div class="row"> <div class="row">

View File

@@ -1,11 +1,11 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journals) }}
{% endblock %} {% endblock %}
{% block content %} {% 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() }}"> <input name="_token" type="hidden" value="{{ csrf_token() }}">
<div class="row"> <div class="row">

View File

@@ -228,9 +228,11 @@ Route::group(
Route::get('expense', ['uses' => 'AccountController@expenseAccounts', 'as' => 'expense']); Route::get('expense', ['uses' => 'AccountController@expenseAccounts', 'as' => 'expense']);
Route::get('revenue', ['uses' => 'AccountController@revenueAccounts', 'as' => 'revenue']); Route::get('revenue', ['uses' => 'AccountController@revenueAccounts', 'as' => 'revenue']);
Route::get('report/{accountList}/{start_date}/{end_date}', ['uses' => 'AccountController@report', 'as' => 'report']); Route::get('report/{accountList}/{start_date}/{end_date}', ['uses' => 'AccountController@report', 'as' => 'report']);
Route::get('all/{account}', ['uses' => 'AccountController@period', 'as' => 'all']); // TODO
Route::get('single/{account}', ['uses' => 'AccountController@single', 'as' => 'single']); Route::get('single/{account}', ['uses' => 'AccountController@single', 'as' => 'single']);
Route::get('period/{account}/{date}', ['uses' => 'AccountController@period', 'as' => 'period']); 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('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-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']); Route::get('expense-budget/{account}/{start_date}/{end_date}', ['uses' => 'AccountController@expenseBudget', 'as' => 'expense-budget']);
@@ -307,8 +309,8 @@ Route::group(
* Chart\PiggyBank Controller * Chart\PiggyBank Controller
*/ */
Route::group( Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/piggy-bank','as'=> 'chart.piggy-bank.'], function () { ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/piggy-bank', 'as' => 'chart.piggy-bank.'], function () {
Route::get('{piggyBank}', ['uses' => 'PiggyBankController@history','as' => 'history']); Route::get('{piggyBank}', ['uses' => 'PiggyBankController@history', 'as' => 'history']);
} }
); );
@@ -593,9 +595,11 @@ Route::group(
*/ */
Route::group( Route::group(
['middleware' => 'user-full-auth', 'prefix' => 'transactions', 'as' => 'transactions.'], function () { ['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}', ['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']); 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']); 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::get('show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'show']);
Route::post('reorder', ['uses' => 'TransactionController@reorder', 'as' => 'reorder']); Route::post('reorder', ['uses' => 'TransactionController@reorder', 'as' => 'reorder']);
} }

View File

@@ -30,58 +30,81 @@ class MassControllerTest extends TestCase
} }
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::massDelete * @covers \FireflyIII\Http\Controllers\Transaction\MassController::delete
* Implement testMassDelete().
*/ */
public function testMassDelete() public function testDelete()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('transactions.mass.delete', [561, 562]));
'This test has not been implemented yet.' $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 * @covers \FireflyIII\Http\Controllers\Transaction\MassController::destroy
* Implement testMassDestroy().
*/ */
public function testMassDestroy() public function testDestroy()
{ {
// Remove the following lines when you implement this test. $this->session(['transactions.mass-delete.url' => 'http://localhost']);
$this->markTestIncomplete(
'This test has not been implemented yet.' $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 * @covers \FireflyIII\Http\Controllers\Transaction\MassController::edit
* Implement testMassEdit().
*/ */
public function testMassEdit() public function testEdit()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('transactions.mass.delete', [132, 113]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('Edit a number of transactions');
// has bread crumb
$this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\MassController::massUpdate * @covers \FireflyIII\Http\Controllers\Transaction\MassController::update
* Implement testMassUpdate().
*/ */
public function testMassUpdate() public function testUpdate()
{ {
// Remove the following lines when you implement this test.
$this->markTestIncomplete( $this->session(['transactions.mass-edit.url' => 'http://localhost']);
'This test has not been implemented yet.'
); $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');
} }
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
} }

View File

@@ -11,6 +11,8 @@
namespace Transaction; namespace Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use TestCase; use TestCase;
/** /**
@@ -31,81 +33,110 @@ class SingleControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create
* Implement testCreate().
*/ */
public function testCreate() public function testCreate()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('transactions.create', ['withdrawal']));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); // has bread crumb
$this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::delete * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::delete
* Implement testDelete().
*/ */
public function testDelete() public function testDelete()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('transactions.delete', [12]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); // has bread crumb
$this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::destroy * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::destroy
* Implement testDestroy().
*/ */
public function testDestroy() public function testDestroy()
{ {
// Remove the following lines when you implement this test. $this->session(['transactions.delete.url' => 'http://localhost']);
$this->markTestIncomplete( $this->be($this->user());
'This test has not been implemented yet.'
); $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 * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
* Implement testEdit().
*/ */
public function testEdit() public function testEdit()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('transactions.edit', [13]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); // has bread crumb
$this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
* Implement testStore().
*/ */
public function testStore() public function testStore()
{ {
// Remove the following lines when you implement this test. $this->session(['transactions.create.url' => 'http://localhost']);
$this->markTestIncomplete( $this->be($this->user());
'This test has not been implemented yet.'
); $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 * @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update
* Implement testUpdate().
*/ */
public function testUpdate() public function testUpdate()
{ {
// Remove the following lines when you implement this test. $this->session(['transactions.edit.url' => 'http://localhost']);
$this->markTestIncomplete( $this->be($this->user());
'This test has not been implemented yet.' $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()
{
}
} }