New tests.

This commit is contained in:
James Cole
2015-04-04 21:52:56 +02:00
parent 48427b1143
commit b38ed06f6e
2 changed files with 30 additions and 26 deletions

View File

@@ -29,7 +29,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
*/ */
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass();
} }
/** /**

View File

@@ -12,8 +12,8 @@ use League\FactoryMuffin\Facade as FactoryMuffin;
*/ */
class AccountControllerTest extends TestCase class AccountControllerTest extends TestCase
{ {
/** @var Account */
protected $account; public $account;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
@@ -22,10 +22,18 @@ class AccountControllerTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->account = FactoryMuffin::create('FireflyIII\Models\Account'); $this->createAccount();
} }
/**
* This method is called before the first test of this test class is run.
*
* @since Method available since Release 3.4.0
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
/** /**
* Tears down the fixture, for example, closes a network connection. * Tears down the fixture, for example, closes a network connection.
@@ -33,21 +41,19 @@ class AccountControllerTest extends TestCase
*/ */
public function tearDown() public function tearDown()
{ {
foreach (DB::table('accounts')->get() as $entry) {
DB::table('accounts')->delete($entry->id);
}
foreach (DB::table('account_types')->get() as $entry) {
DB::table('account_types')->delete($entry->id);
}
parent::tearDown(); parent::tearDown();
/*
* Delete some entries?
*/
} }
public function createAccount()
{
if (is_null($this->account)) {
$this->account = FactoryMuffin::create('FireflyIII\Models\Account');
Log::debug('Created a new account.');
//$this->account->accountType->type = 'Asset account';
//$this->account->accountType->save();
}
}
public function testCreate() public function testCreate()
{ {
@@ -75,9 +81,6 @@ class AccountControllerTest extends TestCase
public function testDelete() public function testDelete()
{ {
// fake an account.
$this->account->accountType->type = 'Asset account';
$this->account->accountType->save();
$this->be($this->account->user); $this->be($this->account->user);
$this->call('GET', '/accounts/delete/' . $this->account->id); $this->call('GET', '/accounts/delete/' . $this->account->id);
@@ -89,13 +92,15 @@ class AccountControllerTest extends TestCase
public function testDestroy() public function testDestroy()
{ {
// fake an account. // fake an account.
$this->be($this->account->user); $account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->assertCount(1, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get());
$this->be($account->user);
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
// post it! // post it!
$this->call('POST', '/accounts/destroy/' . $this->account->id, ['_token' => 'replaceme']); $this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
$this->assertSessionHas('success'); $this->assertSessionHas('success');
$this->assertCount(0, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get()); $this->assertCount(0, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
} }
public function testEdit() public function testEdit()
@@ -160,13 +165,12 @@ class AccountControllerTest extends TestCase
public function testShow() public function testShow()
{ {
// an account: // an account:
$account = FactoryMuffin::create('FireflyIII\Models\Account'); $this->be($this->account->user);
$this->be($account->user);
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A'); Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
// get edit page: // get edit page:
$this->call('GET', '/accounts/show/' . $account->id); $this->call('GET', '/accounts/show/' . $this->account->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }