New tests.

This commit is contained in:
James Cole
2016-12-18 17:54:11 +01:00
parent 8666197e05
commit 5a57398f81
15 changed files with 223 additions and 152 deletions

View File

@@ -24,6 +24,7 @@ use Illuminate\Support\Collection;
use Input; use Input;
use Log; use Log;
use Preferences; use Preferences;
use Response;
use Session; use Session;
use Steam; use Steam;
use URL; use URL;
@@ -243,6 +244,8 @@ class PiggyBankController extends Controller
/** /**
* @param PiggyBankRepositoryInterface $repository * @param PiggyBankRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function order(PiggyBankRepositoryInterface $repository) public function order(PiggyBankRepositoryInterface $repository)
{ {
@@ -257,6 +260,7 @@ class PiggyBankController extends Controller
$repository->setOrder(intval($id), ($order + 1)); $repository->setOrder(intval($id), ($order + 1));
} }
} }
return Response::json(['result' => 'ok']);
} }
/** /**

View File

@@ -150,7 +150,7 @@ class PreferencesController extends Controller
// custom fiscal year // custom fiscal year
$customFiscalYear = intval($request->get('customFiscalYear')) === 1; $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('customFiscalYear', $customFiscalYear);
Preferences::set('fiscalYearStart', $fiscalYearStart); Preferences::set('fiscalYearStart', $fiscalYearStart);

View File

@@ -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, new2 // old, new1, new2
if (!Hash::check($request->get('current_password'), auth()->user()->password)) { if (!Hash::check($request->get('current_password'), auth()->user()->password)) {
@@ -103,9 +104,7 @@ class ProfileController extends Controller
} }
// update the user with the new password. // update the user with the new password.
auth()->user()->password = bcrypt($request->get('new_password')); $repository->changePassword(auth()->user(), $request->get('new_password'));
auth()->user()->save();
Session::flash('success', strval(trans('firefly.password_changed'))); Session::flash('success', strval(trans('firefly.password_changed')));
return redirect(route('profile.index')); return redirect(route('profile.index'));

View File

@@ -42,8 +42,8 @@ class PiggyBankFormRequest extends Request
'startdate' => new Carbon, 'startdate' => new Carbon,
'account_id' => intval($this->get('account_id')), 'account_id' => intval($this->get('account_id')),
'targetamount' => round($this->get('targetamount'), 2), 'targetamount' => round($this->get('targetamount'), 2),
'targetdate' => strlen($this->get('targetdate')) > 0 ? new Carbon($this->get('targetdate')) : null, 'targetdate' => strlen(strval($this->get('targetdate'))) > 0 ? new Carbon($this->get('targetdate')) : null,
'note' => trim($this->get('note')), 'note' => trim(strval($this->get('note'))),
]; ];
} }
@@ -64,7 +64,7 @@ class PiggyBankFormRequest extends Request
'name' => $nameRule, 'name' => $nameRule,
'account_id' => 'required|belongsToUser:accounts', 'account_id' => 'required|belongsToUser:accounts',
'targetamount' => 'required|min:0.01', 'targetamount' => 'required|min:0.01',
'amount_currency_id_targetamount' => 'exists:transaction_currencies,id', 'amount_currency_id_targetamount' => 'required|exists:transaction_currencies,id',
'startdate' => 'date', 'startdate' => 'date',
'targetdate' => $targetDateRule, 'targetdate' => $targetDateRule,
'order' => 'integer|min:1', 'order' => 'integer|min:1',

View File

@@ -413,7 +413,22 @@ Breadcrumbs::register(
'piggy-banks.show', function (BreadCrumbGenerator $breadcrumbs, PiggyBank $piggyBank) { 'piggy-banks.show', function (BreadCrumbGenerator $breadcrumbs, PiggyBank $piggyBank) {
$breadcrumbs->parent('piggy-banks.index'); $breadcrumbs->parent('piggy-banks.index');
$breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id])); $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 * Rules
*/ */

View File

@@ -148,4 +148,16 @@ class UserRepository implements UserRepositoryInterface
return $return; return $return;
} }
/**
* @param User $user
* @param string $password
*
* @return mixed
*/
public function changePassword(User $user, string $password)
{
$user->password = bcrypt($password);
$user->save();
}
} }

View File

