mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Some more fixes and tests.
This commit is contained in:
8
app/config/testing/auth.php
Normal file
8
app/config/testing/auth.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'verify_mail' => true,
|
||||||
|
'verify_reset' => true,
|
||||||
|
'allow_register' => true
|
||||||
|
|
||||||
|
];
|
@@ -12,7 +12,7 @@ class EloquentUserRepository implements UserRepositoryInterface
|
|||||||
public function register($array)
|
public function register($array)
|
||||||
{
|
{
|
||||||
$user = new \User;
|
$user = new \User;
|
||||||
$user->email = $array['emai'];
|
$user->email = isset($array['email']) ? $array['email'] : null;
|
||||||
$user->migrated = 0;
|
$user->migrated = 0;
|
||||||
$user->verification = \Str::random(32);
|
$user->verification = \Str::random(32);
|
||||||
$user->password = \Hash::make(\Str::random(12));
|
$user->password = \Hash::make(\Str::random(12));
|
||||||
|
@@ -20,8 +20,8 @@ class User extends Elegant implements UserInterface, RemindableInterface
|
|||||||
|
|
||||||
public static $rules
|
public static $rules
|
||||||
= [
|
= [
|
||||||
'email' => 'email|unique:users,email',
|
'email' => 'required|email|unique:users,email',
|
||||||
'migrated' => 'numeric|between:0,1',
|
'migrated' => 'required|numeric|between:0,1',
|
||||||
'password' => 'between:60,60',
|
'password' => 'between:60,60',
|
||||||
'verification' => 'between:32,32',
|
'verification' => 'between:32,32',
|
||||||
];
|
];
|
||||||
|
@@ -6,8 +6,118 @@ class UserControllerTest extends TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::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)
|
public function mock($class)
|
||||||
@@ -19,28 +129,25 @@ class UserControllerTest extends TestCase
|
|||||||
return $mock;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLogin()
|
/**
|
||||||
|
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||||
|
*/
|
||||||
|
public function testPostRegisterNotAllowed()
|
||||||
{
|
{
|
||||||
View::shouldReceive('make')->with('user.login');
|
// no mock for config! :(
|
||||||
$this->call('GET', '/login');
|
Config::set('auth.verify_mail', true);
|
||||||
}
|
Config::set('auth.verify_reset', true);
|
||||||
|
Config::set('auth.allow_register', false);
|
||||||
|
|
||||||
public function testPostLogin()
|
// mock repository:
|
||||||
{
|
$data = [
|
||||||
$data = ['email' => 'bla@bla.nl', 'password' => 'xxxx','remember_me' => '1'];
|
'email' => 'bla@bla'
|
||||||
Auth::shouldReceive('attempt')->once()->andReturn(true);
|
];
|
||||||
$this->call('POST', '/login', $data);
|
|
||||||
$this->assertSessionHas('success');
|
// test
|
||||||
$this->assertRedirectedToRoute('index');
|
$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()
|
public function tearDown()
|
||||||
|
Reference in New Issue
Block a user