mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Also covered ProfileController.
This commit is contained in:
parent
516fe54bf0
commit
924ec29eaf
@ -1,8 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Storage\User\UserRepositoryInterface as URI;
|
||||
|
||||
class ProfileController extends BaseController
|
||||
{
|
||||
|
||||
public function __construct(URI $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return View::make('profile.index');
|
||||
@ -37,11 +43,8 @@ class ProfileController extends BaseController
|
||||
}
|
||||
|
||||
// update the user with the new password.
|
||||
$password = Hash::make(Input::get('new1'));
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
Auth::user()->password = $password;
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
Auth::user()->save();
|
||||
$this->user->updatePassword(Auth::user(),Input::get('new1'));
|
||||
|
||||
Session::flash('success', 'Password changed!');
|
||||
return Redirect::route('profile');
|
||||
}
|
||||
|
@ -51,4 +51,14 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return \User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function updatePassword(\User $user, $password)
|
||||
{
|
||||
$password = \Hash::make($password);
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$user->password = $password;
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$user->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -15,5 +15,7 @@ interface UserRepositoryInterface
|
||||
|
||||
public function findByEmail($email);
|
||||
|
||||
public function updatePassword(\User $user,$password);
|
||||
|
||||
|
||||
}
|
@ -1,19 +1,29 @@
|
||||
<?php
|
||||
|
||||
class TestCase extends Illuminate\Foundation\Testing\TestCase {
|
||||
class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$unitTesting = true;
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$unitTesting = true;
|
||||
|
||||
$testEnvironment = 'testing';
|
||||
$testEnvironment = 'testing';
|
||||
|
||||
return require __DIR__.'/../../bootstrap/start.php';
|
||||
}
|
||||
return require __DIR__ . '/../../bootstrap/start.php';
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
{
|
||||
$mock = Mockery::mock($class);
|
||||
|
||||
$this->app->instance($class, $mock);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
}
|
||||
|
141
app/tests/controllers/ProfileControllerTest.php
Normal file
141
app/tests/controllers/ProfileControllerTest.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
class ProfileControllerTest extends TestCase
|
||||
{
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
// mock:
|
||||
View::shouldReceive('make')->with('profile.index');
|
||||
|
||||
// call
|
||||
$this->call('GET', '/profile');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testChangePassword()
|
||||
{
|
||||
// mock:
|
||||
View::shouldReceive('make')->with('profile.change-password');
|
||||
|
||||
// call
|
||||
$this->call('GET', '/profile/change-password');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testOldNoMatch()
|
||||
{
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Auth::shouldReceive('user')->andReturn(new User);
|
||||
Hash::shouldReceive('check')->andReturn(false);
|
||||
|
||||
$data = [
|
||||
'old' => 'lala',
|
||||
'new1' => 'a',
|
||||
'new2' => 'a',
|
||||
];
|
||||
|
||||
|
||||
// call
|
||||
$this->call('POST', '/profile/change-password', $data);
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
$this->assertSessionHas('error', 'Invalid current password!');
|
||||
}
|
||||
|
||||
public function testNewEmpty()
|
||||
{
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Auth::shouldReceive('user')->andReturn(new User);
|
||||
Hash::shouldReceive('check')->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'old' => 'lala',
|
||||
'new1' => '',
|
||||
'new2' => '',
|
||||
];
|
||||
|
||||
|
||||
// call
|
||||
$this->call('POST', '/profile/change-password', $data);
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
$this->assertSessionHas('error', 'Do fill in a password!');
|
||||
}
|
||||
|
||||
public function testOldSame()
|
||||
{
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Auth::shouldReceive('user')->andReturn(new User);
|
||||
Hash::shouldReceive('check')->andReturn(true);
|
||||
Hash::shouldReceive('make')->andReturn('blala');
|
||||
|
||||
$data = [
|
||||
'old' => 'a',
|
||||
'new1' => 'a',
|
||||
'new2' => 'a',
|
||||
];
|
||||
|
||||
|
||||
// call
|
||||
$this->call('POST', '/profile/change-password', $data);
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
$this->assertSessionHas('error', 'The idea is to change your password.');
|
||||
}
|
||||
|
||||
public function testNewNoMatch()
|
||||
{
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Auth::shouldReceive('user')->andReturn(new User);
|
||||
Hash::shouldReceive('check')->andReturn(true);
|
||||
Hash::shouldReceive('make')->andReturn('blala');
|
||||
|
||||
$data = [
|
||||
'old' => 'b',
|
||||
'new1' => 'c',
|
||||
'new2' => 'd',
|
||||
];
|
||||
|
||||
|
||||
// call
|
||||
$this->call('POST', '/profile/change-password', $data);
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
$this->assertSessionHas('error', 'New passwords do not match!');
|
||||
}
|
||||
|
||||
public function testPostChangePassword()
|
||||
{
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
Auth::shouldReceive('user')->andReturn(new User);
|
||||
Hash::shouldReceive('check')->andReturn(true);
|
||||
Hash::shouldReceive('make')->andReturn('blala');
|
||||
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$repository->shouldReceive('updatePassword')->once()->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'old' => 'b',
|
||||
'new1' => 'c',
|
||||
'new2' => 'c',
|
||||
];
|
||||
|
||||
|
||||
// call
|
||||
$this->call('POST', '/profile/change-password', $data);
|
||||
|
||||
// test
|
||||
$this->assertRedirectedToRoute('profile');
|
||||
$this->assertSessionHas('success', 'Password changed!');
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,7 @@ class UserControllerTest extends TestCase
|
||||
$this->call('GET', '/login');
|
||||
|
||||
// test
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostLogin()
|
||||
@ -94,14 +95,7 @@ class UserControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
{
|
||||
$mock = Mockery::mock($class);
|
||||
|
||||
$this->app->instance($class, $mock);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and verify FAILED:
|
||||
|
Loading…
Reference in New Issue
Block a user