mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Some new tests and a bug fix for piggy banks.
This commit is contained in:
@@ -51,9 +51,15 @@ class ConnectJournalToPiggyBank
|
||||
if (is_null($repetition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$amount = $journal->correct_amount;
|
||||
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->save();
|
||||
|
||||
|
@@ -9,6 +9,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait;
|
||||
|
||||
/**
|
||||
* Class User
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @package FireflyIII
|
||||
* @property integer $id
|
||||
|
@@ -73,6 +73,11 @@ class HomeControllerTest extends TestCase
|
||||
$user = FactoryMuffin::create('FireflyIII\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->assertResponseStatus(302);
|
||||
|
||||
|
@@ -147,6 +147,98 @@ class TransactionControllerTest extends TestCase
|
||||
$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
|
||||
*/
|
||||
@@ -259,7 +351,7 @@ class TransactionControllerTest extends TestCase
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @covers FireflyIII\Http\Controllers\TransactionController::store
|
||||
*/
|
||||
public function testStoreCreateAnother()
|
||||
public function testStore()
|
||||
{
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
@@ -278,7 +370,6 @@ class TransactionControllerTest extends TestCase
|
||||
'amount_currency_id' => $currency->id,
|
||||
'date' => '2015-05-05',
|
||||
'budget_id' => '0',
|
||||
'create_another' => '1',
|
||||
'category' => '',
|
||||
'tags' => 'fat-test',
|
||||
'piggy_bank_id' => '0',
|
||||
@@ -304,7 +395,7 @@ class TransactionControllerTest extends TestCase
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @covers FireflyIII\Http\Controllers\TransactionController::store
|
||||
*/
|
||||
public function testStore()
|
||||
public function testStoreCreateAnother()
|
||||
{
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
@@ -323,6 +414,7 @@ class TransactionControllerTest extends TestCase
|
||||
'amount_currency_id' => $currency->id,
|
||||
'date' => '2015-05-05',
|
||||
'budget_id' => '0',
|
||||
'create_another' => '1',
|
||||
'category' => '',
|
||||
'tags' => 'fat-test',
|
||||
'piggy_bank_id' => '0',
|
||||
|
Reference in New Issue
Block a user