mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-23 23:13:18 -06:00
Finished testing user controller
This commit is contained in:
parent
614c556c96
commit
516fe54bf0
@ -75,9 +75,11 @@ class UserController extends BaseController
|
||||
if ($user) {
|
||||
if (Config::get('auth.verify_reset') === true) {
|
||||
$this->email->sendResetVerification($user);
|
||||
return View::make('user.verification-pending');
|
||||
}
|
||||
if (Config::get('auth.verify_reset') === false) {
|
||||
$this->email->sendPasswordMail($user);
|
||||
return View::make('user.registered');
|
||||
}
|
||||
}
|
||||
Session::flash('error', 'No good!');
|
||||
|
@ -94,6 +94,35 @@ class UserControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
{
|
||||
$mock = Mockery::mock($class);
|
||||
|
||||
$this->app->instance($class, $mock);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and verify FAILED:
|
||||
*/
|
||||
public function testPostRegisterAllowedFailed()
|
||||
{
|
||||
// no mock for config! :(
|
||||
Config::set('auth.verify_mail', true);
|
||||
Config::set('auth.allow_register', true);
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
|
||||
$repository->shouldReceive('register')->once()->andReturn(null);
|
||||
// test
|
||||
$crawler = $this->client->request('POST', '/register');
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Register")'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and NO verify:
|
||||
*/
|
||||
@ -116,17 +145,59 @@ class UserControllerTest extends TestCase
|
||||
// test
|
||||
$crawler = $this->client->request('POST', '/register', $data);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Registered!")'));
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
|
||||
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
public function testLogout()
|
||||
{
|
||||
$mock = Mockery::mock($class);
|
||||
|
||||
$this->app->instance($class, $mock);
|
||||
Auth::shouldReceive('logout');
|
||||
|
||||
return $mock;
|
||||
$this->call('GET', '/logout');
|
||||
|
||||
}
|
||||
|
||||
public function testRemindme()
|
||||
{
|
||||
|
||||
$this->call('GET', '/remindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRemindmeWithVerification()
|
||||
{
|
||||
Config::set('auth.verify_reset', true);
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
|
||||
$repository->shouldReceive('findByEmail')->once()->andReturn(new User);
|
||||
$email->shouldReceive('sendResetVerification')->once()->andReturn(true);
|
||||
|
||||
$this->call('POST', '/remindme');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testPostRemindmeWithoutVerification()
|
||||
{
|
||||
Config::set('auth.verify_reset', false);
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
|
||||
$repository->shouldReceive('findByEmail')->once()->andReturn(new User);
|
||||
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
|
||||
|
||||
$this->call('POST', '/remindme');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostRemindmeFails()
|
||||
{
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$repository->shouldReceive('findByEmail')->once()->andReturn(null);
|
||||
|
||||
$this->call('POST', '/remindme');
|
||||
$this->assertResponseOk();
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,6 +221,62 @@ class UserControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testVerification()
|
||||
{
|
||||
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
|
||||
|
||||
$repository->shouldReceive('findByVerification')->once()->andReturn(new User);
|
||||
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('GET', '/verify/blabla');
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
|
||||
|
||||
}
|
||||
|
||||
public function testVerificationFails()
|
||||
{
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$repository->shouldReceive('findByVerification')->once()->andReturn(null);
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('GET', '/verify/blabla');
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Error")'));
|
||||
$this->assertViewHas('message');
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$email = $this->mock('Firefly\Helper\Email\EmailHelper');
|
||||
|
||||
$repository->shouldReceive('findByReset')->once()->andReturn(new User);
|
||||
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('GET', '/reset/blabla');
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Password sent")'));
|
||||
|
||||
}
|
||||
|
||||
public function testResetFails()
|
||||
{
|
||||
$repository = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
$repository->shouldReceive('findByReset')->once()->andReturn(null);
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('GET', '/reset/blabla');
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Error")'));
|
||||
$this->assertViewHas('message');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
|
@ -3,7 +3,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly<br/>
|
||||
<small>Registered!</small>
|
||||
<small>Password sent!</small>
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user