@@ -41,6 +41,14 @@ interface UserRepositoryInterface
*/ */
public function attachRole(User $user, string $role): bool; 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. * Returns a count of all users.
* *

View File

@@ -1,7 +1,7 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, piggyBank) }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View File

@@ -1,6 +1,6 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, piggyBank) }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View File

@@ -457,6 +457,7 @@ Route::group(
Route::get('', ['uses' => 'ProfileController@index', 'as' => 'index']); Route::get('', ['uses' => 'ProfileController@index', 'as' => 'index']);
Route::get('change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'change-password']); Route::get('change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'change-password']);
Route::get('delete-account', ['uses' => 'ProfileController@deleteAccount', 'as' => 'delete-account']); Route::get('delete-account', ['uses' => 'ProfileController@deleteAccount', 'as' => 'delete-account']);
Route::post('delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account.post']); Route::post('delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account.post']);
Route::post('change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password.post']); Route::post('change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password.post']);
} }

View File

@@ -94,6 +94,15 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
} }
/**
* @return User
*/
public function emptyUser()
{
$user = User::find(2);
return $user;
}
/** /**
* @return User * @return User

View File

@@ -31,10 +31,10 @@ class NewUserControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
// Remove the following lines when you implement this test. $this->be($this->emptyUser());
$this->markTestIncomplete( $this->call('get', route('new-user.index'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
@@ -42,10 +42,14 @@ class NewUserControllerTest extends TestCase
*/ */
public function testSubmit() public function testSubmit()
{ {
// Remove the following lines when you implement this test. $data = [
$this->markTestIncomplete( 'bank_name' => 'New bank',
'This test has not been implemented yet.' 'bank_balance' => 100,
); ];
$this->be($this->emptyUser());
$this->call('post', route('new-user.submit'), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
} }
} }

View File

