mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 04:21:20 +00:00
222 lines
7.1 KiB
PHP
222 lines
7.1 KiB
PHP
<?php
|
|
use FireflyIII\Models\Reminder;
|
|
use FireflyIII\Models\Transaction;
|
|
use FireflyIII\Models\TransactionJournal;
|
|
use FireflyIII\Repositories\Journal\JournalRepository;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
|
|
*/
|
|
class JournalRepositoryTest extends TestCase
|
|
{
|
|
/**
|
|
* @var JournalRepository
|
|
*/
|
|
protected $object;
|
|
|
|
/**
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
* This method is called before a test is executed.
|
|
*/
|
|
public function setUp()
|
|
{
|
|
$this->object = new JournalRepository;
|
|
parent::setUp();
|
|
}
|
|
|
|
/**
|
|
* 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\Repositories\Journal\JournalRepository::deactivateReminder
|
|
*/
|
|
public function testDeactivateReminder()
|
|
{
|
|
$reminder = FactoryMuffin::create('FireflyIII\Models\Reminder');
|
|
$reminder->active = 1;
|
|
$reminder->save();
|
|
$this->be($reminder->user);
|
|
|
|
$this->object->deactivateReminder($reminder->id);
|
|
|
|
$this->assertEquals(1, Reminder::where('id', $reminder->id)->where('active', 0)->count());
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::delete
|
|
*/
|
|
public function testDelete()
|
|
{
|
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
$transaction = Transaction::create(
|
|
[
|
|
'account_id' => $account->id,
|
|
'transaction_journal_id' => $journal->id,
|
|
'amount' => 100,
|
|
]
|
|
);
|
|
|
|
$this->object->delete($journal);
|
|
|
|
$this->assertEquals(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->count());
|
|
$this->assertEquals(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->count());
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::first
|
|
*/
|
|
public function testFirst()
|
|
{
|
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
$this->be($journal->user);
|
|
|
|
$first = $this->object->first();
|
|
|
|
$this->assertEquals($journal->id, $first->id);
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::getAmountBefore
|
|
*/
|
|
public function testGetAmountBefore()
|
|
{
|
|
$transaction = FactoryMuffin::create('FireflyIII\Models\Transaction');
|
|
$before = $this->object->getAmountBefore($transaction->transactionjournal, $transaction);
|
|
|
|
$this->assertEquals(0, $before);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfType
|
|
*/
|
|
public function testGetJournalsOfType()
|
|
{
|
|
$user = FactoryMuffin::create('FireflyIII\User');
|
|
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
$this->be($user);
|
|
$result = $this->object->getJournalsOfType($type);
|
|
$this->assertCount(0, $result);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfTypes
|
|
*/
|
|
public function testGetJournalsOfTypes()
|
|
{
|
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
$user = FactoryMuffin::create('FireflyIII\User');
|
|
$this->be($user);
|
|
$types = ['Withdrawal', 'Expense'];
|
|
$set = $this->object->getJournalsOfTypes($types, 0, 1);
|
|
|
|
$this->assertTrue($set instanceof LengthAwarePaginator);
|
|
$this->assertEquals(1, $set->currentPage());
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::getTransactionType
|
|
*/
|
|
public function testGetTransactionType()
|
|
{
|
|
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
$otherType = $this->object->getTransactionType($type->type);
|
|
$this->assertEquals($type->id, $otherType->id);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::getWithDate
|
|
*/
|
|
public function testGetWithDate()
|
|
{
|
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
$this->be($journal->user);
|
|
|
|
$found = $this->object->getWithDate($journal->id, $journal->date);
|
|
|
|
$this->assertEquals($journal->id, $found->id);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::saveTags
|
|
*/
|
|
public function testSaveTags()
|
|
{
|
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
$tags = ['one', 'two', 'three'];
|
|
$this->be($journal->user);
|
|
|
|
$this->object->saveTags($journal, $tags);
|
|
|
|
$this->assertCount(3, $journal->tags()->get());
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
|
|
*/
|
|
public function testStore()
|
|
{
|
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
$user = FactoryMuffin::create('FireflyIII\User');
|
|
$data = [
|
|
'description' => 'Some journal ' . rand(1, 100),
|
|
'user' => $user->id,
|
|
'what' => 'withdrawal',
|
|
'amount_currency_id' => $currency->id,
|
|
'account_id' => $account1->id,
|
|
'expense_account' => 'Some expense account',
|
|
'date' => '2014-01-01',
|
|
'category' => 'Some category',
|
|
'budget_id' => $budget->id,
|
|
'amount' => 100,
|
|
'tags' => ['one', 'two', 'three']
|
|
|
|
|
|
];
|
|
|
|
$journal = $this->object->store($data);
|
|
|
|
$this->assertEquals($data['description'], $journal->description);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::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.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Journal\JournalRepository::updateTags
|
|
* @todo Implement testUpdateTags().
|
|
*/
|
|
public function testUpdateTags()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
}
|