Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New tests.
James Cole5a57398f8125
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.phpindex 7239ba309a..d1feb427eb 100644--- a/app/Http/Controllers/PiggyBankController.php+++ b/app/Http/Controllers/PiggyBankController.php@@ -24,6 +24,7 @@ use Illuminate\Support\Collection;use Input;use Log;use Preferences;+use Response;use Session;use Steam;use URL;@@ -243,6 +244,8 @@ class PiggyBankController extends Controller/*** @param PiggyBankRepositoryInterface $repository+ *+ * @return \Illuminate\Http\JsonResponse*/public function order(PiggyBankRepositoryInterface $repository){@@ -257,6 +260,7 @@ class PiggyBankController extends Controller$repository->setOrder(intval($id), ($order + 1));}}+ return Response::json(['result' => 'ok']);}/**diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.phpindex e8ddd70eb3..a3654bb031 100644--- a/app/Http/Controllers/PreferencesController.php+++ b/app/Http/Controllers/PreferencesController.php@@ -150,7 +150,7 @@ class PreferencesController extends Controller// custom fiscal year$customFiscalYear = intval($request->get('customFiscalYear')) === 1;- $fiscalYearStart = date('m-d', strtotime($request->get('fiscalYearStart')));+ $fiscalYearStart = date('m-d', strtotime(strval($request->get('fiscalYearStart'))));Preferences::set('customFiscalYear', $customFiscalYear);Preferences::set('fiscalYearStart', $fiscalYearStart);diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.phpindex 8f8fbc6b07..3399c84644 100644--- a/app/Http/Controllers/ProfileController.php+++ b/app/Http/Controllers/ProfileController.php@@ -83,11 +83,12 @@ class ProfileController extends Controller}/**- * @param ProfileFormRequest $request+ * @param ProfileFormRequest $request+ * @param UserRepositoryInterface $repository*- * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector*/- public function postChangePassword(ProfileFormRequest $request)+ public function postChangePassword(ProfileFormRequest $request, UserRepositoryInterface $repository){// old, new1, new2if (!Hash::check($request->get('current_password'), auth()->user()->password)) {@@ -103,9 +104,7 @@ class ProfileController extends Controller}// update the user with the new password.- auth()->user()->password = bcrypt($request->get('new_password'));- auth()->user()->save();-+ $repository->changePassword(auth()->user(), $request->get('new_password'));Session::flash('success', strval(trans('firefly.password_changed')));return redirect(route('profile.index'));diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankFormRequest.phpindex 69c11d70b2..684ad148d9 100644--- a/app/Http/Requests/PiggyBankFormRequest.php+++ b/app/Http/Requests/PiggyBankFormRequest.php@@ -42,8 +42,8 @@ class PiggyBankFormRequest extends Request'startdate' => new Carbon,'account_id' => intval($this->get('account_id')),'targetamount' => round($this->get('targetamount'), 2),- 'targetdate' => strlen($this->get('targetdate')) > 0 ? new Carbon($this->get('targetdate')) : null,- 'note' => trim($this->get('note')),+ 'targetdate' => strlen(strval($this->get('targetdate'))) > 0 ? new Carbon($this->get('targetdate')) : null,+ 'note' => trim(strval($this->get('note'))),];}@@ -64,7 +64,7 @@ class PiggyBankFormRequest extends Request'name' => $nameRule,'account_id' => 'required|belongsToUser:accounts','targetamount' => 'required|min:0.01',- 'amount_currency_id_targetamount' => 'exists:transaction_currencies,id',+ 'amount_currency_id_targetamount' => 'required|exists:transaction_currencies,id','startdate' => 'date','targetdate' => $targetDateRule,'order' => 'integer|min:1',diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.phpindex 5b99d097ee..7f35b095b7 100644--- a/app/Http/breadcrumbs.php+++ b/app/Http/breadcrumbs.php@@ -413,7 +413,22 @@ Breadcrumbs::register('piggy-banks.show', function (BreadCrumbGenerator $breadcrumbs, PiggyBank $piggyBank) {$breadcrumbs->parent('piggy-banks.index');$breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id]));+}+);+Breadcrumbs::register(+ 'piggy-banks.add-money-mobile', function (BreadCrumbGenerator $breadcrumbs, PiggyBank $piggyBank) {+ $breadcrumbs->parent('piggy-banks.show', $piggyBank);+ $breadcrumbs->push(trans('firefly.add_money_to_piggy', ['name' => $piggyBank->name]), route('piggy-banks.add-money-mobile', [$piggyBank->id]));+}+);++Breadcrumbs::register(+ 'piggy-banks.remove-money-mobile', function (BreadCrumbGenerator $breadcrumbs, PiggyBank $piggyBank) {+ $breadcrumbs->parent('piggy-banks.show', $piggyBank);+ $breadcrumbs->push(+ trans('firefly.remove_money_from_piggy_title', ['name' => $piggyBank->name]), route('piggy-banks.remove-money-mobile', [$piggyBank->id])+ );});@@ -513,6 +528,16 @@ Breadcrumbs::register(});+/**+ * New user Controller+ */+Breadcrumbs::register(+ 'new-user.index', function (BreadCrumbGenerator $breadcrumbs) {+ $breadcrumbs->parent('home');+ $breadcrumbs->push(trans('firefly.getting_started'), route('new-user.index'));+}+);+/*** Rules*/diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.phpindex f33171c1e4..1f206f89a7 100644--- a/app/Repositories/User/UserRepository.php+++ b/app/Repositories/User/UserRepository.php@@ -148,4 +148,16 @@ class UserRepository implements UserRepositoryInterfacereturn $return;}++ /**+ * @param User $user+ * @param string $password+ *+ * @return mixed+ */+ public function changePassword(User $user, string $password)+ {+ $user->password = bcrypt($password);+ $user->save();+ }}diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.phpindex 66283a9ba0..93e34a7a14 100644--- a/app/Repositories/User/UserRepositoryInterface.php+++ b/app/Repositories/User/UserRepositoryInterface.php@@ -41,6 +41,14 @@ interface UserRepositoryInterface*/public function attachRole(User $user, string $role): bool;+ /**+ * @param User $user+ * @param string $password+ *+ * @return mixed+ */+ public function changePassword(User $user, string $password);+/*** Returns a count of all users.*diff --git a/resources/views/piggy-banks/add-mobile.twig b/resources/views/piggy-banks/add-mobile.twigindex 29460b3e47..1212641bf4 100644--- a/resources/views/piggy-banks/add-mobile.twig+++ b/resources/views/piggy-banks/add-mobile.twig@@ -1,7 +1,7 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, piggyBank) }}{% endblock %}{% block content %}diff --git a/resources/views/piggy-banks/remove-mobile.twig b/resources/views/piggy-banks/remove-mobile.twigindex 9b1574983a..d70ade101e 100644--- a/resources/views/piggy-banks/remove-mobile.twig+++ b/resources/views/piggy-banks/remove-mobile.twig@@ -1,6 +1,6 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, piggyBank) }}{% endblock %}{% block content %}diff --git a/routes/web.php b/routes/web.phpindex 4573eb6696..515573629e 100755--- a/routes/web.php+++ b/routes/web.php@@ -457,6 +457,7 @@ Route::group(Route::get('', ['uses' => 'ProfileController@index', 'as' => 'index']);Route::get('change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'change-password']);Route::get('delete-account', ['uses' => 'ProfileController@deleteAccount', 'as' => 'delete-account']);+Route::post('delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account.post']);Route::post('change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password.post']);}diff --git a/tests/TestCase.php b/tests/TestCase.phpindex b4003cb46a..f0aed4568b 100755--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -94,6 +94,15 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase}+ /**+ * @return User+ */+ public function emptyUser()+ {+ $user = User::find(2);++ return $user;+ }/*** @return Userdiff --git a/tests/acceptance/Controllers/NewUserControllerTest.php b/tests/acceptance/Controllers/NewUserControllerTest.phpindex dd51e1fa8c..7c98ec5583 100644--- a/tests/acceptance/Controllers/NewUserControllerTest.php+++ b/tests/acceptance/Controllers/NewUserControllerTest.php@@ -31,10 +31,10 @@ class NewUserControllerTest extends TestCase*/public function testIndex(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->emptyUser());+ $this->call('get', route('new-user.index'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/**@@ -42,10 +42,14 @@ class NewUserControllerTest extends TestCase*/public function testSubmit(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $data = [+ 'bank_name' => 'New bank',+ 'bank_balance' => 100,+ ];+ $this->be($this->emptyUser());+ $this->call('post', route('new-user.submit'), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');}}diff --git a/tests/acceptance/Controllers/PiggyBankControllerTest.php b/tests/acceptance/Controllers/PiggyBankControllerTest.phpindex 9ad18fb30c..66e2dce67c 100644--- a/tests/acceptance/Controllers/PiggyBankControllerTest.php+++ b/tests/acceptance/Controllers/PiggyBankControllerTest.php@@ -8,6 +8,7 @@** See the LICENSE file for details.*/+use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;/**@@ -28,182 +29,191 @@ class PiggyBankControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::add- * Implement testAdd().*/public function testAdd(){- // 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('piggy-banks.add', [1]));+ $this->assertResponseStatus(200);}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::addMobile- * Implement testAddMobile().*/public function testAddMobile(){- // 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('piggy-banks.add-money-mobile', [1]));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.create'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.delete', [1]));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::destroy- * Implement testDestroy().*/public function testDestroy(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $repository = $this->mock(PiggyBankRepositoryInterface::class);+ $repository->shouldReceive('destroy')->andReturn(true);++ $this->session(['piggy-banks.delete.url' => 'http://localhost']);+ $this->be($this->user());+ $this->call('post', route('piggy-banks.destroy', [2]));+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');+ $this->assertRedirectedToRoute('index');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.edit', [1]));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::index- * Implement testIndex().*/public function testIndex(){- // 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('piggy-banks.index'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::order- * Implement testOrder().*/public function testOrder(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $this->be($this->user());+ $this->call('post', route('piggy-banks.order', [1, 2]));+ $this->assertResponseStatus(200);}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::postAdd- * Implement testPostAdd().*/public function testPostAdd(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $data = ['amount' => 1];+ $this->be($this->user());+ $this->call('post', route('piggy-banks.add', [1]), $data);+ $this->assertResponseStatus(302);+ $this->assertRedirectedToRoute('piggy-banks.index');+ $this->assertSessionHas('success');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::postRemove- * Implement testPostRemove().*/public function testPostRemove(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $data = ['amount' => 1];+ $this->be($this->user());+ $this->call('post', route('piggy-banks.remove', [1]), $data);+ $this->assertResponseStatus(302);+ $this->assertRedirectedToRoute('piggy-banks.index');+ $this->assertSessionHas('success');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::remove- * Implement testRemove().*/public function testRemove(){- // 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('piggy-banks.remove', [1]));+ $this->assertResponseStatus(200);}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::removeMobile- * Implement testRemoveMobile().*/public function testRemoveMobile(){- // 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('piggy-banks.remove-money-mobile', [1]));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::show- * Implement testShow().*/public function testShow(){- // 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('piggy-banks.show', [1]));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::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(['piggy-banks.create.url' => 'http://localhost']);+ $data = [+ 'name' => 'Piggy ' . rand(999, 10000),+ 'targetamount' => 100,+ 'account_id' => 2,+ 'amount_currency_id_targetamount' => 1,++ ];+ $this->be($this->user());+ $this->call('post', route('piggy-banks.store'), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');+ $this->assertRedirectedToRoute('index');}/*** @covers \FireflyIII\Http\Controllers\PiggyBankController::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(['piggy-banks.edit.url' => 'http://localhost']);+ $data = [+ 'name' => 'Updated Piggy ' . rand(999, 10000),+ 'targetamount' => 100,+ 'account_id' => 2,+ 'amount_currency_id_targetamount' => 1,++ ];+ $this->be($this->user());+ $this->call('post', route('piggy-banks.update', [3]), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');+ $this->assertRedirectedToRoute('index');}}diff --git a/tests/acceptance/Controllers/PreferencesControllerTest.php b/tests/acceptance/Controllers/PreferencesControllerTest.phpindex 25c39e2a3f..3cd9698735 100644--- a/tests/acceptance/Controllers/PreferencesControllerTest.php+++ b/tests/acceptance/Controllers/PreferencesControllerTest.php@@ -28,61 +28,51 @@ class PreferencesControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\PreferencesController::code- * Implement testCode().*/public function testCode(){- // 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('preferences.code'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PreferencesController::deleteCode- * Implement testDeleteCode().*/public function testDeleteCode(){- // 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('preferences.delete-code'));+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');+ $this->assertSessionHas('info');+ $this->assertRedirectedToRoute('preferences.index');}/*** @covers \FireflyIII\Http\Controllers\PreferencesController::index- * Implement testIndex().*/public function testIndex(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );- }-- /**- * @covers \FireflyIII\Http\Controllers\PreferencesController::postCode- * Implement testPostCode().- */- public function testPostCode()- {- // 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('preferences.index'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex- * Implement testPostIndex().*/public function testPostIndex(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $data = [+ 'fiscalYearStart' => '2016-01-01'+ ];+ $this->be($this->user());+ $this->call('post', route('preferences.update'), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');+ $this->assertRedirectedToRoute('preferences.index');}}diff --git a/tests/acceptance/Controllers/ProfileControllerTest.php b/tests/acceptance/Controllers/ProfileControllerTest.phpindex c9d53bca71..f11a4556a0 100644--- a/tests/acceptance/Controllers/ProfileControllerTest.php+++ b/tests/acceptance/Controllers/ProfileControllerTest.php@@ -8,6 +8,7 @@** See the LICENSE file for details.*/+use FireflyIII\Repositories\User\UserRepositoryInterface;/**@@ -28,61 +29,69 @@ class ProfileControllerTest extends TestCase/*** @covers \FireflyIII\Http\Controllers\ProfileController::changePassword- * Implement testChangePassword().*/public function testChangePassword(){- // 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('profile.change-password'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\ProfileController::deleteAccount- * Implement testDeleteAccount().*/public function testDeleteAccount(){- // 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('profile.delete-account'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\ProfileController::index- * Implement testIndex().*/public function testIndex(){- // 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('profile.index'));+ $this->assertResponseStatus(200);+ $this->see('<ol class="breadcrumb">');}/*** @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword- * Implement testPostChangePassword().*/public function testPostChangePassword(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $repository = $this->mock(UserRepositoryInterface::class);+ $repository->shouldReceive('changePassword');++ $data = [+ 'current_password' => 'james',+ 'new_password' => 'james2',+ 'new_password_confirmation' => 'james2',+ ];+ $this->be($this->user());+ $this->call('post', route('profile.change-password.post'), $data);+ $this->assertResponseStatus(302);+ $this->assertSessionHas('success');}/*** @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount- * Implement testPostDeleteAccount().*/public function testPostDeleteAccount(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete(- 'This test has not been implemented yet.'- );+ $repository = $this->mock(UserRepositoryInterface::class);+ $repository->shouldReceive('destroy');+ $data = [+ 'password' => 'james',+ ];+ $this->be($this->user());+ $this->call('post', route('profile.delete-account.post'), $data);+ $this->assertResponseStatus(302);+ $this->assertRedirectedToRoute('index');}}