mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Tag repository tests
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Tag\TagRepository;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
|
||||
@@ -31,27 +34,298 @@ class TagRepositoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Already connected tag and transaction journal returns FALSE.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @todo Implement testConnect().
|
||||
*/
|
||||
public function testConnect()
|
||||
public function testConnectAlreadyConnected()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$journal->tags()->save($tag);
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A deposit cannot be connected to a balancing act.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectBalancingOneDeposit()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $deposit->id;
|
||||
$tag->tagMode = 'balancingAct';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connecting a single transfer to a balancing act is possible if there are no
|
||||
* other transfers already connected.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectBalancingOneTransfer()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $transfer->id;
|
||||
$tag->tagMode = 'balancingAct';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connecting a single withdrawal to a balancing act is possible if there are
|
||||
* not other withdrawals already connected.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectBalancingOneWithdrawal()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $withdrawal->id;
|
||||
$tag->tagMode = 'balancingAct';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectDefault()
|
||||
{
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'nothing';
|
||||
$tag->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Once one or more journals have been accepted by the tag, others must match the asset account
|
||||
* id. For this to work, we must also create an asset account, and a transaction.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectPaymentMultipleMatch()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
|
||||
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$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]);
|
||||
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal1->transaction_type_id = $withdrawal->id;
|
||||
$journal2->transaction_type_id = $deposit->id;
|
||||
$tag->tagMode = 'advancePayment';
|
||||
$account->account_type_id = $asset->id;
|
||||
|
||||
$tag->save();
|
||||
$journal1->save();
|
||||
$journal2->save();
|
||||
$account->save();
|
||||
// connect journal1:
|
||||
$journal1->tags()->save($tag);
|
||||
|
||||
$result = $this->object->connect($journal2, $tag);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Once one or more journals have been accepted by the tag, others must match the asset account
|
||||
* id. For this to work, we must also create an asset account, and a transaction.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectPaymentNoMatch()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
|
||||
|
||||
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
|
||||
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$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]);
|
||||
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal1->transaction_type_id = $withdrawal->id;
|
||||
$journal2->transaction_type_id = $deposit->id;
|
||||
$tag->tagMode = 'advancePayment';
|
||||
$account1->account_type_id = $asset->id;
|
||||
$account2->account_type_id = $asset->id;
|
||||
|
||||
$tag->save();
|
||||
$journal1->save();
|
||||
$journal2->save();
|
||||
$account1->save();
|
||||
$account2->save();
|
||||
// connect journal1:
|
||||
$journal1->tags()->save($tag);
|
||||
|
||||
$result = $this->object->connect($journal2, $tag);
|
||||
// account1 and account2 are different, so false:
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An advance payment accepts no transfers
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectPaymentOneTransfer()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $transfer->id;
|
||||
$tag->tagMode = 'advancePayment';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An advance payment accepts only one withdrawal, not two.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectPaymentOneWithdrawal()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $withdrawal->id;
|
||||
$tag->tagMode = 'advancePayment';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertTrue($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An advance payment accepts only one withdrawal, not two.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectPaymentTwoWithdrawals()
|
||||
{
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$otherJournal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
$journal->transaction_type_id = $withdrawal->id;
|
||||
$otherJournal->transaction_type_id = $withdrawal->id;
|
||||
$tag->tagMode = 'advancePayment';
|
||||
|
||||
$tag->save();
|
||||
$journal->save();
|
||||
$otherJournal->save();
|
||||
$otherJournal->tags()->save($tag);
|
||||
|
||||
$result = $this->object->connect($journal, $tag);
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::destroy
|
||||
* @todo Implement testDestroy().
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$this->object->destroy($tag);
|
||||
|
||||
$this->assertCount(0, Tag::where('id', $tag->id)->whereNull('deleted_at')->get());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,33 +334,68 @@ class TagRepositoryTest extends TestCase
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$tag1 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag1->tag = 'BBB';
|
||||
$tag2->tag = 'AAA';
|
||||
$tag1->user_id = $user->id;
|
||||
$tag2->user_id = $user->id;
|
||||
|
||||
$tag1->save();
|
||||
$tag2->save();
|
||||
|
||||
$this->be($user);
|
||||
|
||||
$set = $this->object->get();
|
||||
|
||||
$this->assertCount(2, $set);
|
||||
$this->assertEquals('AAA', $set->first()->tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::store
|
||||
* @todo Implement testStore().
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
|
||||
$data = [
|
||||
'tag' => 'Hello' . rand(1, 100),
|
||||
'date' => '2012-01-01',
|
||||
'description' => 'Some',
|
||||
'latitude' => 12,
|
||||
'longitude' => 13,
|
||||
'zoomLevel' => 4,
|
||||
'tagMode' => 'nothing'
|
||||
];
|
||||
$this->be($user);
|
||||
|
||||
$tag = $this->object->store($data);
|
||||
$this->assertEquals($data['tag'], $tag->tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::update
|
||||
* @todo Implement testUpdate().
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
|
||||
$data = [
|
||||
'tag' => 'Hello' . rand(1, 100),
|
||||
'date' => '2012-01-01',
|
||||
'description' => 'Some',
|
||||
'latitude' => 12,
|
||||
'longitude' => 13,
|
||||
'zoomLevel' => 4,
|
||||
'tagMode' => 'nothing'
|
||||
];
|
||||
$this->be($tag->user);
|
||||
|
||||
$newTag = $this->object->update($tag, $data);
|
||||
$this->assertEquals($data['tag'], $newTag->tag);
|
||||
$this->assertEquals($tag->id, $newTag->id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user