@@ -8,6 +8,7 @@
* *
* See the LICENSE file for details. * 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 * @covers \FireflyIII\Http\Controllers\PiggyBankController::add
* Implement testAdd().
*/ */
public function testAdd() public function testAdd()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.add', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::addMobile * @covers \FireflyIII\Http\Controllers\PiggyBankController::addMobile
* Implement testAddMobile().
*/ */
public function testAddMobile() public function testAddMobile()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.add-money-mobile', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::create * @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.create'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::delete * @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.delete', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::destroy * @covers \FireflyIII\Http\Controllers\PiggyBankController::destroy
* Implement testDestroy().
*/ */
public function testDestroy() public function testDestroy()
{ {
// Remove the following lines when you implement this test. $repository = $this->mock(PiggyBankRepositoryInterface::class);
$this->markTestIncomplete( $repository->shouldReceive('destroy')->andReturn(true);
'This test has not been implemented yet.'
); $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 * @covers \FireflyIII\Http\Controllers\PiggyBankController::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('piggy-banks.edit', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::index * @covers \FireflyIII\Http\Controllers\PiggyBankController::index
* Implement testIndex().
*/ */
public function testIndex() public function testIndex()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.index'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::order * @covers \FireflyIII\Http\Controllers\PiggyBankController::order
* Implement testOrder().
*/ */
public function testOrder() public function testOrder()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('post', route('piggy-banks.order', [1, 2]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::postAdd * @covers \FireflyIII\Http\Controllers\PiggyBankController::postAdd
* Implement testPostAdd().
*/ */
public function testPostAdd() public function testPostAdd()
{ {
// Remove the following lines when you implement this test. $data = ['amount' => 1];
$this->markTestIncomplete( $this->be($this->user());
'This test has not been implemented yet.' $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 * @covers \FireflyIII\Http\Controllers\PiggyBankController::postRemove
* Implement testPostRemove().
*/ */
public function testPostRemove() public function testPostRemove()
{ {
// Remove the following lines when you implement this test. $data = ['amount' => 1];
$this->markTestIncomplete( $this->be($this->user());
'This test has not been implemented yet.' $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 * @covers \FireflyIII\Http\Controllers\PiggyBankController::remove
* Implement testRemove().
*/ */
public function testRemove() public function testRemove()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.remove', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::removeMobile * @covers \FireflyIII\Http\Controllers\PiggyBankController::removeMobile
* Implement testRemoveMobile().
*/ */
public function testRemoveMobile() public function testRemoveMobile()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.remove-money-mobile', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::show * @covers \FireflyIII\Http\Controllers\PiggyBankController::show
* Implement testShow().
*/ */
public function testShow() public function testShow()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('piggy-banks.show', [1]));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PiggyBankController::store * @covers \FireflyIII\Http\Controllers\PiggyBankController::store
* Implement testStore().
*/ */
public function testStore() public function testStore()
{ {
// Remove the following lines when you implement this test. $this->session(['piggy-banks.create.url' => 'http://localhost']);
$this->markTestIncomplete( $data = [
'This test has not been implemented yet.' '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 * @covers \FireflyIII\Http\Controllers\PiggyBankController::update
* Implement testUpdate().
*/ */
public function testUpdate() public function testUpdate()
{ {
// Remove the following lines when you implement this test. $this->session(['piggy-banks.edit.url' => 'http://localhost']);
$this->markTestIncomplete( $data = [
'This test has not been implemented yet.' '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');
} }
} }

View File

@@ -28,61 +28,51 @@ class PreferencesControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\PreferencesController::code * @covers \FireflyIII\Http\Controllers\PreferencesController::code
* Implement testCode().
*/ */
public function testCode() public function testCode()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('preferences.code'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PreferencesController::deleteCode * @covers \FireflyIII\Http\Controllers\PreferencesController::deleteCode
* Implement testDeleteCode().
*/ */
public function testDeleteCode() public function testDeleteCode()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('preferences.delete-code'));
'This test has not been implemented yet.' $this->assertResponseStatus(302);
); $this->assertSessionHas('success');
$this->assertSessionHas('info');
$this->assertRedirectedToRoute('preferences.index');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PreferencesController::index * @covers \FireflyIII\Http\Controllers\PreferencesController::index
* Implement testIndex().
*/ */
public function testIndex() public function testIndex()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('preferences.index'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
}
/**
* @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.'
);
} }
/** /**
* @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex * @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex
* Implement testPostIndex().
*/ */
public function testPostIndex() public function testPostIndex()
{ {
// Remove the following lines when you implement this test. $data = [
$this->markTestIncomplete( 'fiscalYearStart' => '2016-01-01'
'This test has not been implemented yet.' ];
); $this->be($this->user());
$this->call('post', route('preferences.update'), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('preferences.index');
} }
} }

View File

@@ -8,6 +8,7 @@
* *
* See the LICENSE file for details. * 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 * @covers \FireflyIII\Http\Controllers\ProfileController::changePassword
* Implement testChangePassword().
*/ */
public function testChangePassword() public function testChangePassword()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('profile.change-password'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\ProfileController::deleteAccount * @covers \FireflyIII\Http\Controllers\ProfileController::deleteAccount
* Implement testDeleteAccount().
*/ */
public function testDeleteAccount() public function testDeleteAccount()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('profile.delete-account'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\ProfileController::index * @covers \FireflyIII\Http\Controllers\ProfileController::index
* Implement testIndex().
*/ */
public function testIndex() public function testIndex()
{ {
// Remove the following lines when you implement this test. $this->be($this->user());
$this->markTestIncomplete( $this->call('get', route('profile.index'));
'This test has not been implemented yet.' $this->assertResponseStatus(200);
); $this->see('<ol class="breadcrumb">');
} }
/** /**
* @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword * @covers \FireflyIII\Http\Controllers\ProfileController::postChangePassword
* Implement testPostChangePassword().
*/ */
public function testPostChangePassword() public function testPostChangePassword()
{ {
// Remove the following lines when you implement this test. $repository = $this->mock(UserRepositoryInterface::class);
$this->markTestIncomplete( $repository->shouldReceive('changePassword');
'This test has not been implemented yet.'
); $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 * @covers \FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
* Implement testPostDeleteAccount().
*/ */
public function testPostDeleteAccount() public function testPostDeleteAccount()
{ {
// Remove the following lines when you implement this test. $repository = $this->mock(UserRepositoryInterface::class);
$this->markTestIncomplete( $repository->shouldReceive('destroy');
'This test has not been implemented yet.' $data = [
); 'password' => 'james',
];
$this->be($this->user());
$this->call('post', route('profile.delete-account.post'), $data);
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('index');
} }
} }