mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expanded some tests.
This commit is contained in:
parent
fea9bc4e7e
commit
d483005219
@ -8,6 +8,7 @@ use Closure;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Reminder;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
use View;
|
||||
@ -49,7 +50,8 @@ class Reminders
|
||||
{
|
||||
|
||||
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest()) {
|
||||
$user = $this->auth->user();
|
||||
if ($this->auth->check() && !$request->isXmlHttpRequest() && $user instanceof User) {
|
||||
// do reminders stuff.
|
||||
|
||||
// abuse CacheProperties to find out if we need to do this:
|
||||
@ -63,7 +65,7 @@ class Reminders
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
|
||||
$piggyBanks = $user->piggyBanks()->where('remind_me', 1)->get();
|
||||
|
||||
/** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */
|
||||
$helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface');
|
||||
@ -75,12 +77,11 @@ class Reminders
|
||||
// delete invalid reminders
|
||||
// this is a construction SQLITE cannot handle :(
|
||||
if (env('DB_CONNECTION') != 'sqlite') {
|
||||
Reminder::whereUserId($this->auth->user()->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')
|
||||
->whereNull('piggy_banks.id')->delete();
|
||||
Reminder::whereUserId($user->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->delete();
|
||||
}
|
||||
|
||||
// get and list active reminders:
|
||||
$reminders = $this->auth->user()->reminders()->today()->get();
|
||||
$reminders = $user->reminders()->today()->get();
|
||||
$reminders->each(
|
||||
function (Reminder $reminder) use ($helper) {
|
||||
$reminder->description = $helper->getReminderText($reminder);
|
||||
|
@ -9,7 +9,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class TagRepository
|
||||
@ -64,14 +63,15 @@ class TagRepository implements TagRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return integer
|
||||
* @return string
|
||||
*/
|
||||
public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
// the quickest way to do this is by scanning all balancingAct tags
|
||||
// because there will be less of them any way.
|
||||
$tags = Auth::user()->tags()->where('tagMode', 'balancingAct')->get();
|
||||
$amount = 0;
|
||||
$amount = '0';
|
||||
bcscale(2);
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
@ -80,7 +80,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($journal->destination_account->id == $account->id) {
|
||||
$amount += $journal->amount;
|
||||
$amount = bcadd($amount, $journal->amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ interface TagRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return float
|
||||
* @return string
|
||||
*/
|
||||
public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Tag\TagRepository;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
@ -54,6 +54,7 @@ class TagRepositoryTest extends TestCase
|
||||
* A deposit cannot be connected to a balancing act.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
|
||||
*/
|
||||
public function testConnectBalancingOneDeposit()
|
||||
{
|
||||
@ -80,6 +81,7 @@ class TagRepositoryTest extends TestCase
|
||||
* other transfers already connected.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
|
||||
*/
|
||||
public function testConnectBalancingOneTransfer()
|
||||
{
|
||||
@ -106,6 +108,7 @@ class TagRepositoryTest extends TestCase
|
||||
* not other withdrawals already connected.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
|
||||
*/
|
||||
public function testConnectBalancingOneWithdrawal()
|
||||
{
|
||||
@ -128,6 +131,8 @@ class TagRepositoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Default connection between a journal and a tag.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectDefault()
|
||||
@ -143,6 +148,8 @@ class TagRepositoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback for connect then the tag mode is unknown
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
*/
|
||||
public function testConnectInvalidType()
|
||||
@ -161,7 +168,11 @@ class TagRepositoryTest extends TestCase
|
||||
* 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.
|
||||
*
|
||||
* This covers an advance payment
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
|
||||
*/
|
||||
public function testConnectPaymentMultipleMatch()
|
||||
{
|
||||
@ -212,8 +223,12 @@ class TagRepositoryTest extends TestCase
|
||||
* 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.
|
||||
*
|
||||
* This covers the advance payment
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
|
||||
*/
|
||||
public function testConnectPaymentNoMatch()
|
||||
{
|
||||
@ -266,9 +281,11 @@ class TagRepositoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* An advance payment accepts no transfers
|
||||
* An advance payment accepts no transfers.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
|
||||
*/
|
||||
public function testConnectPaymentOneTransfer()
|
||||
{
|
||||
@ -294,6 +311,8 @@ class TagRepositoryTest extends TestCase
|
||||
* An advance payment accepts only one withdrawal, not two.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
|
||||
*/
|
||||
public function testConnectPaymentOneWithdrawal()
|
||||
{
|
||||
@ -319,6 +338,8 @@ class TagRepositoryTest extends TestCase
|
||||
* An advance payment accepts only one withdrawal, not two.
|
||||
*
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
|
||||
*/
|
||||
public function testConnectPaymentTwoWithdrawals()
|
||||
{
|
||||
@ -344,6 +365,68 @@ class TagRepositoryTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::coveredByBalancingActs
|
||||
*/
|
||||
public function testCoveredByBalancingActs()
|
||||
{
|
||||
// create a user:
|
||||
$user = FactoryMuffin::create('FireflyIII\User');
|
||||
$this->be($user);
|
||||
|
||||
// create transaction and account types:
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
|
||||
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType'); // expense
|
||||
FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset
|
||||
|
||||
// create two accounts:
|
||||
$fromAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset
|
||||
$toAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset
|
||||
$fromAccount->account_type_id = $asset->id;
|
||||
$toAccount->account_type_id = $asset->id;
|
||||
$fromAccount->save();
|
||||
$toAccount->save();
|
||||
|
||||
|
||||
// create a tag
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
$tag->tagMode = 'balancingAct';
|
||||
$tag->user_id = $user->id;
|
||||
$tag->save();
|
||||
|
||||
// date
|
||||
$today = new Carbon('2014-01-12');
|
||||
$start = new Carbon('2014-01-01');
|
||||
$end = new Carbon('2014-01-31');
|
||||
|
||||
// store five journals
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // deposit!
|
||||
// set date:
|
||||
$journal->date = $today;
|
||||
$journal->user_id = $user->id;
|
||||
$journal->transaction_type_id = $transfer->id;
|
||||
$journal->tags()->save($tag);
|
||||
$journal->save();
|
||||
|
||||
// update accounts:
|
||||
$journal->transactions[0]->account_id = $fromAccount->id;
|
||||
$journal->transactions[0]->amount = '-100';
|
||||
$journal->transactions[0]->save();
|
||||
$journal->transactions[1]->account_id = $toAccount->id;
|
||||
$journal->transactions[1]->amount = '100';
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
|
||||
$amount = $this->object->coveredByBalancingActs($toAccount, $start, $end);
|
||||
// five transactions, 100 each.
|
||||
$this->assertEquals('500', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Repositories\Tag\TagRepository::destroy
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user