Fixed more tests but the factories are not perfect yet.

This commit is contained in:
James Cole
2015-04-04 21:23:37 +02:00
parent 0c02a08954
commit 5d505f4ed0
6 changed files with 144 additions and 80 deletions

View File

@@ -1,7 +1,10 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
@@ -17,6 +20,7 @@ class AccountControllerTest extends TestCase
public function setUp()
{
parent::setUp();
$this->account = FactoryMuffin::create('FireflyIII\Models\Account');
}
@@ -28,6 +32,7 @@ class AccountControllerTest extends TestCase
public function tearDown()
{
parent::tearDown();
}
@@ -58,42 +63,34 @@ class AccountControllerTest extends TestCase
public function testDelete()
{
// fake an account.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->accountType->type = 'Asset account';
$account->accountType->save();
$this->account->accountType->type = 'Asset account';
$this->account->accountType->save();
$this->be($account->user);
$this->call('GET', '/accounts/delete/' . $account->id);
$this->be($this->account->user);
$this->call('GET', '/accounts/delete/' . $this->account->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"');
$this->assertViewHas('subTitle', 'Delete ' . strtolower(e($this->account->accountType->type)) . ' "' . e($this->account->name) . '"');
}
public function testDestroy()
{
// fake an account.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->accountType->type = 'Asset account';
$account->accountType->save();
$this->be($account->user);
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
$this->be($this->account->user);
$this->assertCount(1, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get());
// post it!
$this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
$this->call('POST', '/accounts/destroy/' . $this->account->id, ['_token' => 'replaceme']);
$this->assertSessionHas('success');
$this->assertCount(0, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
$this->assertCount(0, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get());
}
public function testEdit()
{
// fake an account.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->accountType->type = 'Asset account';
$account->accountType->save();
$this->be($account->user);
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
$this->be($this->account->user);
$this->assertCount(1, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get());
// create a transaction journal that will act as opening balance:
$openingBalance = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
@@ -110,24 +107,32 @@ class AccountControllerTest extends TestCase
Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
// get edit page:
$this->call('GET', '/accounts/edit/' . $account->id);
$this->call('GET', '/accounts/edit/' . $this->account->id);
// assert stuff:
$this->assertResponseOk();
$this->assertSessionHas('preFilled');
$this->assertViewHas('subTitle', 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"');
$this->assertViewHas('subTitle', 'Edit ' . strtolower(e($this->account->accountType->type)) . ' "' . e($this->account->name) . '"');
}
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// an account:
$this->be($this->account->user);
$collection = new Collection;
$collection->push($this->account);
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->andReturn($collection);
$repository->shouldReceive('countAccounts')->andReturn(1);
$repository->shouldReceive('getLastActivity')->andReturn(null);
Amount::shouldReceive('format')->andReturn('');
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
// get currency code:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
Amount::shouldReceive('getCurrencyCode')->andReturn($currency->code);
// put stuff in session:
$this->session(['start' => new Carbon, 'end' => new Carbon]);
@@ -141,7 +146,15 @@ class AccountControllerTest extends TestCase
public function testShow()
{
$this->markTestIncomplete();
// an account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
// get edit page:
$this->call('GET', '/accounts/show/' . $account->id);
$this->assertResponseOk();
}
public function testStore()