Some experimental model tests.

This commit is contained in:
James Cole
2014-07-09 13:19:30 +02:00
parent 5645f7a893
commit 84f4e80da1
8 changed files with 93 additions and 111 deletions

View File

@@ -0,0 +1,55 @@
<?php
use Zizaco\FactoryMuff\Facade\FactoryMuff;
class AllModelsTest extends TestCase
{
/**
* Default preparation for each test
*/
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* Migrate the database
*/
private function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
/**
* User tests
*/
public function testUser()
{
$user = FactoryMuff::create('User');
$pref = FactoryMuff::create('Preference');
$account = FactoryMuff::create('Account');
$account->user()->associate($user);
$pref->user()->associate($user);
$this->assertEquals($account->user_id, $user->id);
$this->assertEquals($pref->user_id,$user->id);
$this->assertTrue(true);
}
/**
* Account tests
*/
public function testUserAccounts()
{
$this->assertTrue(true);
}
}

View File

@@ -1,30 +0,0 @@
<?php
class TransactionJournalTest extends TestCase
{
/**
* Default preparation for each test
*/
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* Migrate the database
*/
private function prepareForTests()
{
Artisan::call('migrate');
}
/**
* Test accounts
*/
public function testJournal()
{
$this->assertTrue(true);
}
}

View File

@@ -1,75 +0,0 @@
<?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.");
}
/**
* Test accounts
*/
public function testUserAccounts()
{
// Create a new User
$user = new User;
$user->email = 'bla';
$user->password = 'bla';
$user->migrated = 0;
$user->save();
// account type:
$at = new AccountType;
$at->description = 'Bla';
$at->save();
$account = new Account;
$account->name = 'bla';
$account->active = 1;
$account->accountType()->associate($at);
$account->user()->associate($user);
$account->save();
$this->assertCount(1,$user->accounts()->get());
}
}