mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Removed everything related to unit tests. Can restore later.
This commit is contained in:
@@ -1,162 +0,0 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class AccountModelTest
|
||||
*/
|
||||
class AccountModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncrypted()
|
||||
{
|
||||
// create account:
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
|
||||
// search for account with the same properties:
|
||||
$search = [
|
||||
'name' => $account->name,
|
||||
'account_type_id' => $account->account_type_id,
|
||||
'user_id' => $account->user_id
|
||||
];
|
||||
|
||||
$result = Account::firstOrCreateEncrypted($search);
|
||||
|
||||
// should be the same account:
|
||||
|
||||
$this->assertEquals($account->id, $result->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncryptedNew()
|
||||
{
|
||||
// create account:
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
FactoryMuffin::create('FireflyIII\User');
|
||||
|
||||
// search for account with the same properties:
|
||||
$search = [
|
||||
'name' => 'Some new account',
|
||||
'account_type_id' => $account->account_type_id,
|
||||
'user_id' => $account->user_id,
|
||||
'active' => 1,
|
||||
];
|
||||
|
||||
$result = Account::firstOrCreateEncrypted($search);
|
||||
|
||||
// should not be the same account:
|
||||
|
||||
$this->assertNotEquals($account->id, $result->id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
|
||||
*/
|
||||
public function testFirstOrNullEncrypted()
|
||||
{
|
||||
// create account:
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
|
||||
// search for account with the same properties:
|
||||
$search = [
|
||||
'name' => $account->name,
|
||||
'account_type_id' => $account->account_type_id,
|
||||
'user_id' => $account->user_id
|
||||
];
|
||||
|
||||
$result = Account::firstOrNullEncrypted($search);
|
||||
|
||||
// should be the same account:
|
||||
|
||||
$this->assertEquals($account->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
|
||||
*/
|
||||
public function testFirstOrNullEncryptedNew()
|
||||
{
|
||||
// create account:
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
FactoryMuffin::create('FireflyIII\User');
|
||||
|
||||
// search for account with the same properties:
|
||||
$search = [
|
||||
'name' => 'Some new account',
|
||||
'account_type_id' => $account->account_type_id,
|
||||
'user_id' => $account->user_id,
|
||||
'active' => 1,
|
||||
];
|
||||
|
||||
$result = Account::firstOrNullEncrypted($search);
|
||||
|
||||
// should not be the same account:
|
||||
|
||||
$this->assertNull($result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::getNameForEditformAttribute
|
||||
*/
|
||||
public function testGetNameForEditformAttribute()
|
||||
{
|
||||
// normal name is normal
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$this->assertEquals($account->name, $account->getNameForEditformAttribute());
|
||||
}
|
||||
/**
|
||||
* @covers FireflyIII\Models\Account::getNameForEditformAttribute
|
||||
*/
|
||||
public function testGetNameForEditformAttributeCash()
|
||||
{
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
// cash name is empty
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$this->assertEquals('', $account->getNameForEditformAttribute());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
|
||||
/**
|
||||
* Class CategoryModelTest
|
||||
*/
|
||||
class CategoryModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Category::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncrypted()
|
||||
{
|
||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||
|
||||
$search = [
|
||||
'name' => $category->name,
|
||||
'user_id' => $category->user_id
|
||||
];
|
||||
|
||||
$result = Category::firstOrCreateEncrypted($search);
|
||||
|
||||
$this->assertEquals($result->id, $category->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Category::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncryptedNew()
|
||||
{
|
||||
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||
|
||||
$search = [
|
||||
'name' => 'Some category name',
|
||||
'user_id' => $category->user_id
|
||||
];
|
||||
|
||||
$result = Category::firstOrCreateEncrypted($search);
|
||||
|
||||
$this->assertNotEquals($result->id, $category->id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class TagModelTest
|
||||
*/
|
||||
class TagModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Tag::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncrypted()
|
||||
{
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$search = [
|
||||
'tagMode' => 'something',
|
||||
'tag' => $tag->tag,
|
||||
'user_id' => $tag->user_id,
|
||||
];
|
||||
|
||||
$result = Tag::firstOrCreateEncrypted($search);
|
||||
|
||||
$this->assertEquals($tag->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Tag::firstOrCreateEncrypted
|
||||
*/
|
||||
public function testFirstOrCreateEncryptedNew()
|
||||
{
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$search = [
|
||||
'tagMode' => 'something',
|
||||
'tag' => 'Something else',
|
||||
'user_id' => $tag->user_id,
|
||||
];
|
||||
|
||||
$result = Tag::firstOrCreateEncrypted($search);
|
||||
|
||||
$this->assertNotEquals($tag->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\Tag::save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
// connect some transaction journals to the tag:
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->tags()->save($tag);
|
||||
$tag->save();
|
||||
$journal = TransactionJournal::find($journal->id);
|
||||
|
||||
$this->assertEquals(1, $journal->tag_count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,636 +0,0 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalModelTest
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
*/
|
||||
class TransactionJournalModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getActualAmountAttribute
|
||||
*/
|
||||
public function testGetActualAmountAttribute()
|
||||
{
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
$journal->transactions[0]->amount = '123.45';
|
||||
$journal->transactions[0]->save();
|
||||
$journal->transactions[1]->amount = '-123.45';
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
$amount = $journal->actual_amount;
|
||||
$this->assertEquals('123.45', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Journal has one tag.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::save
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testGetAmountAttributeAdvancePayment()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
// make types:
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
// make tag
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'advancePayment';
|
||||
$tag->save();
|
||||
|
||||
// make withdrawal
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make deposit
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$deposit->transaction_type_id = $depositType->id;
|
||||
$deposit->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
$deposit->transactions[0]->account_id = $revenue->id;
|
||||
$deposit->transactions[0]->amount = -89.88;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $asset->id;
|
||||
$deposit->transactions[1]->amount = 89.88;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
$tag->transactionJournals()->save($deposit);
|
||||
|
||||
$withdrawal->save();
|
||||
$deposit->save();
|
||||
$withdrawal = TransactionJournal::find($withdrawal->id);
|
||||
$deposit = TransactionJournal::find($deposit->id);
|
||||
|
||||
// amount should be 210.12:
|
||||
$this->assertEquals('210.12', $withdrawal->amount);
|
||||
$this->assertEquals('0', $deposit->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Journal has one tag.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testGetAmountAttributeBalancingAct()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// make types:
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
// make a tag
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'balancingAct';
|
||||
$tag->save();
|
||||
|
||||
// make a withdrawal and a transfer
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$transfer->transaction_type_id = $transferType->id;
|
||||
$transfer->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
$tag->transactionJournals()->save($transfer);
|
||||
|
||||
// make accounts:
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue->account_type_id = $asset->account_type_id;
|
||||
$revenue->save();
|
||||
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -123.45;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->amount = 123.45;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
$transfer->transactions[0]->account_id = $revenue->id;
|
||||
$transfer->transactions[0]->amount = -123.45;
|
||||
$transfer->transactions[0]->save();
|
||||
|
||||
$transfer->transactions[1]->account_id = $asset->id;
|
||||
$transfer->transactions[1]->amount = 123.45;
|
||||
$transfer->transactions[1]->save();
|
||||
|
||||
$withdrawal->save();
|
||||
|
||||
$withdrawal = TransactionJournal::find($withdrawal->id);
|
||||
|
||||
$amount = $withdrawal->amount;
|
||||
|
||||
|
||||
$this->assertEquals('0', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Journal has no tags.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeNoTags()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
$journal->transactions[0]->amount = 123.45;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->amount = -123.45;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
$amount = $journal->amount;
|
||||
$this->assertEquals('123.45', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Journal has one tag.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeTag()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// has a normal tag, but nothing special.
|
||||
// make tag
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'nothing';
|
||||
$tag->save();
|
||||
|
||||
// make withdrawal
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
|
||||
$withdrawal->save();
|
||||
$withdrawal = TransactionJournal::find($withdrawal->id);
|
||||
|
||||
$this->assertEquals('300', $withdrawal->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Journal has multiple tags, withdrawal. All default tag.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeTags()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// has two normal tags:
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'nothing';
|
||||
$tag->save();
|
||||
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag2->tagMode = 'nothing';
|
||||
$tag2->save();
|
||||
|
||||
// make withdrawal
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
$tag2->transactionJournals()->save($withdrawal);
|
||||
|
||||
// grab withdrawal again to update tag count:
|
||||
$withdrawal->save();
|
||||
$withdrawal = TransactionJournal::find($withdrawal->id);
|
||||
|
||||
$this->assertEquals('300', $withdrawal->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple tags, transfer, and one is a balancing act
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeTagsTransfer()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// has two normal tags:
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'balancingAct';
|
||||
$tag->save();
|
||||
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag2->tagMode = 'nothing';
|
||||
$tag2->save();
|
||||
|
||||
// make withdrawal
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$transfer->transaction_type_id = $transferType->id;
|
||||
$transfer->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$transfer->transactions[0]->amount = -300;
|
||||
$transfer->transactions[0]->account_id = $asset->id;
|
||||
$transfer->transactions[0]->save();
|
||||
|
||||
$transfer->transactions[1]->amount = 300;
|
||||
$transfer->transactions[1]->account_id = $expense->id;
|
||||
$transfer->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($transfer);
|
||||
$tag2->transactionJournals()->save($transfer);
|
||||
|
||||
$transfer->save();
|
||||
$transfer = TransactionJournal::find($transfer->id);
|
||||
|
||||
$this->assertEquals('300', $transfer->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple tags, transfer, and one is a advance payment.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeTagsTransferAdvance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// has two normal tags:
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'advancePayment';
|
||||
$tag->save();
|
||||
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag2->tagMode = 'nothing';
|
||||
$tag2->save();
|
||||
|
||||
// make withdrawal
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$transfer->transaction_type_id = $transferType->id;
|
||||
$transfer->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$transfer->transactions[0]->amount = -300;
|
||||
$transfer->transactions[0]->account_id = $asset->id;
|
||||
$transfer->transactions[0]->save();
|
||||
|
||||
$transfer->transactions[1]->amount = 300;
|
||||
$transfer->transactions[1]->account_id = $expense->id;
|
||||
$transfer->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($transfer);
|
||||
$tag2->transactionJournals()->save($transfer);
|
||||
|
||||
$transfer->save();
|
||||
$transfer = TransactionJournal::find($transfer->id);
|
||||
|
||||
$this->assertEquals('300', $transfer->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple tags, withdrawal, and one is a balancingAct.
|
||||
*
|
||||
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTag
|
||||
* @covers FireflyIII\Models\TransactionJournal::amountByTags
|
||||
*/
|
||||
public function testGetAmountAttributeTagsWithdrawalAdvance()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// has two normal tags:
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'balancingAct';
|
||||
$tag->save();
|
||||
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag2->tagMode = 'nothing';
|
||||
$tag2->save();
|
||||
|
||||
// make withdrawal
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
$tag2->transactionJournals()->save($withdrawal);
|
||||
|
||||
$withdrawal->save();
|
||||
$withdrawal = TransactionJournal::find($withdrawal->id);
|
||||
|
||||
$this->assertEquals('300', $withdrawal->amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectAmountAttribute()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->transaction_type_id = $withdrawal->id;
|
||||
$journal->save();
|
||||
|
||||
$journal->transactions[0]->account_id = $asset->id;
|
||||
$journal->transactions[0]->amount = 300;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->account_id = $revenue->id;
|
||||
$journal->transactions[1]->amount = -300;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $journal->correct_amount;
|
||||
|
||||
$this->assertEquals(-300, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectAmountAttributeDeposit()
|
||||
{
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->transaction_type_id = $deposit->id;
|
||||
$journal->save();
|
||||
|
||||
$journal->transactions[0]->account_id = $asset->id;
|
||||
$journal->transactions[0]->amount = 300;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->account_id = $revenue->id;
|
||||
$journal->transactions[1]->amount = -300;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $journal->correct_amount;
|
||||
|
||||
$this->assertEquals(300, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectAmountAttributeTransfer()
|
||||
{
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->transaction_type_id = $transfer->id;
|
||||
$journal->save();
|
||||
|
||||
$journal->transactions[0]->account_id = $asset->id;
|
||||
$journal->transactions[0]->amount = 300;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->account_id = $revenue->id;
|
||||
$journal->transactions[1]->amount = -300;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $journal->correct_amount;
|
||||
|
||||
$this->assertEquals('300', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute
|
||||
*/
|
||||
public function testGetDestinationAccountAttribute()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$deposit->transaction_type_id = $depositType->id;
|
||||
$deposit->save();
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = 300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->destination_account;
|
||||
|
||||
$this->assertEquals($asset->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getSourceAccountAttribute
|
||||
*/
|
||||
public function testGetSourceAccountAttribute()
|
||||
{
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$deposit->transaction_type_id = $depositType->id;
|
||||
$deposit->save();
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = 300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->source_account;
|
||||
|
||||
$this->assertEquals($revenue->id, $result->id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user