mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 15:18:05 +00:00
Finished testing user controller
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user