mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Some more tests, don't know if they'll cover.
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
class Budget extends Component {
|
class Budget extends Component {
|
||||||
protected $isSubclass = true;
|
protected $isSubclass = true;
|
||||||
|
|
||||||
|
public static $factory = [
|
||||||
|
'name' => 'string',
|
||||||
|
'user_id' => 'factory|User',
|
||||||
|
'class' => 'Budget'
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
@@ -3,4 +3,9 @@
|
|||||||
class Category extends Component
|
class Category extends Component
|
||||||
{
|
{
|
||||||
protected $isSubclass = true;
|
protected $isSubclass = true;
|
||||||
|
public static $factory = [
|
||||||
|
'name' => 'string',
|
||||||
|
'user_id' => 'factory|User',
|
||||||
|
'class' => 'Category'
|
||||||
|
];
|
||||||
}
|
}
|
@@ -14,6 +14,11 @@ class Component extends Firefly\Database\SingleTableInheritanceEntity
|
|||||||
protected $table = 'components';
|
protected $table = 'components';
|
||||||
protected $subclassField = 'class';
|
protected $subclassField = 'class';
|
||||||
|
|
||||||
|
public static $factory = [
|
||||||
|
'name' => 'string',
|
||||||
|
'user_id' => 'factory|User',
|
||||||
|
];
|
||||||
|
|
||||||
public function transactions()
|
public function transactions()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('Transaction');
|
return $this->belongsToMany('Transaction');
|
||||||
|
@@ -11,6 +11,13 @@ class Transaction extends Elegant
|
|||||||
'amount' => 'required|between:-65536,65536',
|
'amount' => 'required|between:-65536,65536',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static $factory
|
||||||
|
= [
|
||||||
|
'account_id' => 'factory|Account',
|
||||||
|
'transaction_journal_id' => 'factory|TransactionJournal',
|
||||||
|
'description' => 'string',
|
||||||
|
'amount' => 'integer:5'
|
||||||
|
];
|
||||||
|
|
||||||
public function account()
|
public function account()
|
||||||
{
|
{
|
||||||
@@ -31,6 +38,7 @@ class Transaction extends Elegant
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany('Budget');
|
return $this->belongsToMany('Budget');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function categories()
|
public function categories()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('Category');
|
return $this->belongsToMany('Category');
|
||||||
|
@@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class TransactionCurrency extends Eloquent {
|
class TransactionCurrency extends Eloquent
|
||||||
|
{
|
||||||
|
|
||||||
public function transactionJournals() {
|
public static $factory
|
||||||
|
= [
|
||||||
|
'code' => 'string'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function transactionJournals()
|
||||||
|
{
|
||||||
return $this->hasMany('TransactionJournal');
|
return $this->hasMany('TransactionJournal');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,6 +13,15 @@ class TransactionJournal extends Elegant
|
|||||||
'completed' => 'required|between:0,1'
|
'completed' => 'required|between:0,1'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static $factory
|
||||||
|
= [
|
||||||
|
'transaction_type_id' => 'factory|TransactionType',
|
||||||
|
'transaction_currency_id' => 'factory|TransactionCurrency',
|
||||||
|
'description' => 'string',
|
||||||
|
'completed' => '1',
|
||||||
|
'date' => 'date|Y-m-d'
|
||||||
|
];
|
||||||
|
|
||||||
public function transactionType()
|
public function transactionType()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('TransactionType');
|
return $this->belongsTo('TransactionType');
|
||||||
@@ -35,12 +44,16 @@ class TransactionJournal extends Elegant
|
|||||||
|
|
||||||
public function budgets()
|
public function budgets()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('Budget','component_transaction_journal','transaction_journal_id','component_id');
|
return $this->belongsToMany(
|
||||||
|
'Budget', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function categories()
|
public function categories()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('Category','component_transaction_journal','transaction_journal_id','component_id');
|
return $this->belongsToMany(
|
||||||
|
'Category', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDates()
|
public function getDates()
|
||||||
@@ -48,10 +61,13 @@ class TransactionJournal extends Elegant
|
|||||||
return array('created_at', 'updated_at', 'date');
|
return array('created_at', 'updated_at', 'date');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeAfter($query, \Carbon\Carbon $date) {
|
public function scopeAfter($query, \Carbon\Carbon $date)
|
||||||
|
{
|
||||||
return $query->where('date', '>=', $date->format('Y-m-d'));
|
return $query->where('date', '>=', $date->format('Y-m-d'));
|
||||||
}
|
}
|
||||||
public function scopeBefore($query, \Carbon\Carbon $date) {
|
|
||||||
|
public function scopeBefore($query, \Carbon\Carbon $date)
|
||||||
|
{
|
||||||
return $query->where('date', '<=', $date->format('Y-m-d'));
|
return $query->where('date', '<=', $date->format('Y-m-d'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,4 +6,8 @@ class TransactionType extends Eloquent {
|
|||||||
return $this->hasMany('TransactionJournal');
|
return $this->hasMany('TransactionJournal');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static $factory = [
|
||||||
|
'type' => 'string'
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
@@ -52,4 +52,36 @@ class AllModelsTest extends TestCase
|
|||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction journal tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function testTransactionJournals() {
|
||||||
|
$tj = FactoryMuff::create('TransactionJournal');
|
||||||
|
|
||||||
|
$t1 = FactoryMuff::create('Transaction');
|
||||||
|
$t2 = FactoryMuff::create('Transaction');
|
||||||
|
$t3 = FactoryMuff::create('Transaction');
|
||||||
|
|
||||||
|
$tj->transactions()->save($t1);
|
||||||
|
$tj->transactions()->save($t2);
|
||||||
|
$tj->transactions()->save($t3);
|
||||||
|
|
||||||
|
$budget = FactoryMuff::create('Budget');
|
||||||
|
$category = FactoryMuff::create('Category');
|
||||||
|
|
||||||
|
$tj->components()->save($budget);
|
||||||
|
$tj->components()->save($category);
|
||||||
|
|
||||||
|
$this->assertCount(2,$tj->components()->get());
|
||||||
|
$this->assertCount(1,$tj->budgets()->get());
|
||||||
|
$this->assertCount(1,$tj->categories()->get());
|
||||||
|
|
||||||
|
$this->assertCount(3,$tj->transactions()->get());
|
||||||
|
|
||||||
|
$this->assertEquals($tj->transaction_type_id,$tj->transactionType()->first()->id);
|
||||||
|
$this->assertEquals($tj->transaction_currency_id,$tj->transactionCurrency()->first()->id);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user