mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 23:50:09 +00:00
Some more fixes and tests.
This commit is contained in:
@@ -6,8 +6,118 @@ class UserControllerTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
// mock:
|
||||
View::shouldReceive('make')->with('user.login');
|
||||
|
||||
// call
|
||||
$this->call('GET', '/login');
|
||||
|
||||
// test
|
||||
}
|
||||
|
||||
public function testPostLogin()
|
||||
{
|
||||
// data:
|
||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx', 'remember_me' => '1'];
|
||||
|
||||
// mock
|
||||
Auth::shouldReceive('attempt')->once()->andReturn(true);
|
||||
|
||||
// test
|
||||
$this->call('POST', '/login', $data);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
|
||||
public function testPostFalseLogin()
|
||||
{
|
||||
// data
|
||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx', 'remember_me' => '1'];
|
||||
|
||||
// mock
|
||||
Auth::shouldReceive('attempt')->once()->andReturn(false);
|
||||
View::shouldReceive('make')->with('user.login')->once();
|
||||
|
||||
// test
|
||||
$this->call('POST', '/login', $data);
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function testRegister()
|
||||
{
|
||||
// no mock for config! :(
|
||||
Config::set('auth.allow_register', true);
|
||||
// test
|
||||
$this->call('GET', '/register');
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
*/
|
||||
public function testRegisterNotAllowed()
|
||||
{
|
||||
// no mock for config! :(
|
||||
Config::set('auth.allow_register', false);
|
||||
// test
|
||||
$this->call('GET', '/register');
|
||||
$this->assertResponseStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and verify:
|
||||
*/
|
||||
public function testPostRegisterAllowed()
|
||||
{
|
||||
// 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(new User);
|
||||
$email->shouldReceive('sendVerificationMail')->once()->andReturn(true);
|
||||
// data:
|
||||
$data = [
|
||||
'email' => 'bla@bla'
|
||||
];
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('POST', '/register', $data);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Verification pending")'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and NO verify:
|
||||
*/
|
||||
public function testPostRegisterNoVerifyAllowed()
|
||||
{
|
||||
// no mock for config! :(
|
||||
Config::set('auth.verify_mail', false);
|
||||
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(new User);
|
||||
$email->shouldReceive('sendPasswordMail')->once()->andReturn(true);
|
||||
// data:
|
||||
$data = [
|
||||
'email' => 'bla@bla'
|
||||
];
|
||||
|
||||
// test
|
||||
$crawler = $this->client->request('POST', '/register', $data);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertCount(1, $crawler->filter('h1:contains("Registered!")'));
|
||||
|
||||
$this->mock = $this->mock('Firefly\Storage\User\UserRepositoryInterface');
|
||||
}
|
||||
|
||||
public function mock($class)
|
||||
@@ -19,28 +129,25 @@ class UserControllerTest extends TestCase
|
||||
return $mock;
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
/**
|
||||
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
*/
|
||||
public function testPostRegisterNotAllowed()
|
||||
{
|
||||
View::shouldReceive('make')->with('user.login');
|
||||
$this->call('GET', '/login');
|
||||
}
|
||||
// no mock for config! :(
|
||||
Config::set('auth.verify_mail', true);
|
||||
Config::set('auth.verify_reset', true);
|
||||
Config::set('auth.allow_register', false);
|
||||
|
||||
public function testPostLogin()
|
||||
{
|
||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx','remember_me' => '1'];
|
||||
Auth::shouldReceive('attempt')->once()->andReturn(true);
|
||||
$this->call('POST', '/login', $data);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertRedirectedToRoute('index');
|
||||
}
|
||||
// mock repository:
|
||||
$data = [
|
||||
'email' => 'bla@bla'
|
||||
];
|
||||
|
||||
// test
|
||||
$this->call('POST', '/register', $data);
|
||||
$this->assertResponseStatus(404);
|
||||
|
||||
public function testPostFalseLogin()
|
||||
{
|
||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx','remember_me' => '1'];
|
||||
Auth::shouldReceive('attempt')->once()->andReturn(false);
|
||||
View::shouldReceive('make')->with('user.login')->once();
|
||||
$this->call('POST', '/login', $data);
|
||||
$this->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
|
||||
Reference in New Issue
Block a user