mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
First tests for User model.
This commit is contained in:
11
app/config/testing/database.php
Normal file
11
app/config/testing/database.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'default' => 'sqlite',
|
||||||
|
'connections' => [
|
||||||
|
'sqlite' => [
|
||||||
|
'driver' => 'sqlite',
|
||||||
|
'database' => ':memory:',
|
||||||
|
'prefix' => ''
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
@@ -22,7 +22,7 @@ class User extends Elegant implements UserInterface, RemindableInterface
|
|||||||
= [
|
= [
|
||||||
'email' => 'required|email|unique:users,email',
|
'email' => 'required|email|unique:users,email',
|
||||||
'migrated' => 'required|numeric|between:0,1',
|
'migrated' => 'required|numeric|between:0,1',
|
||||||
'password' => 'between:60,60',
|
'password' => 'required|between:60,60',
|
||||||
'verification' => 'between:32,32',
|
'verification' => 'between:32,32',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ class User extends Elegant implements UserInterface, RemindableInterface
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $hidden = array('password', 'remember_token');
|
protected $hidden = array('remember_token');
|
||||||
|
|
||||||
public function accounts() {
|
public function accounts() {
|
||||||
return $this->hasMany('Account');
|
return $this->hasMany('Account');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
23
app/tests/controllers/HomeControllerTest.php
Normal file
23
app/tests/controllers/HomeControllerTest.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class HomeControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
// mock:
|
||||||
|
View::shouldReceive('make')->with('index');
|
||||||
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
|
|
||||||
|
// call
|
||||||
|
$this->call('GET', '/');
|
||||||
|
|
||||||
|
// test
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
app/tests/models/UserTest.php
Normal file
45
app/tests/models/UserTest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class UserTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Default preparation for each test
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->prepareForTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate the database
|
||||||
|
*/
|
||||||
|
private function prepareForTests()
|
||||||
|
{
|
||||||
|
Artisan::call('migrate');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Username is required
|
||||||
|
*/
|
||||||
|
public function testUsernameIsRequired()
|
||||||
|
{
|
||||||
|
// Create a new User
|
||||||
|
$user = new User;
|
||||||
|
$user->migrated = 0;
|
||||||
|
$user->password = Str::random(60);
|
||||||
|
|
||||||
|
// User should not save
|
||||||
|
$this->assertFalse($user->isValid());
|
||||||
|
|
||||||
|
// Save the errors
|
||||||
|
$errors = $user->validator->messages()->all();
|
||||||
|
// // There should be 1 error
|
||||||
|
$this->assertCount(1, $errors);
|
||||||
|
|
||||||
|
// // The username error should be set
|
||||||
|
$this->assertEquals($errors[0], "The email field is required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user