mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Improve test coverage.
This commit is contained in:
@@ -105,10 +105,10 @@ class EditController extends Controller
|
|||||||
'times' => (string)trans('firefly.repeat_times'),
|
'times' => (string)trans('firefly.repeat_times'),
|
||||||
];
|
];
|
||||||
if (null !== $recurrence->repeat_until) {
|
if (null !== $recurrence->repeat_until) {
|
||||||
$repetitionEnd = 'until_date';
|
$repetitionEnd = 'until_date'; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
if ($recurrence->repetitions > 0) {
|
if ($recurrence->repetitions > 0) {
|
||||||
$repetitionEnd = 'times';
|
$repetitionEnd = 'times'; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$weekendResponses = [
|
$weekendResponses = [
|
||||||
|
@@ -63,10 +63,12 @@ class AccountController extends Controller
|
|||||||
$accountReport = $accountTasker->getAccountReport($accounts, $start, $end);
|
$accountReport = $accountTasker->getAccountReport($accounts, $start, $end);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.accounts', compact('accountReport'))->render();
|
$result = view('reports.partials.accounts', compact('accountReport'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -61,10 +61,12 @@ class BalanceController extends Controller
|
|||||||
$balance = $helper->getBalanceReport($accounts, $start, $end);
|
$balance = $helper->getBalanceReport($accounts, $start, $end);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.balance', compact('balance'))->render();
|
$result = view('reports.partials.balance', compact('balance'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -63,10 +63,12 @@ class BudgetController extends Controller
|
|||||||
$budgets = $helper->getBudgetReport($start, $end, $accounts);
|
$budgets = $helper->getBudgetReport($start, $end, $accounts);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.budgets', compact('budgets'))->render();
|
$result = view('reports.partials.budgets', compact('budgets'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -103,10 +105,12 @@ class BudgetController extends Controller
|
|||||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
|
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -67,10 +67,12 @@ class CategoryController extends Controller
|
|||||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
@@ -107,10 +109,12 @@ class CategoryController extends Controller
|
|||||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -160,10 +164,12 @@ class CategoryController extends Controller
|
|||||||
try {
|
try {
|
||||||
$result = view('reports.partials.categories', compact('report'))->render();
|
$result = view('reports.partials.categories', compact('report'))->render();
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@@ -107,10 +107,12 @@ class ExpenseController extends Controller
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.exp-budgets', compact('together'))->render();
|
$result = view('reports.partials.exp-budgets', compact('together'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::budget: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::budget: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -170,10 +172,12 @@ class ExpenseController extends Controller
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.exp-categories', compact('together'))->render();
|
$result = view('reports.partials.exp-categories', compact('together'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -220,10 +224,12 @@ class ExpenseController extends Controller
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.exp-not-grouped', compact('result'))->render();
|
$result = view('reports.partials.exp-not-grouped', compact('result'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -271,10 +277,12 @@ class ExpenseController extends Controller
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::topExpense: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::topExpense: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -320,10 +328,12 @@ class ExpenseController extends Controller
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error(sprintf('Could not render category::topIncome: %s', $e->getMessage()));
|
Log::error(sprintf('Could not render category::topIncome: %s', $e->getMessage()));
|
||||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -81,10 +81,12 @@ class OperationsController extends Controller
|
|||||||
$type = 'expense-entry';
|
$type = 'expense-entry';
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -114,10 +116,12 @@ class OperationsController extends Controller
|
|||||||
$type = 'income-entry';
|
$type = 'income-entry';
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
@@ -166,10 +170,12 @@ class OperationsController extends Controller
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.operations', compact('incomeSum', 'expensesSum'))->render();
|
$result = view('reports.partials.operations', compact('incomeSum', 'expensesSum'))->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::debug(sprintf('Could not render reports.partials.operations: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.operations: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
$cache->store($result);
|
$cache->store($result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -258,10 +258,13 @@ class CreateController extends Controller
|
|||||||
'count' => $index + 1,
|
'count' => $index + 1,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
|
||||||
Log::debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
|
Log::debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
|
||||||
Log::debug($e->getTraceAsString());
|
Log::debug($e->getTraceAsString());
|
||||||
$string = '';
|
$string = '';
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
if ('' !== $string) {
|
if ('' !== $string) {
|
||||||
$result[] = $string;
|
$result[] = $string;
|
||||||
|
@@ -49,7 +49,8 @@ class CronController
|
|||||||
*/
|
*/
|
||||||
private function runRecurring(): string
|
private function runRecurring(): string
|
||||||
{
|
{
|
||||||
$recurring = new RecurringCronjob;
|
/** @var RecurringCronjob $recurring */
|
||||||
|
$recurring = app(RecurringCronjob::class);
|
||||||
try {
|
try {
|
||||||
$result = $recurring->fire();
|
$result = $recurring->fire();
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
|
@@ -118,7 +118,7 @@ class RecurrenceFormRequest extends Request
|
|||||||
// fill in source and destination account data
|
// fill in source and destination account data
|
||||||
switch ($this->string('transaction_type')) {
|
switch ($this->string('transaction_type')) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
|
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type'))); // @codeCoverageIgnore
|
||||||
case 'withdrawal':
|
case 'withdrawal':
|
||||||
$return['transactions'][0]['source_id'] = $this->integer('source_id');
|
$return['transactions'][0]['source_id'] = $this->integer('source_id');
|
||||||
$return['transactions'][0]['destination_name'] = $this->string('destination_name');
|
$return['transactions'][0]['destination_name'] = $this->string('destination_name');
|
||||||
@@ -227,8 +227,6 @@ class RecurrenceFormRequest extends Request
|
|||||||
$rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,' . $recurrence->id;
|
$rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,' . $recurrence->id;
|
||||||
$rules['first_date'] = 'required|date';
|
$rules['first_date'] = 'required|date';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,9 +28,7 @@ use FireflyIII\Exceptions\FireflyException;
|
|||||||
use FireflyIII\Helpers\Collector\TransactionCollector;
|
use FireflyIII\Helpers\Collector\TransactionCollector;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -46,7 +44,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Passport::actingAs($this->user());
|
Passport::actingAs($this->user());
|
||||||
@@ -1329,16 +1327,8 @@ class TransactionControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowDeposit(): void
|
public function testShowDeposit(): void
|
||||||
{
|
{
|
||||||
$loop = 0;
|
$deposit = $this->getRandomDeposit();
|
||||||
do {
|
$transaction = $deposit->transactions()->first();
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
$transaction = $journal->transactions()->first();
|
|
||||||
|
|
||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
$accountRepos->shouldReceive('getAccountsByType')
|
$accountRepos->shouldReceive('getAccountsByType')
|
||||||
@@ -1350,7 +1340,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
$collector->setUser($this->user());
|
$collector->setUser($this->user());
|
||||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||||
$collector->setAllAssetAccounts();
|
$collector->setAllAssetAccounts();
|
||||||
$collector->setJournals(new Collection([$journal]));
|
$collector->setJournals(new Collection([$deposit]));
|
||||||
$collector->setLimit(5)->setPage(1);
|
$collector->setLimit(5)->setPage(1);
|
||||||
$transactions = $collector->getTransactions();
|
$transactions = $collector->getTransactions();
|
||||||
|
|
||||||
@@ -1374,7 +1364,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
[
|
[
|
||||||
'data' => [[
|
'data' => [[
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
'description' => $journal->description,
|
'description' => $deposit->description,
|
||||||
'type' => 'Deposit',
|
'type' => 'Deposit',
|
||||||
],
|
],
|
||||||
]],
|
]],
|
||||||
@@ -1393,15 +1383,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowWithdrawal(): void
|
public function testShowWithdrawal(): void
|
||||||
{
|
{
|
||||||
$loop = 0;
|
$journal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
// this is kind of cheating but OK.
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
$transaction = $journal->transactions()->first();
|
$transaction = $journal->transactions()->first();
|
||||||
$transaction->description = null;
|
$transaction->description = null;
|
||||||
$transaction->save();
|
$transaction->save();
|
||||||
@@ -2441,7 +2423,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
|
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'description' => 'Some deposit #' . random_int(1, 10000),
|
'description' => 'Some deposit #' . random_int(1, 10000),
|
||||||
'date' => '2018-01-01',
|
'date' => '2018-01-01',
|
||||||
'transactions' => [
|
'transactions' => [
|
||||||
@@ -2452,12 +2434,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
do {
|
$deposit = $this->getRandomDeposit();
|
||||||
/** @var TransactionJournal $deposit */
|
|
||||||
$deposit = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->first();
|
|
||||||
$count = $deposit->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$transaction = $deposit->transactions()->first();
|
$transaction = $deposit->transactions()->first();
|
||||||
$repository->shouldReceive('setUser');
|
$repository->shouldReceive('setUser');
|
||||||
$repository->shouldReceive('update')->andReturn($deposit)->once();
|
$repository->shouldReceive('update')->andReturn($deposit)->once();
|
||||||
@@ -2494,13 +2471,8 @@ class TransactionControllerTest extends TestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $withdrawal */
|
|
||||||
$withdrawal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
|
|
||||||
$count = $withdrawal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
|
|
||||||
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$transaction = $withdrawal->transactions()->first();
|
$transaction = $withdrawal->transactions()->first();
|
||||||
$repository->shouldReceive('setUser');
|
$repository->shouldReceive('setUser');
|
||||||
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
|
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
|
||||||
|
@@ -28,6 +28,7 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -74,35 +75,189 @@ class CreateControllerTest extends TestCase
|
|||||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$tomorrow = Carbon::create()->addDays(2);
|
$tomorrow = Carbon::create()->addDays(2);
|
||||||
$recurrence = $this->user()->recurrences()->first();
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
$data = [
|
$data = [
|
||||||
'title' => 'hello',
|
'title' => 'hello' . random_int(1, 100000),
|
||||||
'first_date' => $tomorrow->format('Y-m-d'),
|
'first_date' => $tomorrow->format('Y-m-d'),
|
||||||
'repetition_type' => 'daily',
|
'repetition_type' => 'daily',
|
||||||
'skip' => 0,
|
'skip' => 0,
|
||||||
'recurring_description' => 'Some descr',
|
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||||
'active' => '1',
|
'active' => '1',
|
||||||
'apply_rules' => '1',
|
'apply_rules' => '1',
|
||||||
|
'foreign_amount' => '1',
|
||||||
|
'foreign_currency_id' => '2',
|
||||||
|
|
||||||
// mandatory for transaction:
|
// mandatory for transaction:
|
||||||
'transaction_description' => 'Some descr',
|
'transaction_description' => 'Some descr',
|
||||||
'transaction_type' => 'withdrawal',
|
'transaction_type' => 'withdrawal',
|
||||||
'transaction_currency_id' => '1',
|
'transaction_currency_id' => '1',
|
||||||
'amount' => '30',
|
'amount' => '30',
|
||||||
|
|
||||||
// mandatory account info:
|
// mandatory account info:
|
||||||
'source_id' => '1',
|
'source_id' => '1',
|
||||||
'source_name' => '',
|
|
||||||
'destination_id' => '',
|
|
||||||
'destination_name' => 'Some Expense',
|
'destination_name' => 'Some Expense',
|
||||||
|
|
||||||
// optional fields:
|
// optional fields:
|
||||||
'budget_id' => '1',
|
'budget_id' => '1',
|
||||||
'category' => 'CategoryA',
|
'category' => 'CategoryA',
|
||||||
'tags' => 'A,B,C',
|
'tags' => 'A,B,C',
|
||||||
|
'create_another' => '1',
|
||||||
|
'repetition_end' => 'times',
|
||||||
|
'repetitions' => 3,
|
||||||
|
];
|
||||||
|
|
||||||
'repetition_end' => 'times',
|
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||||
'repetitions' => 3,
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('recurring.store'), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||||
|
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||||
|
*/
|
||||||
|
public function testStoreDeposit(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$tomorrow = Carbon::create()->addDays(2);
|
||||||
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
|
$data = [
|
||||||
|
'title' => 'hello' . random_int(1, 100000),
|
||||||
|
'first_date' => $tomorrow->format('Y-m-d'),
|
||||||
|
'repetition_type' => 'daily',
|
||||||
|
'skip' => 0,
|
||||||
|
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||||
|
'active' => '1',
|
||||||
|
'apply_rules' => '1',
|
||||||
|
'foreign_amount' => '1',
|
||||||
|
'foreign_currency_id' => '2',
|
||||||
|
|
||||||
|
// mandatory for transaction:
|
||||||
|
'transaction_description' => 'Some descr',
|
||||||
|
'transaction_type' => 'deposit',
|
||||||
|
'transaction_currency_id' => '1',
|
||||||
|
'amount' => '30',
|
||||||
|
|
||||||
|
// mandatory account info:
|
||||||
|
'source_id' => '2',
|
||||||
|
'source_name' => 'Some source',
|
||||||
|
'destination_id' => '1',
|
||||||
|
'destination_name' => 'Some Expense',
|
||||||
|
|
||||||
|
// optional fields:
|
||||||
|
'budget_id' => '1',
|
||||||
|
'category' => 'CategoryA',
|
||||||
|
'tags' => 'A,B,C',
|
||||||
|
'create_another' => '1',
|
||||||
|
'repetition_end' => 'times',
|
||||||
|
'repetitions' => 3,
|
||||||
|
];
|
||||||
|
|
||||||
|
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('recurring.store'), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||||
|
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||||
|
*/
|
||||||
|
public function testStoreTransfer(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$tomorrow = Carbon::create()->addDays(2);
|
||||||
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
|
$data = [
|
||||||
|
'title' => 'hello' . random_int(1, 100000),
|
||||||
|
'first_date' => $tomorrow->format('Y-m-d'),
|
||||||
|
'repetition_type' => 'daily',
|
||||||
|
'skip' => 0,
|
||||||
|
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||||
|
'active' => '1',
|
||||||
|
'apply_rules' => '1',
|
||||||
|
'foreign_amount' => '1',
|
||||||
|
'foreign_currency_id' => '2',
|
||||||
|
|
||||||
|
// mandatory for transaction:
|
||||||
|
'transaction_description' => 'Some descr',
|
||||||
|
'transaction_type' => 'transfer',
|
||||||
|
'transaction_currency_id' => '1',
|
||||||
|
'amount' => '30',
|
||||||
|
|
||||||
|
// mandatory account info:
|
||||||
|
'source_id' => '2',
|
||||||
|
'source_name' => 'Some source',
|
||||||
|
'destination_id' => '1',
|
||||||
|
'destination_name' => 'Some Expense',
|
||||||
|
|
||||||
|
// optional fields:
|
||||||
|
'budget_id' => '1',
|
||||||
|
'category' => 'CategoryA',
|
||||||
|
'tags' => 'A,B,C',
|
||||||
|
'create_another' => '1',
|
||||||
|
'repetition_end' => 'times',
|
||||||
|
'repetitions' => 3,
|
||||||
|
];
|
||||||
|
|
||||||
|
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('recurring.store'), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||||
|
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||||
|
*/
|
||||||
|
public function testStoreUntilDate(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
|
$tomorrow = Carbon::create()->addDays(2);
|
||||||
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
|
$data = [
|
||||||
|
'title' => 'hello' . random_int(1, 100000),
|
||||||
|
'first_date' => $tomorrow->format('Y-m-d'),
|
||||||
|
'repetition_type' => 'daily',
|
||||||
|
'skip' => 0,
|
||||||
|
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||||
|
'active' => '1',
|
||||||
|
'apply_rules' => '1',
|
||||||
|
'foreign_amount' => '1',
|
||||||
|
'foreign_currency_id' => '2',
|
||||||
|
|
||||||
|
// mandatory for transaction:
|
||||||
|
'transaction_description' => 'Some descr',
|
||||||
|
'transaction_type' => 'withdrawal',
|
||||||
|
'transaction_currency_id' => '1',
|
||||||
|
'amount' => '30',
|
||||||
|
|
||||||
|
// mandatory account info:
|
||||||
|
'source_id' => '1',
|
||||||
|
'destination_name' => 'Some Expense',
|
||||||
|
|
||||||
|
// optional fields:
|
||||||
|
'budget_id' => '1',
|
||||||
|
'category' => 'CategoryA',
|
||||||
|
'tags' => 'A,B,C',
|
||||||
|
'create_another' => '1',
|
||||||
|
'repetition_end' => 'until_date',
|
||||||
|
'repeat_until' => $tomorrow->format('Y-m-d'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||||
|
77
tests/Feature/Controllers/Recurring/DeleteControllerTest.php
Normal file
77
tests/Feature/Controllers/Recurring/DeleteControllerTest.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* DeleteControllerTest.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Controllers\Recurring;
|
||||||
|
|
||||||
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class DeleteControllerTest
|
||||||
|
*/
|
||||||
|
class DeleteControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
|
||||||
|
*/
|
||||||
|
public function testDelete(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$recurringRepos->shouldReceive('getTransactions')->andReturn(new Collection())->once();
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('recurring.delete', [1]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
|
||||||
|
*/
|
||||||
|
public function testDestroy(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$recurringRepos->shouldReceive('destroy')->once();
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('recurring.destroy', [1]));
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
125
tests/Feature/Controllers/Recurring/EditControllerTest.php
Normal file
125
tests/Feature/Controllers/Recurring/EditControllerTest.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* EditControllerTest.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Controllers\Recurring;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class EditControllerTest
|
||||||
|
*/
|
||||||
|
class EditControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
||||||
|
*/
|
||||||
|
public function testEdit(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
$recurringRepos->shouldReceive('setUser');
|
||||||
|
$recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
|
||||||
|
$recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
|
||||||
|
$recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
|
||||||
|
$budgetRepos->shouldReceive('findNull')->andReturn($this->user()->budgets()->first());
|
||||||
|
|
||||||
|
|
||||||
|
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
||||||
|
//\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('recurring.edit', [1]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
||||||
|
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||||
|
*/
|
||||||
|
public function testUpdate(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
|
||||||
|
$recurringRepos->shouldReceive('update')->once();
|
||||||
|
|
||||||
|
$tomorrow = Carbon::create()->addDays(2);
|
||||||
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
|
$data = [
|
||||||
|
'id' => $recurrence->id,
|
||||||
|
'title' => 'hello',
|
||||||
|
'first_date' => $tomorrow->format('Y-m-d'),
|
||||||
|
'repetition_type' => 'daily',
|
||||||
|
'skip' => 0,
|
||||||
|
'recurring_description' => 'Some descr',
|
||||||
|
'active' => '1',
|
||||||
|
'apply_rules' => '1',
|
||||||
|
'return_to_edit' => '1',
|
||||||
|
// mandatory for transaction:
|
||||||
|
'transaction_description' => 'Some descr',
|
||||||
|
'transaction_type' => 'withdrawal',
|
||||||
|
'transaction_currency_id' => '1',
|
||||||
|
'amount' => '30',
|
||||||
|
// mandatory account info:
|
||||||
|
'source_id' => '1',
|
||||||
|
'source_name' => '',
|
||||||
|
'destination_id' => '',
|
||||||
|
'destination_name' => 'Some Expense',
|
||||||
|
|
||||||
|
// optional fields:
|
||||||
|
'budget_id' => '1',
|
||||||
|
'category' => 'CategoryA',
|
||||||
|
'tags' => 'A,B,C',
|
||||||
|
'create_another' => '1',
|
||||||
|
'repetition_end' => 'times',
|
||||||
|
'repetitions' => 3,
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('recurring.update', [1]), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
97
tests/Feature/Controllers/Recurring/IndexControllerTest.php
Normal file
97
tests/Feature/Controllers/Recurring/IndexControllerTest.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* IndexControllerTest.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Controllers\Recurring;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Configuration;
|
||||||
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class IndexControllerTest
|
||||||
|
*/
|
||||||
|
class IndexControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
|
||||||
|
*/
|
||||||
|
public function testIndex(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
|
||||||
|
$config = new Configuration;
|
||||||
|
$config->data = 0;
|
||||||
|
|
||||||
|
$falseConfig = new Configuration;
|
||||||
|
$falseConfig->data = false;
|
||||||
|
|
||||||
|
$collection = $this->user()->recurrences()->take(2)->get();
|
||||||
|
|
||||||
|
// mock cron job config:
|
||||||
|
\FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
|
||||||
|
\FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||||
|
|
||||||
|
$repository->shouldReceive('get')->andReturn($collection)->once();
|
||||||
|
$repository->shouldReceive('setUser');
|
||||||
|
$repository->shouldReceive('getNoteText')->andReturn('Notes');
|
||||||
|
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
|
||||||
|
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('recurring.index'));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShow(): void
|
||||||
|
{
|
||||||
|
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$recurrence = $this->user()->recurrences()->first();
|
||||||
|
$repository->shouldReceive('setUser');
|
||||||
|
$repository->shouldReceive('getNoteText')->andReturn('Notes');
|
||||||
|
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
|
||||||
|
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||||
|
$repository->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('recurring.show', [$recurrence->id]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -231,7 +231,6 @@ class ExpenseControllerTest extends TestCase
|
|||||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('getTransactions')->andReturn($collection);
|
$collector->shouldReceive('getTransactions')->andReturn($collection);
|
||||||
//$collector->shouldReceive('')->andReturnSelf();
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
|
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
|
||||||
@@ -248,6 +247,36 @@ class ExpenseControllerTest extends TestCase
|
|||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||||
|
|
||||||
|
// fake collection:
|
||||||
|
$transA = new Transaction;
|
||||||
|
$transA->transaction_currency_id = 1;
|
||||||
|
$transA->transaction_category_name = 'Category';
|
||||||
|
$transA->transaction_category_id = 1;
|
||||||
|
$transA->transaction_currency_symbol = 'A';
|
||||||
|
$transA->transaction_currency_dp = 2;
|
||||||
|
$transA->transaction_amount = '100';
|
||||||
|
$transA->opposing_account_id = $expense->id;
|
||||||
|
$transB = new Transaction;
|
||||||
|
$transB->transaction_currency_id = 2;
|
||||||
|
$transB->transaction_category_name = null;
|
||||||
|
$transB->transaction_category_id = 0;
|
||||||
|
$transB->transaction_journal_budget_name = 'Category2';
|
||||||
|
$transB->transaction_journal_budget_id = 2;
|
||||||
|
$transB->transaction_currency_symbol = 'A';
|
||||||
|
$transB->transaction_currency_dp = 2;
|
||||||
|
$transB->transaction_amount = '100';
|
||||||
|
$transB->opposing_account_id = $expense->id;
|
||||||
|
$collection = new Collection([$transA, $transB]);
|
||||||
|
|
||||||
|
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getTransactions')->andReturn($collection);
|
||||||
|
//$collector->shouldReceive('')->andReturnSelf();
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
|
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
@@ -63,6 +63,23 @@ class CreateControllerTest extends TestCase
|
|||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||||
|
*/
|
||||||
|
public function testCreateFromBill(): void
|
||||||
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->get(route('rules.create-from-bill', [1,1]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||||
*/
|
*/
|
||||||
|
117
tests/Feature/Controllers/System/CronControllerTest.php
Normal file
117
tests/Feature/Controllers/System/CronControllerTest.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CronControllerTest.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Controllers\System;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
use Mockery;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class CronControllerTest
|
||||||
|
*/
|
||||||
|
class CronControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||||
|
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||||
|
*/
|
||||||
|
public function testCron(): void
|
||||||
|
{
|
||||||
|
$users = new Collection([$this->user()]);
|
||||||
|
$job = $this->mock(RecurringCronjob::class);
|
||||||
|
$preference = new Preference();
|
||||||
|
$preference->data = 'token';
|
||||||
|
$job->shouldReceive('fire')->once()->andReturn(true);
|
||||||
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('all')->andReturn($users);
|
||||||
|
\Preferences::shouldReceive('getForUser')
|
||||||
|
->withArgs([Mockery::any(), 'access_token', null])
|
||||||
|
->andReturn($preference)->once();
|
||||||
|
$response = $this->get(route('cron.cron', ['token']));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('The recurring transaction cron job fired successfully.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||||
|
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||||
|
*/
|
||||||
|
public function testCronException(): void
|
||||||
|
{
|
||||||
|
$users = new Collection([$this->user()]);
|
||||||
|
$job = $this->mock(RecurringCronjob::class);
|
||||||
|
$preference = new Preference();
|
||||||
|
$preference->data = 'token';
|
||||||
|
$job->shouldReceive('fire')->once()->andThrow(new FireflyException('Exception noted.'));
|
||||||
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('all')->andReturn($users);
|
||||||
|
\Preferences::shouldReceive('getForUser')
|
||||||
|
->withArgs([Mockery::any(), 'access_token', null])
|
||||||
|
->andReturn($preference)->once();
|
||||||
|
$response = $this->get(route('cron.cron', ['token']));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('Exception noted.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||||
|
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||||
|
*/
|
||||||
|
public function testCronFalse(): void
|
||||||
|
{
|
||||||
|
$users = new Collection([$this->user()]);
|
||||||
|
$job = $this->mock(RecurringCronjob::class);
|
||||||
|
$preference = new Preference();
|
||||||
|
$preference->data = 'token';
|
||||||
|
$job->shouldReceive('fire')->once()->andReturn(false);
|
||||||
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('all')->andReturn($users);
|
||||||
|
\Preferences::shouldReceive('getForUser')
|
||||||
|
->withArgs([Mockery::any(), 'access_token', null])
|
||||||
|
->andReturn($preference)->once();
|
||||||
|
$response = $this->get(route('cron.cron', ['token']));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('The recurring transaction cron job did not fire.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -55,7 +55,6 @@ class ConvertControllerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
||||||
*/
|
*/
|
||||||
public function testIndexDepositTransfer(): void
|
public function testIndexDepositTransfer(): void
|
||||||
@@ -64,13 +63,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
// find deposit:
|
// find deposit:
|
||||||
$loop = 0;
|
$deposit = $this->getRandomDeposit();
|
||||||
do {
|
|
||||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $deposit->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||||
@@ -102,13 +95,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
// find deposit:
|
// find deposit:
|
||||||
$loop = 0;
|
$deposit = $this->getRandomDeposit();
|
||||||
do {
|
|
||||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $deposit->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||||
@@ -135,13 +122,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
// mock stuff:
|
// mock stuff:
|
||||||
|
|
||||||
// find deposit:
|
// find deposit:
|
||||||
$loop = 0;
|
$deposit = $this->getRandomDeposit();
|
||||||
do {
|
|
||||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $deposit->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||||
@@ -190,13 +171,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
// mock stuff:
|
// mock stuff:
|
||||||
|
|
||||||
// find transfer:
|
// find transfer:
|
||||||
$loop = 0;
|
$transfer = $this->getRandomTransfer();
|
||||||
do {
|
|
||||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $transfer->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
|
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
|
||||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||||
@@ -215,13 +190,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
public function testIndexTransferWithdrawal(): void
|
public function testIndexTransferWithdrawal(): void
|
||||||
{
|
{
|
||||||
// find transfer:
|
// find transfer:
|
||||||
$loop = 0;
|
$transfer = $this->getRandomTransfer();
|
||||||
do {
|
|
||||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $transfer->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||||
@@ -247,13 +216,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
|
|
||||||
// find withdrawal:
|
// find withdrawal:
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $withdrawal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||||
@@ -278,13 +241,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
public function testIndexWithdrawalTransfer(): void
|
public function testIndexWithdrawalTransfer(): void
|
||||||
{
|
{
|
||||||
// find withdrawal:
|
// find withdrawal:
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $withdrawal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||||
@@ -379,13 +336,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
$account = $this->user()->accounts()->first();
|
$account = $this->user()->accounts()->first();
|
||||||
|
|
||||||
// find withdrawal:
|
// find withdrawal:
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $withdrawal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
|
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$messageBag = new MessageBag;
|
$messageBag = new MessageBag;
|
||||||
@@ -459,12 +410,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
public function testPostIndexTransferDeposit(): void
|
public function testPostIndexTransferDeposit(): void
|
||||||
{
|
{
|
||||||
// find transfer:
|
// find transfer:
|
||||||
$loop = 0;
|
$transfer =$this->getRandomTransfer();
|
||||||
do {
|
|
||||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $transfer->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
@@ -249,7 +249,9 @@ class SingleControllerTest extends TestCase
|
|||||||
// mock new account list:
|
// mock new account list:
|
||||||
$currency = TransactionCurrency::first();
|
$currency = TransactionCurrency::first();
|
||||||
$accountRepos->shouldReceive('getAccountsByType')
|
$accountRepos->shouldReceive('getAccountsByType')
|
||||||
->withArgs([[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]])->andReturn(new Collection([$account]))->once();
|
->withArgs(
|
||||||
|
[[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]]
|
||||||
|
)->andReturn(new Collection([$account]))->once();
|
||||||
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(6);
|
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(6);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@@ -867,13 +869,7 @@ class SingleControllerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find withdrawal:
|
// find withdrawal:
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
|
||||||
$count = $withdrawal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
|
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
|
||||||
|
|
||||||
$this->session(['transactions.edit.uri' => 'http://localhost']);
|
$this->session(['transactions.edit.uri' => 'http://localhost']);
|
||||||
|
@@ -24,9 +24,11 @@ declare(strict_types=1);
|
|||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
@@ -41,7 +43,6 @@ use Mockery;
|
|||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param string $range
|
* @param string $range
|
||||||
@@ -76,8 +77,6 @@ abstract class TestCase extends BaseTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use CreatesApplication;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -94,6 +93,8 @@ abstract class TestCase extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use CreatesApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
@@ -110,6 +111,30 @@ abstract class TestCase extends BaseTestCase
|
|||||||
return User::find(2);
|
return User::find(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function getRandomDeposit(): TransactionJournal
|
||||||
|
{
|
||||||
|
return $this->getRandomJournal(TransactionType::DEPOSIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function getRandomWithdrawal(): TransactionJournal
|
||||||
|
{
|
||||||
|
return $this->getRandomJournal(TransactionType::WITHDRAWAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function getRandomTransfer(): TransactionJournal
|
||||||
|
{
|
||||||
|
return $this->getRandomJournal(TransactionType::TRANSFER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
@@ -146,10 +171,38 @@ abstract class TestCase extends BaseTestCase
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
private function getRandomJournal(string $type): TransactionJournal
|
||||||
|
{
|
||||||
|
$query = DB::table('transactions')
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
|
->where('transaction_journals.user_id', $this->user()->id)
|
||||||
|
->whereNull('transaction_journals.deleted_at')
|
||||||
|
->whereNull('transactions.deleted_at')
|
||||||
|
->where('transaction_types.type', $type)
|
||||||
|
->groupBy('transactions.transaction_journal_id')
|
||||||
|
->having('ct', '=', 2)
|
||||||
|
->inRandomOrder()->take(1);
|
||||||
|
$result = $query->get(
|
||||||
|
[
|
||||||
|
'transactions.transaction_journal_id',
|
||||||
|
'transaction_journalstransaction_type_id',
|
||||||
|
DB::raw('COUNT(transaction_journal_id) as ct'),
|
||||||
|
]
|
||||||
|
)->first();
|
||||||
|
|
||||||
|
return TransactionJournal::find((int)$result->transaction_journal_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -137,17 +137,12 @@ class JournalUpdateServiceTest extends TestCase
|
|||||||
$service->shouldReceive('setUser');
|
$service->shouldReceive('setUser');
|
||||||
$service->shouldReceive('updateBudget')->withArgs([Mockery::any(), $budget->id])->twice();
|
$service->shouldReceive('updateBudget')->withArgs([Mockery::any(), $budget->id])->twice();
|
||||||
|
|
||||||
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
// call update service to update budget. Should call transaction service twice.
|
// call update service to update budget. Should call transaction service twice.
|
||||||
/** @var JournalUpdateService $service */
|
/** @var JournalUpdateService $service */
|
||||||
$service = app(JournalUpdateService::class);
|
$service = app(JournalUpdateService::class);
|
||||||
$service->updateBudget($journal, $budget->id);
|
$service->updateBudget($withdrawal, $budget->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,16 +155,12 @@ class JournalUpdateServiceTest extends TestCase
|
|||||||
$service->shouldReceive('updateCategory')->withArgs([Mockery::any(), 'New category'])->twice();
|
$service->shouldReceive('updateCategory')->withArgs([Mockery::any(), 'New category'])->twice();
|
||||||
|
|
||||||
|
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
// call update service to update budget. Should call transaction service twice.
|
// call update service to update budget. Should call transaction service twice.
|
||||||
/** @var JournalUpdateService $service */
|
/** @var JournalUpdateService $service */
|
||||||
$service = app(JournalUpdateService::class);
|
$service = app(JournalUpdateService::class);
|
||||||
$service->updateCategory($journal, 'New category');
|
$service->updateCategory($withdrawal, 'New category');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\TransactionRules\Actions\SetDestinationAccount;
|
use FireflyIII\TransactionRules\Actions\SetDestinationAccount;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -46,18 +45,11 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testActDepositExisting(): void
|
public function testActDepositExisting(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
$deposit = $this->getRandomDeposit();
|
||||||
|
$destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
|
||||||
$destination = $destinationTr->account;
|
$destination = $destinationTr->account;
|
||||||
$user = $journal->user;
|
$user = $deposit->user;
|
||||||
$accountType = AccountType::whereType(AccountType::ASSET)->first();
|
$accountType = AccountType::whereType(AccountType::ASSET)->first();
|
||||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
||||||
$this->assertNotEquals($destination->id, $account->id);
|
$this->assertNotEquals($destination->id, $account->id);
|
||||||
@@ -70,12 +62,11 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = $account->name;
|
$ruleAction->action_value = $account->name;
|
||||||
$action = new SetDestinationAccount($ruleAction);
|
$action = new SetDestinationAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($deposit);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
// test journal for new account
|
// test journal for new account
|
||||||
$journal = TransactionJournal::find($journal->id);
|
$destinationTr = $deposit->transactions()->where('amount', '>', 0)->first();
|
||||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
|
||||||
$newDestination = $destinationTr->account;
|
$newDestination = $destinationTr->account;
|
||||||
$this->assertNotEquals($destination->id, $newDestination->id);
|
$this->assertNotEquals($destination->id, $newDestination->id);
|
||||||
$this->assertEquals($newDestination->id, $account->id);
|
$this->assertEquals($newDestination->id, $account->id);
|
||||||
@@ -89,13 +80,7 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
public function testActDepositNotExisting(): void
|
public function testActDepositNotExisting(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
$deposit = $this->getRandomDeposit();
|
||||||
|
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
// find account? Return account:
|
// find account? Return account:
|
||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
@@ -105,7 +90,7 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = 'Not existing asset account #' . random_int(1, 10000);
|
$ruleAction->action_value = 'Not existing asset account #' . random_int(1, 10000);
|
||||||
$action = new SetDestinationAccount($ruleAction);
|
$action = new SetDestinationAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($deposit);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,15 +102,8 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
public function testActWithDrawalNotExisting(): void
|
public function testActWithDrawalNotExisting(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
|
||||||
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 4)->first();
|
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 4)->first();
|
||||||
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
|
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
// find account? Return account:
|
// find account? Return account:
|
||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
@@ -136,7 +114,7 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = 'Not existing expense account #' . random_int(1, 10000);
|
$ruleAction->action_value = 'Not existing expense account #' . random_int(1, 10000);
|
||||||
$action = new SetDestinationAccount($ruleAction);
|
$action = new SetDestinationAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($withdrawal);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
@@ -148,19 +126,11 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testActWithdrawalExisting(): void
|
public function testActWithdrawalExisting(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
|
$destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
|
|
||||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
|
||||||
$destination = $destinationTr->account;
|
$destination = $destinationTr->account;
|
||||||
$user = $journal->user;
|
$user = $withdrawal->user;
|
||||||
$accountType = AccountType::whereType(AccountType::EXPENSE)->first();
|
$accountType = AccountType::whereType(AccountType::EXPENSE)->first();
|
||||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $destination->id)->first();
|
||||||
$this->assertNotEquals($destination->id, $account->id);
|
$this->assertNotEquals($destination->id, $account->id);
|
||||||
@@ -173,12 +143,11 @@ class SetDestinationAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = $account->name;
|
$ruleAction->action_value = $account->name;
|
||||||
$action = new SetDestinationAccount($ruleAction);
|
$action = new SetDestinationAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
// test journal for new account
|
// test journal for new account
|
||||||
$journal = TransactionJournal::find($journal->id);
|
$destinationTr = $withdrawal->transactions()->where('amount', '>', 0)->first();
|
||||||
$destinationTr = $journal->transactions()->where('amount', '>', 0)->first();
|
|
||||||
$newDestination = $destinationTr->account;
|
$newDestination = $destinationTr->account;
|
||||||
$this->assertNotEquals($destination->id, $newDestination->id);
|
$this->assertNotEquals($destination->id, $newDestination->id);
|
||||||
$this->assertEquals($newDestination->id, $account->id);
|
$this->assertEquals($newDestination->id, $account->id);
|
||||||
|
@@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\TransactionRules\Actions\SetSourceAccount;
|
use FireflyIII\TransactionRules\Actions\SetSourceAccount;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -45,21 +44,12 @@ class SetSourceAccountTest extends TestCase
|
|||||||
public function testActDepositExistingUpdated(): void
|
public function testActDepositExistingUpdated(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$deposit = $this->getRandomDeposit();
|
||||||
|
$sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
|
||||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
$source = $sourceTr->account;
|
||||||
|
$user = $deposit->user;
|
||||||
do {
|
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
|
||||||
/** @var TransactionJournal $journal */
|
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
|
|
||||||
$source = $sourceTr->account;
|
|
||||||
$user = $journal->user;
|
|
||||||
$accountType = AccountType::whereType(AccountType::REVENUE)->first();
|
|
||||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
|
|
||||||
$this->assertNotEquals($source->id, $account->id);
|
$this->assertNotEquals($source->id, $account->id);
|
||||||
|
|
||||||
// find account? Return account:
|
// find account? Return account:
|
||||||
@@ -70,12 +60,11 @@ class SetSourceAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = $account->name;
|
$ruleAction->action_value = $account->name;
|
||||||
$action = new SetSourceAccount($ruleAction);
|
$action = new SetSourceAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($deposit);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
// test journal for new account
|
// test journal for new account
|
||||||
$journal = TransactionJournal::find($journal->id);
|
$sourceTr = $deposit->transactions()->where('amount', '<', 0)->first();
|
||||||
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
|
|
||||||
$newSource = $sourceTr->account;
|
$newSource = $sourceTr->account;
|
||||||
$this->assertNotEquals($source->id, $newSource->id);
|
$this->assertNotEquals($source->id, $newSource->id);
|
||||||
$this->assertEquals($newSource->id, $account->id);
|
$this->assertEquals($newSource->id, $account->id);
|
||||||
@@ -89,14 +78,8 @@ class SetSourceAccountTest extends TestCase
|
|||||||
public function testActDepositRevenue(): void
|
public function testActDepositRevenue(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
|
||||||
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 5)->first();
|
$account = $this->user()->accounts()->inRandomOrder()->where('account_type_id', 5)->first();
|
||||||
|
$deposit = $this->getRandomDeposit();
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
$accountRepos->shouldReceive('findByName')->andReturn(null);
|
$accountRepos->shouldReceive('findByName')->andReturn(null);
|
||||||
@@ -106,7 +89,7 @@ class SetSourceAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = 'Some new revenue #' . random_int(1, 10000);
|
$ruleAction->action_value = 'Some new revenue #' . random_int(1, 10000);
|
||||||
$action = new SetSourceAccount($ruleAction);
|
$action = new SetSourceAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($deposit);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,17 +101,11 @@ class SetSourceAccountTest extends TestCase
|
|||||||
public function testActWithdrawalExistingUpdated(): void
|
public function testActWithdrawalExistingUpdated(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
|
|
||||||
do {
|
$sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
|
|
||||||
$source = $sourceTr->account;
|
$source = $sourceTr->account;
|
||||||
$user = $journal->user;
|
$user = $withdrawal->user;
|
||||||
$accountType = AccountType::whereType(AccountType::ASSET)->first();
|
$accountType = AccountType::whereType(AccountType::ASSET)->first();
|
||||||
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
|
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
|
||||||
$this->assertNotEquals($source->id, $account->id);
|
$this->assertNotEquals($source->id, $account->id);
|
||||||
@@ -141,12 +118,11 @@ class SetSourceAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = $account->name;
|
$ruleAction->action_value = $account->name;
|
||||||
$action = new SetSourceAccount($ruleAction);
|
$action = new SetSourceAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
// test journal for new account
|
// test journal for new account
|
||||||
$journal = TransactionJournal::find($journal->id);
|
$sourceTr = $withdrawal->transactions()->where('amount', '<', 0)->first();
|
||||||
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
|
|
||||||
$newSource = $sourceTr->account;
|
$newSource = $sourceTr->account;
|
||||||
$this->assertNotEquals($source->id, $newSource->id);
|
$this->assertNotEquals($source->id, $newSource->id);
|
||||||
$this->assertEquals($newSource->id, $account->id);
|
$this->assertEquals($newSource->id, $account->id);
|
||||||
@@ -160,13 +136,7 @@ class SetSourceAccountTest extends TestCase
|
|||||||
public function testActWithdrawalNotExisting(): void
|
public function testActWithdrawalNotExisting(): void
|
||||||
{
|
{
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
|
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $this->user()->transactionJournals()->where('transaction_type_id', $type->id)->inRandomOrder()->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
$accountRepos->shouldReceive('setUser');
|
$accountRepos->shouldReceive('setUser');
|
||||||
$accountRepos->shouldReceive('findByName')->andReturn(null);
|
$accountRepos->shouldReceive('findByName')->andReturn(null);
|
||||||
@@ -175,7 +145,7 @@ class SetSourceAccountTest extends TestCase
|
|||||||
$ruleAction = new RuleAction;
|
$ruleAction = new RuleAction;
|
||||||
$ruleAction->action_value = 'Some new account #' . random_int(1, 10000);
|
$ruleAction->action_value = 'Some new account #' . random_int(1, 10000);
|
||||||
$action = new SetSourceAccount($ruleAction);
|
$action = new SetSourceAccount($ruleAction);
|
||||||
$result = $action->act($journal);
|
$result = $action->act($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Unit\TransactionRules\Triggers;
|
namespace Tests\Unit\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\TransactionRules\Triggers\BudgetIs;
|
use FireflyIII\TransactionRules\Triggers\BudgetIs;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -38,18 +37,14 @@ class BudgetIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredJournal(): void
|
public function testTriggeredJournal(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
$count = $journal->transactions()->count();
|
$withdrawal->budgets()->detach();
|
||||||
} while ($count !== 2);
|
$withdrawal->budgets()->save($budget);
|
||||||
|
$this->assertEquals(1, $withdrawal->budgets()->count());
|
||||||
$budget = $journal->user->budgets()->first();
|
|
||||||
$journal->budgets()->detach();
|
|
||||||
$journal->budgets()->save($budget);
|
|
||||||
$this->assertEquals(1, $journal->budgets()->count());
|
|
||||||
|
|
||||||
$trigger = BudgetIs::makeFromStrings($budget->name, false);
|
$trigger = BudgetIs::makeFromStrings($budget->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,19 +53,15 @@ class BudgetIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNotJournal(): void
|
public function testTriggeredNotJournal(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
$count = $journal->transactions()->count();
|
$otherBudget = $withdrawal->user->budgets()->where('id', '!=', $budget->id)->first();
|
||||||
} while ($count !== 2);
|
$withdrawal->budgets()->detach();
|
||||||
|
$withdrawal->budgets()->save($budget);
|
||||||
$budget = $journal->user->budgets()->first();
|
$this->assertEquals(1, $withdrawal->budgets()->count());
|
||||||
$otherBudget = $journal->user->budgets()->where('id', '!=', $budget->id)->first();
|
|
||||||
$journal->budgets()->detach();
|
|
||||||
$journal->budgets()->save($budget);
|
|
||||||
$this->assertEquals(1, $journal->budgets()->count());
|
|
||||||
|
|
||||||
$trigger = BudgetIs::makeFromStrings($otherBudget->name, false);
|
$trigger = BudgetIs::makeFromStrings($otherBudget->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,16 +70,12 @@ class BudgetIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredTransaction(): void
|
public function testTriggeredTransaction(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($count !== 2);
|
|
||||||
|
|
||||||
/** @var Collection $transactions */
|
/** @var Collection $transactions */
|
||||||
$transactions = $journal->transactions()->get();
|
$transactions = $withdrawal->transactions()->get();
|
||||||
$budget = $journal->user->budgets()->first();
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
|
|
||||||
$journal->budgets()->detach();
|
$withdrawal->budgets()->detach();
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$transaction->budgets()->detach();
|
$transaction->budgets()->detach();
|
||||||
@@ -96,10 +83,10 @@ class BudgetIsTest extends TestCase
|
|||||||
$this->assertEquals(1, $transaction->budgets()->count());
|
$this->assertEquals(1, $transaction->budgets()->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(0, $journal->budgets()->count());
|
$this->assertEquals(0, $withdrawal->budgets()->count());
|
||||||
|
|
||||||
$trigger = BudgetIs::makeFromStrings($budget->name, false);
|
$trigger = BudgetIs::makeFromStrings($budget->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,18 +36,14 @@ class CategoryIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredJournal(): void
|
public function testTriggeredJournal(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$category = $withdrawal->user->categories()->first();
|
||||||
$transactions = $journal->transactions()->count();
|
$withdrawal->categories()->detach();
|
||||||
} while ($transactions !== 2);
|
$withdrawal->categories()->save($category);
|
||||||
|
$this->assertEquals(1, $withdrawal->categories()->count());
|
||||||
$category = $journal->user->categories()->first();
|
|
||||||
$journal->categories()->detach();
|
|
||||||
$journal->categories()->save($category);
|
|
||||||
$this->assertEquals(1, $journal->categories()->count());
|
|
||||||
|
|
||||||
$trigger = CategoryIs::makeFromStrings($category->name, false);
|
$trigger = CategoryIs::makeFromStrings($category->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,19 +52,15 @@ class CategoryIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNotJournal(): void
|
public function testTriggeredNotJournal(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$category = $withdrawal->user->categories()->first();
|
||||||
$transactions = $journal->transactions()->count();
|
$otherCategory = $withdrawal->user->categories()->where('id', '!=', $category->id)->first();
|
||||||
} while ($transactions !== 2);
|
$withdrawal->categories()->detach();
|
||||||
|
$withdrawal->categories()->save($category);
|
||||||
$category = $journal->user->categories()->first();
|
$this->assertEquals(1, $withdrawal->categories()->count());
|
||||||
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
|
|
||||||
$journal->categories()->detach();
|
|
||||||
$journal->categories()->save($category);
|
|
||||||
$this->assertEquals(1, $journal->categories()->count());
|
|
||||||
|
|
||||||
$trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
|
$trigger = CategoryIs::makeFromStrings($otherCategory->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,22 +69,18 @@ class CategoryIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredTransaction(): void
|
public function testTriggeredTransaction(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$transaction = $withdrawal->transactions()->first();
|
||||||
$transactions = $journal->transactions()->count();
|
$category = $withdrawal->user->categories()->first();
|
||||||
} while ($transactions !== 2);
|
|
||||||
|
|
||||||
$transaction = $journal->transactions()->first();
|
$withdrawal->categories()->detach();
|
||||||
$category = $journal->user->categories()->first();
|
|
||||||
|
|
||||||
$journal->categories()->detach();
|
|
||||||
$transaction->categories()->detach();
|
$transaction->categories()->detach();
|
||||||
$transaction->categories()->save($category);
|
$transaction->categories()->save($category);
|
||||||
$this->assertEquals(0, $journal->categories()->count());
|
$this->assertEquals(0, $withdrawal->categories()->count());
|
||||||
$this->assertEquals(1, $transaction->categories()->count());
|
$this->assertEquals(1, $transaction->categories()->count());
|
||||||
|
|
||||||
$trigger = CategoryIs::makeFromStrings($category->name, false);
|
$trigger = CategoryIs::makeFromStrings($category->name, false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,21 +38,15 @@ class HasAnyBudgetTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$budget = $journal->user->budgets()->first();
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
$journal->budgets()->detach();
|
$withdrawal->budgets()->detach();
|
||||||
$journal->budgets()->save($budget);
|
$withdrawal->budgets()->save($budget);
|
||||||
|
|
||||||
$this->assertEquals(1, $journal->budgets()->count());
|
$this->assertEquals(1, $withdrawal->budgets()->count());
|
||||||
$trigger = HasAnyBudget::makeFromStrings('', false);
|
$trigger = HasAnyBudget::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -62,25 +56,18 @@ class HasAnyBudgetTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNot(): void
|
public function testTriggeredNot(): void
|
||||||
{
|
{
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
$withdrawal->budgets()->detach();
|
||||||
/** @var TransactionJournal $journal */
|
$this->assertEquals(0, $withdrawal->budgets()->count());
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
|
|
||||||
$journal->budgets()->detach();
|
|
||||||
$this->assertEquals(0, $journal->budgets()->count());
|
|
||||||
|
|
||||||
// also detach all transactions:
|
// also detach all transactions:
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($journal->transactions()->get() as $transaction) {
|
foreach ($withdrawal->transactions()->get() as $transaction) {
|
||||||
$transaction->budgets()->detach();
|
$transaction->budgets()->detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
$trigger = HasAnyBudget::makeFromStrings('', false);
|
$trigger = HasAnyBudget::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,28 +77,17 @@ class HasAnyBudgetTest extends TestCase
|
|||||||
public function testTriggeredTransactions(): void
|
public function testTriggeredTransactions(): void
|
||||||
{
|
{
|
||||||
Log::debug('Now in testTriggeredTransactions()');
|
Log::debug('Now in testTriggeredTransactions()');
|
||||||
$loop = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
Log::debug(sprintf('Loop is now at #%d', $loop));
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
|
|
||||||
Log::debug(sprintf('Found journal #%d with %d transactions', $journal->id, $count));
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
|
|
||||||
$loop++;
|
|
||||||
} while ($count !== 2 && $loop < 30);
|
|
||||||
Log::debug('end of loop!');
|
|
||||||
|
|
||||||
$budget = $journal->user->budgets()->first();
|
|
||||||
Log::debug(sprintf('First budget is %d ("%s")', $budget->id, $budget->name));
|
Log::debug(sprintf('First budget is %d ("%s")', $budget->id, $budget->name));
|
||||||
$journal->budgets()->detach();
|
$withdrawal->budgets()->detach();
|
||||||
$this->assertEquals(0, $journal->budgets()->count());
|
$this->assertEquals(0, $withdrawal->budgets()->count());
|
||||||
Log::debug('Survived the assumption.');
|
Log::debug('Survived the assumption.');
|
||||||
|
|
||||||
// append to transaction
|
// append to transaction
|
||||||
Log::debug('Do transaction loop.');
|
Log::debug('Do transaction loop.');
|
||||||
foreach ($journal->transactions()->get() as $index => $transaction) {
|
foreach ($withdrawal->transactions()->get() as $index => $transaction) {
|
||||||
Log::debug(sprintf('Now at index #%d, transaction #%d', $index, $transaction->id));
|
Log::debug(sprintf('Now at index #%d, transaction #%d', $index, $transaction->id));
|
||||||
$transaction->budgets()->detach();
|
$transaction->budgets()->detach();
|
||||||
if (0 === $index) {
|
if (0 === $index) {
|
||||||
@@ -121,7 +97,7 @@ class HasAnyBudgetTest extends TestCase
|
|||||||
}
|
}
|
||||||
Log::debug('Done with loop, make trigger');
|
Log::debug('Done with loop, make trigger');
|
||||||
$trigger = HasAnyBudget::makeFromStrings('', false);
|
$trigger = HasAnyBudget::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,27 +73,21 @@ class HasAnyCategoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredTransactions(): void
|
public function testTriggeredTransactions(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = null;
|
|
||||||
while ($count === 0) {
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = $journal->user->categories()->first();
|
$category = $withdrawal->user->categories()->first();
|
||||||
$journal->categories()->detach();
|
$withdrawal->categories()->detach();
|
||||||
$this->assertEquals(0, $journal->categories()->count());
|
$this->assertEquals(0, $withdrawal->categories()->count());
|
||||||
|
|
||||||
// append to transaction, not to journal.
|
// append to transaction, not to journal.
|
||||||
foreach ($journal->transactions()->get() as $index => $transaction) {
|
foreach ($withdrawal->transactions()->get() as $index => $transaction) {
|
||||||
$transaction->categories()->sync([$category->id]);
|
$transaction->categories()->sync([$category->id]);
|
||||||
$this->assertEquals(1, $transaction->categories()->count());
|
$this->assertEquals(1, $transaction->categories()->count());
|
||||||
}
|
}
|
||||||
$this->assertEquals(0, $journal->categories()->count());
|
$this->assertEquals(0, $withdrawal->categories()->count());
|
||||||
|
|
||||||
$trigger = HasAnyCategory::makeFromStrings('', false);
|
$trigger = HasAnyCategory::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,17 +36,14 @@ class HasAttachmentTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->attachments()->count();
|
|
||||||
} while ($count !== 0);
|
|
||||||
|
|
||||||
$attachment = $journal->user->attachments()->first();
|
$attachment = $withdrawal->user->attachments()->first();
|
||||||
$journal->attachments()->save($attachment);
|
$withdrawal->attachments()->save($attachment);
|
||||||
$this->assertEquals(1, $journal->attachments()->count());
|
$this->assertEquals(1, $withdrawal->attachments()->count());
|
||||||
|
|
||||||
$trigger = HasAttachment::makeFromStrings('1', false);
|
$trigger = HasAttachment::makeFromStrings('1', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,16 +52,12 @@ class HasAttachmentTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredFalse(): void
|
public function testTriggeredFalse(): void
|
||||||
{
|
{
|
||||||
do {
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
// this is kind of cheating but OK.
|
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->attachments()->count();
|
|
||||||
} while ($count !== 0);
|
|
||||||
|
|
||||||
$this->assertEquals(0, $journal->attachments()->count());
|
$this->assertEquals(0, $withdrawal->attachments()->count());
|
||||||
|
|
||||||
$trigger = HasAttachment::makeFromStrings('1', false);
|
$trigger = HasAttachment::makeFromStrings('1', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,25 +72,21 @@ class HasNoBudgetTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredTransaction(): void
|
public function testTriggeredTransaction(): void
|
||||||
{
|
{
|
||||||
$loopCount = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
do {
|
|
||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
} while ($loopCount < 30 && $count !== 2);
|
|
||||||
|
|
||||||
$transactions = $journal->transactions()->get();
|
$transactions = $withdrawal->transactions()->get();
|
||||||
$budget = $journal->user->budgets()->first();
|
$budget = $withdrawal->user->budgets()->first();
|
||||||
|
|
||||||
$journal->budgets()->detach();
|
$withdrawal->budgets()->detach();
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$transaction->budgets()->sync([$budget->id]);
|
$transaction->budgets()->sync([$budget->id]);
|
||||||
$this->assertEquals(1, $transaction->budgets()->count());
|
$this->assertEquals(1, $transaction->budgets()->count());
|
||||||
}
|
}
|
||||||
$this->assertEquals(0, $journal->budgets()->count());
|
$this->assertEquals(0, $withdrawal->budgets()->count());
|
||||||
|
|
||||||
$trigger = HasNoBudget::makeFromStrings('', false);
|
$trigger = HasNoBudget::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -75,21 +75,17 @@ class HasNoCategoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredTransaction(): void
|
public function testTriggeredTransaction(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$withdrawal = $this->getRandomWithdrawal();
|
||||||
while ($count === 0) {
|
$transaction = $withdrawal->transactions()->first();
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$category = $withdrawal->user->categories()->first();
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
}
|
|
||||||
$transaction = $journal->transactions()->first();
|
|
||||||
$category = $journal->user->categories()->first();
|
|
||||||
|
|
||||||
$journal->categories()->detach();
|
$withdrawal->categories()->detach();
|
||||||
$transaction->categories()->sync([$category->id]);
|
$transaction->categories()->sync([$category->id]);
|
||||||
$this->assertEquals(0, $journal->categories()->count());
|
$this->assertEquals(0, $withdrawal->categories()->count());
|
||||||
$this->assertEquals(1, $transaction->categories()->count());
|
$this->assertEquals(1, $transaction->categories()->count());
|
||||||
|
|
||||||
$trigger = HasNoCategory::makeFromStrings('', false);
|
$trigger = HasNoCategory::makeFromStrings('', false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($withdrawal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user