Some new tests and a bug fix for piggy banks.

This commit is contained in:
James Cole
2015-06-24 21:02:34 +02:00
parent 124c9303b9
commit 5160f2c298
4 changed files with 109 additions and 5 deletions

View File

@@ -51,9 +51,15 @@ class ConnectJournalToPiggyBank
if (is_null($repetition)) { if (is_null($repetition)) {
return false; return false;
} }
$amount = $journal->correct_amount;
bcscale(2); bcscale(2);
$amount = $journal->actual_amount;
// if piggy account matches source account, the amount is positive
if ($piggyBank->account_id == $journal->source_account->id) {
$amount = $amount * -1;
}
$repetition->currentamount = bcadd($repetition->currentamount, $amount); $repetition->currentamount = bcadd($repetition->currentamount, $amount);
$repetition->save(); $repetition->save();

View File

@@ -9,6 +9,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait;
/** /**
* Class User * Class User
* @codeCoverageIgnore
* *
* @package FireflyIII * @package FireflyIII
* @property integer $id * @property integer $id

View File

@@ -73,6 +73,11 @@ class HomeControllerTest extends TestCase
$user = FactoryMuffin::create('FireflyIII\User'); $user = FactoryMuffin::create('FireflyIII\User');
$this->be($user); $this->be($user);
// create at least one tag:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->tags()->save($tag);
$this->call('GET', '/flush'); $this->call('GET', '/flush');
$this->assertResponseStatus(302); $this->assertResponseStatus(302);

View File

@@ -147,6 +147,98 @@ class TransactionControllerTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditCashDestination()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make complete journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
//$expense = FactoryMuffin::create('FireflyIII\Models\Account'); // expense account
//$revenue = FactoryMuffin::create('FireflyIII\Models\Account'); // revenue account
$asset = FactoryMuffin::create('FireflyIII\Models\Account'); // asset account
$cash = FactoryMuffin::create('FireflyIII\Models\Account'); // cash account
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->amount = -300;
$journal->transactions[0]->save();
$journal->transactions[0]->account_id = $cash->id;
$journal->transactions[0]->amount = 300;
$journal->transactions[0]->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transaction/edit/' . $journal->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditDeposit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make complete journal:
$accountType = FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$transaction1 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$transaction2 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$accountType->type = 'Asset account';
$account->account_type_id = $accountType->id;
$account->save();
$transaction1->account_id = $account->id;
$transaction1->transaction_journal_id = $journal->id;
$transaction1->save();
$transaction2->account_id = $account->id;
$transaction2->transaction_journal_id = $journal->id;
$transaction2->save();
// also add some tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->transactionJournals()->save($journal);
// and a category and a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$category->transactionJournals()->save($journal);
$budget->transactionJournals()->save($journal);
// and a piggy bank event:
$pbEvent = FactoryMuffin::create('FireflyIII\Models\PiggyBankEvent');
$pbEvent->transaction_journal_id = $journal->id;
$pbEvent->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transaction/edit/' . $journal->id);
$this->assertResponseOk();
}
/** /**
* @covers FireflyIII\Http\Controllers\TransactionController::index * @covers FireflyIII\Http\Controllers\TransactionController::index
*/ */
@@ -259,7 +351,7 @@ class TransactionControllerTest extends TestCase
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::store * @covers FireflyIII\Http\Controllers\TransactionController::store
*/ */
public function testStoreCreateAnother() public function testStore()
{ {
$account = FactoryMuffin::create('FireflyIII\Models\Account'); $account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
@@ -278,7 +370,6 @@ class TransactionControllerTest extends TestCase
'amount_currency_id' => $currency->id, 'amount_currency_id' => $currency->id,
'date' => '2015-05-05', 'date' => '2015-05-05',
'budget_id' => '0', 'budget_id' => '0',
'create_another' => '1',
'category' => '', 'category' => '',
'tags' => 'fat-test', 'tags' => 'fat-test',
'piggy_bank_id' => '0', 'piggy_bank_id' => '0',
@@ -304,7 +395,7 @@ class TransactionControllerTest extends TestCase
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::store * @covers FireflyIII\Http\Controllers\TransactionController::store
*/ */
public function testStore() public function testStoreCreateAnother()
{ {
$account = FactoryMuffin::create('FireflyIII\Models\Account'); $account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
@@ -323,6 +414,7 @@ class TransactionControllerTest extends TestCase
'amount_currency_id' => $currency->id, 'amount_currency_id' => $currency->id,
'date' => '2015-05-05', 'date' => '2015-05-05',
'budget_id' => '0', 'budget_id' => '0',
'create_another' => '1',
'category' => '', 'category' => '',
'tags' => 'fat-test', 'tags' => 'fat-test',
'piggy_bank_id' => '0', 'piggy_bank_id' => '0',