mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Improve tests for transaction rules.
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\TransactionRules\Actions;
|
namespace FireflyIII\TransactionRules\Actions;
|
||||||
|
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@@ -55,6 +56,13 @@ class ClearBudget implements ActionInterface
|
|||||||
{
|
{
|
||||||
$journal->budgets()->detach();
|
$journal->budgets()->detach();
|
||||||
$journal->touch();
|
$journal->touch();
|
||||||
|
|
||||||
|
// also remove categories from transactions:
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach($journal->transactions as $transaction) {
|
||||||
|
$transaction->budgets()->detach();
|
||||||
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal %d.', $journal->id));
|
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal %d.', $journal->id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\TransactionRules\Actions;
|
namespace FireflyIII\TransactionRules\Actions;
|
||||||
|
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@@ -55,6 +56,13 @@ class ClearCategory implements ActionInterface
|
|||||||
{
|
{
|
||||||
$journal->categories()->detach();
|
$journal->categories()->detach();
|
||||||
$journal->touch();
|
$journal->touch();
|
||||||
|
|
||||||
|
// also remove categories from transactions:
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach($journal->transactions as $transaction) {
|
||||||
|
$transaction->categories()->detach();
|
||||||
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal %d.', $journal->id));
|
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal %d.', $journal->id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\TransactionRules\Actions;
|
|||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
@@ -87,7 +88,12 @@ class SetBudget implements ActionInterface
|
|||||||
|
|
||||||
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
|
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
|
||||||
|
|
||||||
$journal->budgets()->sync([$budget->id]);
|
$journal->budgets()->detach();
|
||||||
|
// set budget on transactions:
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($journal->transaction as $transaction) {
|
||||||
|
$transaction->budgets()->sync([$budget->id]);
|
||||||
|
}
|
||||||
$journal->touch();
|
$journal->touch();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\TransactionRules\Actions;
|
|||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@@ -56,7 +57,16 @@ class SetCategory implements ActionInterface
|
|||||||
{
|
{
|
||||||
$name = $this->action->action_value;
|
$name = $this->action->action_value;
|
||||||
$category = Category::firstOrCreateEncrypted(['name' => $name, 'user_id' => $journal->user->id]);
|
$category = Category::firstOrCreateEncrypted(['name' => $name, 'user_id' => $journal->user->id]);
|
||||||
$journal->categories()->sync([$category->id]);
|
|
||||||
|
$journal->categories()->detach();
|
||||||
|
// set category on transactions:
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($journal->transaction as $transaction) {
|
||||||
|
$transaction->categories()->sync([$category->id]);
|
||||||
|
}
|
||||||
|
$journal->touch();
|
||||||
|
|
||||||
|
|
||||||
$journal->touch();
|
$journal->touch();
|
||||||
Log::debug(sprintf('RuleAction SetCategory set the category of journal #%d to budget #%d ("%s").', $journal->id, $category->id, $category->name));
|
Log::debug(sprintf('RuleAction SetCategory set the category of journal #%d to budget #%d ("%s").', $journal->id, $category->id, $category->name));
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ class ClearCategoryTest extends TestCase
|
|||||||
// associate budget with journal:
|
// associate budget with journal:
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$category = $journal->user->categories()->first();
|
$category = $journal->user->categories()->first();
|
||||||
$journal->budgets()->save($category);
|
$journal->categories()->save($category);
|
||||||
$this->assertGreaterThan(0, $journal->categories()->count());
|
$this->assertGreaterThan(0, $journal->categories()->count());
|
||||||
|
|
||||||
// fire the action:
|
// fire the action:
|
||||||
|
Reference in New Issue
Block a user