Skip to content

Firefly III: a personal finances manager

Even more tests.

James Cole72fc88f3c680
diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.php
index 6f12ff3a80..59141f30f7 100644
--- a/tests/controllers/AccountControllerTest.php
+++ b/tests/controllers/AccountControllerTest.php
@@ -37,12 +37,12 @@ class AccountControllerTest extends TestCase
$this->be($pref->user);
- // CURRENCY:
- $currency = new TransactionCurrency;
-
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);
- Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
- Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
+
+ // CURRENCY:
+ $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
+ Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
+ Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
$this->call('GET', '/accounts/create/asset');
$this->assertResponseOk();
@@ -57,7 +57,7 @@ class AccountControllerTest extends TestCase
public function testDelete()
{
// fake an account.
- $account = FactoryMuffin::create('FireflyIII\Models\Account');
+ $account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->accountType->type = 'Asset account';
$account->accountType->save();
@@ -70,12 +70,44 @@ class AccountControllerTest extends TestCase
public function testDestroy()
{
- $this->markTestIncomplete();
+ // 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());
+
+ // post it!
+ $this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
+ $this->assertSessionHas('success');
+ $this->assertCount(0, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
}
public function testEdit()
{
- $this->markTestIncomplete();
+ // 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());
+
+ // CURRENCY:
+ $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
+ Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
+ Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
+
+ // get edit page:
+ $this->call('GET', '/accounts/edit/' . $account->id);
+
+ // assert stuff:
+ $this->assertResponseOk();
+ $this->assertSessionHas('preFilled');
+ $this->assertViewHas('subTitle', 'Edit ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"');
+
+
}
public function testIndex()
diff --git a/tests/factories/all.php b/tests/factories/all.php
index 190bb559e6..022018297f 100644
--- a/tests/factories/all.php
+++ b/tests/factories/all.php
@@ -27,6 +27,14 @@ FactoryMuffin::define(
]
);
+FactoryMuffin::define(
+ 'FireflyIII\Models\TransactionCurrency', [
+ 'code' => 'EUR',
+ 'symbol' => 'x',
+ 'name' => 'word'
+]
+);
+
FactoryMuffin::define(
'FireflyIII\User', [
'email' => 'email',