mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
Fixed tests.
This commit is contained in:
parent
2d2f18e538
commit
7dfde51b84
@ -223,28 +223,6 @@ class TransactionJournal extends Model
|
||||
return $this->hasMany('FireflyIII\Models\Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCorrectedActualAmountAttribute()
|
||||
{
|
||||
$amount = '0';
|
||||
$type = $this->transactionType->type;
|
||||
/** @var Transaction $t */
|
||||
foreach ($this->transactions as $t) {
|
||||
if ($t->amount > 0 && $type != 'Withdrawal') {
|
||||
$amount = $t->amount;
|
||||
break;
|
||||
}
|
||||
if ($t->amount < 0 && $type == 'Withdrawal') {
|
||||
$amount = $t->amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
|
@ -167,7 +167,7 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
$query = DB::table($parameters[0])->where($parameters[1], $value);
|
||||
$query->where('user_id', Auth::user()->id);
|
||||
if (isset($paramers[2])) {
|
||||
if (isset($parameters[2])) {
|
||||
$query->where('id', '!=', $parameters[2]);
|
||||
}
|
||||
$count = $query->count();
|
||||
|
@ -38,7 +38,8 @@
|
||||
"satooshi/php-coveralls": "0.6.1",
|
||||
"mockery/mockery": "0.9.*",
|
||||
"league/factory-muffin": "~2.1",
|
||||
"codeclimate/php-test-reporter": "^0.1.2"
|
||||
"codeclimate/php-test-reporter": "^0.1.2",
|
||||
"fzaninotto/faker": "^1.4"
|
||||
|
||||
|
||||
|
||||
|
98
composer.lock
generated
98
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "5c085b2cc90ffa610e386897066315a7",
|
||||
"hash": "46b7813f499f70942e9997e916e68145",
|
||||
"packages": [
|
||||
{
|
||||
"name": "classpreloader/classpreloader",
|
||||
@ -673,6 +673,54 @@
|
||||
],
|
||||
"time": "2014-09-09 13:34:57"
|
||||
},
|
||||
{
|
||||
"name": "fzaninotto/faker",
|
||||
"version": "v1.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fzaninotto/Faker.git",
|
||||
"reference": "010c7efedd88bf31141a02719f51fb44c732d5a0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/010c7efedd88bf31141a02719f51fb44c732d5a0",
|
||||
"reference": "010c7efedd88bf31141a02719f51fb44c732d5a0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~1.5"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": []
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Faker": "src/",
|
||||
"Faker\\PHPUnit": "test/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "François Zaninotto"
|
||||
}
|
||||
],
|
||||
"description": "Faker is a PHP library that generates fake data for you.",
|
||||
"keywords": [
|
||||
"data",
|
||||
"faker",
|
||||
"fixtures"
|
||||
],
|
||||
"time": "2014-06-04 14:43:02"
|
||||
},
|
||||
{
|
||||
"name": "grumpydictator/gchart",
|
||||
"version": "1.0.9",
|
||||
@ -2800,54 +2848,6 @@
|
||||
],
|
||||
"time": "2014-10-13 12:58:55"
|
||||
},
|
||||
{
|
||||
"name": "fzaninotto/faker",
|
||||
"version": "v1.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fzaninotto/Faker.git",
|
||||
"reference": "010c7efedd88bf31141a02719f51fb44c732d5a0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/010c7efedd88bf31141a02719f51fb44c732d5a0",
|
||||
"reference": "010c7efedd88bf31141a02719f51fb44c732d5a0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~1.5"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": []
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Faker": "src/",
|
||||
"Faker\\PHPUnit": "test/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "François Zaninotto"
|
||||
}
|
||||
],
|
||||
"description": "Faker is a PHP library that generates fake data for you.",
|
||||
"keywords": [
|
||||
"data",
|
||||
"faker",
|
||||
"fixtures"
|
||||
],
|
||||
"time": "2014-06-04 14:43:02"
|
||||
},
|
||||
{
|
||||
"name": "guzzle/guzzle",
|
||||
"version": "v3.9.3",
|
||||
|
@ -159,6 +159,7 @@ class CategoryControllerTest extends TestCase
|
||||
|
||||
Amount::shouldReceive('format')->andReturn('xx');
|
||||
Amount::shouldReceive('getCurrencyCode')->andReturn('xx');
|
||||
Amount::shouldReceive('formatJournal')->andReturn('xx');
|
||||
|
||||
$this->call('GET', '/categories/show/' . $category->id);
|
||||
$this->assertResponseOk();
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
if (!class_exists('RandomString')) {
|
||||
@ -198,10 +200,15 @@ FactoryMuffin::define(
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\User',
|
||||
[
|
||||
'email' => 'email',
|
||||
'email' => function () {
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
return $faker->email;
|
||||
},
|
||||
'password' => bcrypt('james'),
|
||||
]
|
||||
);
|
||||
@ -286,5 +293,27 @@ FactoryMuffin::define(
|
||||
'date' => 'date',
|
||||
'encrypted' => '1',
|
||||
'order' => '0',
|
||||
], function (TransactionJournal $object, $saved) {
|
||||
if ($saved) {
|
||||
$one = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$two = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $one->id,
|
||||
'transaction_journal_id' => $object->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $two->id,
|
||||
'transaction_journal_id' => $object->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
@ -61,23 +61,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
$rep->forceDelete();
|
||||
}
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
// two transactions:
|
||||
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
@ -141,21 +124,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
$result = $class->handle($event);
|
||||
@ -202,21 +170,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
$result = $class->handle($event);
|
||||
|
@ -122,20 +122,6 @@ class ReportHelperTest extends TestCase
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(-100, 100)
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(-100, 100)
|
||||
]
|
||||
);
|
||||
$journals->push($journal);
|
||||
}
|
||||
|
||||
@ -257,25 +243,11 @@ class ReportHelperTest extends TestCase
|
||||
$journal->transaction_type_id = $type->id;
|
||||
$journal->user_id = $user->id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// test!
|
||||
$object = $this->object->getExpenseReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
|
||||
$this->assertCount(1, $object->getExpenses());
|
||||
$this->assertCount(5, $object->getExpenses());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,25 +294,11 @@ class ReportHelperTest extends TestCase
|
||||
$journal->transaction_type_id = $type->id;
|
||||
$journal->user_id = $user->id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// test!
|
||||
$object = $this->object->getIncomeReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
|
||||
$this->assertCount(1, $object->getIncomes());
|
||||
$this->assertCount(5, $object->getIncomes());
|
||||
|
||||
}
|
||||
|
||||
|
@ -80,21 +80,15 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@ -149,21 +143,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@ -271,21 +258,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = 100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = -100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@ -339,21 +319,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
|
@ -47,13 +47,11 @@ class TransactionJournalModelTest extends TestCase
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 123.45
|
||||
]
|
||||
);
|
||||
$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);
|
||||
}
|
||||
@ -88,13 +86,22 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// for withdrawal, asset to expense account and reversed: //89,88
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -89.88]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 89.88]);
|
||||
$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);
|
||||
@ -138,17 +145,27 @@ class TransactionJournalModelTest extends TestCase
|
||||
|
||||
// make accounts:
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset2->account_type_id = $asset->account_type_id;
|
||||
$asset2->save();
|
||||
$revenue->account_type_id = $asset->account_type_id;
|
||||
$revenue->save();
|
||||
|
||||
// make transactions:
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -123.45]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 123.45]);
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -123.45;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
Transaction::create(['account_id' => $asset2->id, 'transaction_journal_id' => $transfer->id, 'amount' => -123.45]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $transfer->id, 'amount' => 123.45]);
|
||||
$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();
|
||||
|
||||
$amount = $withdrawal->amount;
|
||||
|
||||
@ -161,15 +178,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
public function testGetAmountAttributeNoTags()
|
||||
{
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 123.45
|
||||
]
|
||||
);
|
||||
$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);
|
||||
}
|
||||
@ -195,8 +210,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
$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);
|
||||
@ -224,8 +244,15 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
// update transactions
|
||||
$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->asset_account;
|
||||
@ -240,19 +267,24 @@ class TransactionJournalModelTest extends TestCase
|
||||
{
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$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();
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->asset_account;
|
||||
@ -265,18 +297,25 @@ class TransactionJournalModelTest extends TestCase
|
||||
*/
|
||||
public function testGetAssetAccountAttributeWithdrawal()
|
||||
{
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// 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');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
|
||||
$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();
|
||||
|
||||
// get asset account:
|
||||
$result = $withdrawal->asset_account;
|
||||
@ -284,58 +323,6 @@ class TransactionJournalModelTest extends TestCase
|
||||
$this->assertEquals($asset->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectedActualAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectedActualAmountAttributeDeposit()
|
||||
{
|
||||
|
||||
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');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->corrected_actual_amount;
|
||||
|
||||
$this->assertEquals('300', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectedActualAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectedActualAmountAttributeWithdrawal()
|
||||
{
|
||||
|
||||
// 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');
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
|
||||
// get asset account:
|
||||
$result = $withdrawal->corrected_actual_amount;
|
||||
|
||||
$this->assertEquals('-300', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute
|
||||
*/
|
||||
@ -352,8 +339,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$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;
|
||||
@ -377,8 +369,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$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;
|
||||
|
@ -2,8 +2,6 @@
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepository;
|
||||
@ -117,30 +115,18 @@ class AccountRepositoryTest extends TestCase
|
||||
{
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$first = $journal->transactions()->orderBy('date', 'DESC')->first();
|
||||
$first->account_id = $account->id;
|
||||
$first->save();
|
||||
|
||||
// two matching transactions:
|
||||
$first = Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100,
|
||||
]
|
||||
);
|
||||
|
||||
// login
|
||||
$this->be($account->user);
|
||||
|
||||
$oldest = $this->object->getFirstTransaction($journal, $account);
|
||||
|
||||
$this->assertEquals($oldest->amount, $first->amount);
|
||||
$this->assertEquals($oldest->id, $first->id);
|
||||
$this->assertEquals($first->amount, $oldest->amount);
|
||||
$this->assertEquals($first->id, $oldest->id);
|
||||
|
||||
}
|
||||
|
||||
@ -215,28 +201,12 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->save();
|
||||
$journal3->save();
|
||||
|
||||
// transactions to match the dates (one per journal will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->save();
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal1->user);
|
||||
@ -277,28 +247,12 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->save();
|
||||
$journal3->save();
|
||||
|
||||
// transactions to match the dates (one per journal will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->save();
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal1->user);
|
||||
@ -329,14 +283,8 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal->user_id = $account->user_id;
|
||||
$journal->save();
|
||||
|
||||
// transaction to match the date (one will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->account_id = $account->id;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal->user);
|
||||
@ -478,28 +426,25 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->transaction_type_id = $journal1->transaction_type_id;
|
||||
$journal3->transaction_type_id = $journal1->transaction_type_id;
|
||||
|
||||
// three transactions:
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// transactions are already present, update them!
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->amount = 100;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[1]->amount = 100;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->amount = 100;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[1]->amount = 100;
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->amount = 100;
|
||||
$journal3->transactions[1]->account_id = $account->id;
|
||||
$journal3->transactions[1]->amount = 100;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
$journal3->transactions[0]->save();
|
||||
$journal3->transactions[1]->save();
|
||||
|
||||
// check date:
|
||||
$start = new Carbon('2014-01-01');
|
||||
@ -557,21 +502,6 @@ class AccountRepositoryTest extends TestCase
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
// two transactions:
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
|
||||
// dates
|
||||
$one = new Carbon('2013-01-15');
|
||||
@ -582,6 +512,18 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal1->user_id = $account->user_id;
|
||||
$journal2->date = $two;
|
||||
$journal2->user_id = $account->user_id;
|
||||
|
||||
// add account things:
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
|
||||
$journal1->save();
|
||||
$journal2->save();
|
||||
|
||||
|
@ -176,13 +176,8 @@ class BillRepositoryTest extends TestCase
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->user_id = $bill1->user_id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(101, 999),
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->account_id = $account->id;
|
||||
$journal->transactions[0]->save();
|
||||
}
|
||||
$this->be($bill1->user);
|
||||
|
||||
|
@ -129,7 +129,8 @@ class CategoryRepositoryTest extends TestCase
|
||||
$this->assertCount(10, $set);
|
||||
reset($set);
|
||||
|
||||
$this->assertEquals(0, current($set)['sum']);
|
||||
// every journal has amount 100.
|
||||
$this->assertEquals(100, current($set)['sum']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,9 +180,14 @@ class TagRepositoryTest extends TestCase
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
// transactions for both:
|
||||
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100]);
|
||||
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100]);
|
||||
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
@ -228,8 +233,14 @@ class TagRepositoryTest extends TestCase
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
// transactions for both:
|
||||
Transaction::create(['account_id' => $account1->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100]);
|
||||
Transaction::create(['account_id' => $account2->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100]);
|
||||
$journal1->transactions[0]->account_id = $account1->id;
|
||||
$journal2->transactions[0]->account_id = $account2->id;
|
||||
$journal1->transactions[1]->account_id = $account1->id;
|
||||
$journal2->transactions[1]->account_id = $account2->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
Loading…
Reference in New Issue
Block a user